gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS Misc > heres a little demo for doing 3d on both screens!

#60759 - ninogenio - Mon Nov 14, 2005 3:21 pm

heres a demo for anyone interested it does a software rendered 3d texture mapped cube on the sub screen(double buffered) and a hardware rendered one on the main screen all at really fast speed.theres a bit of warping on the sub screen cube but thats because its affinely mapped and im currently working on perspective correct mapping.

http://dc3.4shared.com/download/466280/a9e873a0/both_screens_3d.html

#60760 - revo - Mon Nov 14, 2005 4:05 pm

I'll take a look at it later, interesting ;)

Anyone made demo of hardware 3D on both screens?

edit:
tested, works fine ;)
_________________
[ sorry for all mistakes, but my english isn't as good as I wish it to be ]

#60793 - bahnhof - Mon Nov 14, 2005 10:14 pm

Gah.. Misleading title

#60859 - lambi1982 - Tue Nov 15, 2005 1:56 pm

Good job :)

Looks great.

Is something like this possible ( to be ported) to the DS

used on the touch screen ????
http://download.nvidia.com/downloads/nZone/demos/nvidia/Bubble.zip
_________________
Who, Me?

#60880 - SevenString - Tue Nov 15, 2005 8:46 pm

One could do 2 passes on a double-buffered 3D screen:

1) Do a HW render pass to the backbuffer
2) Blit that back buffer to the 2D screen
3) Clear the backbuffer and HW render a second pass with different content
4) buffer swap

voila! 3D on two screens.

My current engine does 3D on one screen and 2D on the other, but I think I'll try to do something like this tonight...
_________________
"Artificial Intelligence is no match for natural stupidity."

#60885 - ecurtz - Tue Nov 15, 2005 9:35 pm

SevenString wrote:
One could do 2 passes on a double-buffered 3D screen:

1) Do a HW render pass to the backbuffer


Ummm, does anyone know how to do this, and I just missed it? This is required for doing 30 fps double pass 3d with more triangles, which I would like to try.

#60886 - dovoto - Tue Nov 15, 2005 9:53 pm

The DS does not have a 3D framebuffer (well it has a single scan line worth of one if you want to get technical)

What you can do is direct the output of the 3D raster into memory instead of to the LCD controller (vram and possibly main memory) then use that to display to either screen. This allows you to gitter and blend two frames together or to display alternate frames on alternate displays...

I do not know how to do this at the moment though, and only believe this is possible from talking to a few people. Perhaps i will look into it if no one has figured it out by the time finals are over.
_________________
www.drunkencoders.com

#60900 - ninogenio - Wed Nov 16, 2005 12:26 am

im really glad this has spurred the some thought about how 3d hardware can be done on both screens it was just ment as a little demo to show how this might be done what i was really impressed by though was the speed of the ds when i used it correctly it a mean pixel pusher indeed.in most surcomestances it keeps on par with my pc when running similar double buffer based demos :)

cheers for the comments btw.;)

#60907 - SevenString - Wed Nov 16, 2005 12:57 am

Quote:
What you can do is direct the output of the 3D raster into memory instead of to the LCD controller (vram and possibly main memory)


Sounds like there is more to it than I was talking about, otherwise everybody would be doing it, eh?

But maybe if one can direct to vram, then there's a good workaround... if it exists.
_________________
"Artificial Intelligence is no match for natural stupidity."

#60914 - tepples - Wed Nov 16, 2005 2:24 am

SevenString wrote:
Quote:
What you can do is direct the output of the 3D raster into memory

Sounds like there is more to it than I was talking about, otherwise everybody would be doing it, eh?

First off, as I've been saying for months, there has to be a commercial game that uses the technique so that we can disassemble it in order to know what address to set as the source for DMA.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#60946 - ecurtz - Wed Nov 16, 2005 5:22 am

tepples wrote:

First off, as I've been saying for months, there has to be a commercial game that uses the technique so that we can disassemble it in order to know what address to set as the source for DMA.


Metroid Prime Demo? Or did it run at 60 fps?

#60948 - Lino - Wed Nov 16, 2005 5:51 am

its very ingenious...

#60953 - chishm - Wed Nov 16, 2005 6:57 am

Well StoneCypher gave me some info last night on IRC:
StoneCyqh wrote:
capture register is 0x04000064
ram blend EVA is bits 0..4
graphics blend evb is 8..12
vram bank select is 16-17
write offset is 18-19
capture data write size is 20-21
capture source is 24-25
capture source offset is 26-27
29-30 does something but nobody knows what yet
31 is enable
29-30 seems to have something to do with the blending
blending only seems to work when 29-30 is 10 or 11
when it's 00 or 01 only one of the two sources shows
i can't get 10 and 11 to do anything different
but it doesn't shut down on 11, where most things with a prohibited mode do, so it's probably two distinct things, i just don't know what

Apparently the info was on one of Patater's links.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#60957 - bluescrn - Wed Nov 16, 2005 9:33 am

chishm wrote:
Well StoneCypher gave me some info last night on IRC:
StoneCyqh wrote:
capture register is 0x04000064
ram blend EVA is bits 0..4
graphics blend evb is 8..12
vram bank select is 16-17
write offset is 18-19
capture data write size is 20-21
capture source is 24-25
capture source offset is 26-27
29-30 does something but nobody knows what yet
31 is enable
29-30 seems to have something to do with the blending
blending only seems to work when 29-30 is 10 or 11
when it's 00 or 01 only one of the two sources shows
i can't get 10 and 11 to do anything different
but it doesn't shut down on 11, where most things with a prohibited mode do, so it's probably two distinct things, i just don't know what

Apparently the info was on one of Patater's links.


hmmm... blending to ram?... sounds interesting... have we got a way to implement full-screen blur/glow effects?... :)

Although I'd be more interested in knowing how to do standard alpha blending on 3D polys... that seems to be another of the few remaining mysteries of DS homebrew...

#60966 - Lino - Wed Nov 16, 2005 10:20 am

chishm wrote:
Apparently the info was on one of Patater's links.


What link?

#60973 - chishm - Wed Nov 16, 2005 11:16 am

I don't know, I couldn't be bothered going through them all :). I just passed on the info I was given.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#61014 - dovoto - Wed Nov 16, 2005 7:23 pm

bluescrn wrote:

Although I'd be more interested in knowing how to do standard alpha blending on 3D polys... that seems to be another of the few remaining mysteries of DS homebrew...


Alpha blending works fine. Although there are two issues remaining: One is I need to move control of alpha to the material property setters (right now it is done via glPolyFormat()); The second is the 3D hardware appears to suffer from the same alpha blending limitations that plague 2D. It does not blend more than one polygon against one other non-blended polygon. In short, you can not blend a poly against another blended poly (so a completely translucent cube would not work).

There is an alpha blending example in the nehe section of the libnds examples (lesson 8 maybe) http://sourceforge.net/project/showfiles.php?group_id=114505&package_id=159894 . It should demonstrate both how to do it as well as how limited it is compared to the normal gl polygon blending (just try making more than one side of the cube translucent). Lesson 9 gives a much more blatant demonstration of the limitations as that demo could barely be considered functional. To compare to the actual nehe demos run these: http://nehe.gamedev.net lessons 8 and 9.

It is possible I have missed some blending settings that will make these limitations magically disappear but I have yet been able to locate anything of the sort
_________________
www.drunkencoders.com

#61019 - dovoto - Wed Nov 16, 2005 7:55 pm

It only took a couple of minutes but someone has pointed out a solution. I will test this out when i get home.
_________________
www.drunkencoders.com

#61122 - bluescrn - Thu Nov 17, 2005 2:44 pm

dovoto wrote:

Alpha blending works fine. Although there are two issues remaining: One is I need to move control of alpha to the material property setters (right now it is done via glPolyFormat());


Cool... might have to give that another look... It's a few months since I had a play with 3D stuff on the DS, and my current project is very much 2D. But as that's on hold waiting for wi-fi, I might have another go at something 3D :)

dovoto wrote:

The second is the 3D hardware appears to suffer from the same alpha blending limitations that plague 2D. It does not blend more than one polygon against one other non-blended polygon. In short, you can not blend a poly against another blended poly (so a completely translucent cube would not work).


That's strange... as it looks like both in Mario64 and definitely in Nanostray, there's overlapping blended polys that seem to work (I suppose they could potentially be doing it in software, but it seems a bit unlikely?)

Maybe it's something to do with those poly IDs, like the outlining?

#61162 - dovoto - Thu Nov 17, 2005 7:27 pm

Yes it has to do with poly IDs. I was told that they will blend as long as they dont have the same poly ID. I have not tried this yet though.
_________________
www.drunkencoders.com

#61250 - M3d10n - Fri Nov 18, 2005 1:41 pm

Ah, so this (polygon IDs) might be the problem the guy from Castlevania (sorry, I had bad memory for names) was referring to in an interview.

He said something about transparencies being a bit harder to do in the DS than in the PSOne. They had to find ways to assign different IDs to each transparent poly so they could blend against each other properly, otherwise the motion trail left by the main character and Alucard, as example, would've sucked hard.

And it was probably by abusing this that they made that room with the invisible maze, where you can only see the maze walls when a ghost is over them.

#61356 - The 9th Sage - Sat Nov 19, 2005 4:49 am

Hm...someone was asking about games that do 3D on two screens...I think Feel the Magic and Mario (in some of the minigames) do it, I know for a fact that Viewtiful Joe does it (and quite handily I might add).
_________________
Now with 20% More Old Man from Zelda 1 than ever before!

#61412 - M3d10n - Sat Nov 19, 2005 9:32 pm

Mario Kart does it too. I haven't got the game yet, but in the vids I saw, you get a 2-screen view of the camera showing the track (probably at halved framerate - in the videos all over the net you can't tell if it's 30fps or 60fps, since the videos themselves are in 30fps, somethings less).

#61426 - ecurtz - Sun Nov 20, 2005 1:12 am

Work in progress

Here's some code for playing around with dual screen 3D. It doesn't really work yet, but it's close. If anybody gets it finished, please let me know. I'll keep playing around with it as well.

[edit] Better version up in the same spot. Are there any other VRAM banks that can be used for Sub Background besides C? I think it would work at that point, at the expense of using up a ton of our video RAM. [/edit]

#61637 - ecurtz - Tue Nov 22, 2005 6:38 am

Dual 3D

OK, at the cost of 2 banks of VRAM, here's an example with dual hardware 3D.

#61640 - gladius - Tue Nov 22, 2005 7:19 am

Cool! Nice job ecurtz.

#61737 - revo - Tue Nov 22, 2005 11:38 pm

ecurtz wrote:
Dual 3D

OK, at the cost of 2 banks of VRAM, here's an example with dual hardware 3D.


thx! great job :) I have tried before, but without results... But now with working capture, it should be possible to make motion blur demo, or making some screenshots from apps :)
_________________
[ sorry for all mistakes, but my english isn't as good as I wish it to be ]

#61741 - lambi1982 - Wed Nov 23, 2005 12:28 am

great job :)
_________________
Who, Me?

#61757 - ninogenio - Wed Nov 23, 2005 3:04 am

that absouloty rocks dude!

im really glad i posted my demo up now as its led to this congrats.

#61893 - ecurtz - Thu Nov 24, 2005 5:32 pm

Glad I could get it working, but real thanks go to the person who originally posted the register info.

Now, has anybody had any luck with two passes on the same screen? It really seems like it should be possible to do with only one VRAM bank, but I haven't managed it yet.

#62040 - ninogenio - Sat Nov 26, 2005 7:16 pm

your right its strange that everything has to be rendered to the two screen from the sub 2d core its kind of like the capturing code isnt working quite as it should.ive spent most of 2 day playing with this trying to get it going and for the most part it does ive managed to render from one vram bank but the top display is ever so slightly faded.

the way i though this would have worked would have been to render to the main screen directly from the 3d core and inbtween frames to screen capture the object you want to display on the sub screen to to blit it to the sub bg.

any ideas any one!!!!!!!!!!!!

Code:
 
/****************************************
 *       Display Capture Test
 *       Author: eli
 *       (basically just one the DrunkenCoders demos by Dovoto)
 ****************************************/
 #define REG_CAPTURE (*(vu32*)0x04000064)

 #include <nds.h>
 #include "teapot_bin.h"
 #include "cafe_bin.h"

 void SetRegCapture(bool enable, uint8 srcBlend, uint8 destBlend, uint8 bank, uint8 offset, uint8 size, uint8 source, uint8 srcOffset);
 int LoadGLTextures();
 int DrawTeapot();
 int cafe_texid;
 int texture[1];
 int teapotX,teapotY;

 int main()
 {   
   powerON(POWER_ALL);

        irqInit();
   irqSet(IRQ_VBLANK, 0);

   videoSetMode(MODE_0_3D);
    videoSetModeSub(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE);
      vramSetBankA(VRAM_A_TEXTURE);
      vramSetBankC(VRAM_C_SUB_BG);
     
      SUB_BG2_CR = BG_BMP16_256x256;
      SUB_BG2_XDX = 256;
      SUB_BG2_XDY = 0;
      SUB_BG2_YDX = 0;
      SUB_BG2_YDY = 256;
      SUB_BG2_CY = 0;
      SUB_BG2_CX = 0;
     
      SUB_BG3_CR = BG_BMP16_256x256;
      SUB_BG3_XDX = 256;
      SUB_BG3_XDY = 0;
      SUB_BG3_YDX = 0;
      SUB_BG3_YDY = 256;
      SUB_BG3_CY = 0;
      SUB_BG3_CX = 0;

      glViewPort(0,0,255,191);

      glClearColor(0,0,0);
      glClearDepth(0x7FFF);
   
      LoadGLTextures();

      uint32 frameCount = 0;
      while (1)
     {
         glReset();
         scanKeys();

             if (frameCount & 1)
             { 
                          vramSetBankC(VRAM_C_LCD);
                          SetRegCapture(true, 0, 15, 2, 0, 3, 0, 0);
                          DrawTeapot();
             }
             else
             {
                          vramSetBankC(VRAM_C_SUB_BG);
                          DrawTeapot();
                           
             }

             glFlush();
             frameCount++;
             lcdSwap();
             swiWaitForVBlank();
   }
   
   return 0;
 }

 //------------------------------------------------------------------------------------------
 //                                   START OF FUCTIONS
 //------------------------------------------------------------------------------------------
 int DrawTeapot()
 {
              gluPerspective(35, 256.0 / 192.0, 0.1, 40);

              glMatrixMode(GL_TEXTURE);
         glIdentity();
         vector tex_scale = { 64<<16, -64<<16, 1<<16 };
              glScalev( &tex_scale );
         glRotateXi(teapotX);      
         glRotateYi(teapotX);

              glMatrixMode(GL_MODELVIEW);
         glIdentity();
              glTranslate3f32(0, 0, floatof32(-3));
         glRotateXi(teapotX);
         glRotateYi(teapotY);glColor3f(1,1,1);
      
         glLight(0, RGB15(31,31,31),0,floatov10(-3.0),0);
         glLight(1, RGB15(31,31,31),0,0,floatov10(-3.0));
         glLight(2, RGB15(31,31,31),0,0,floatov10(3.0));

              glMaterialf(GL_AMBIENT, RGB15(16,16,16));
         glMaterialf(GL_DIFFUSE, RGB15(16,16,16));
         glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8));
         glMaterialf(GL_EMISSION, RGB15(16,16,16));
              glMaterialf(GL_EMISSION, RGB15(31,31,31));

              if(!(keysHeld() & KEY_R))
              {
               glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK  | POLY_FORMAT_LIGHT0| POLY_FORMAT_LIGHT1| POLY_FORMAT_LIGHT2);

              }
        else
              {
               glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK  | POLY_FORMAT_LIGHT0| POLY_FORMAT_LIGHT1| POLY_FORMAT_LIGHT2);

              }

              teapotX -= 1;
         teapotY += 1;
             
              glBindTexture( 0, cafe_texid );
              glCallList((u32*)teapot_bin);   
             
         return TRUE;                   
 }


 void SetRegCapture(bool enable, uint8 srcBlend, uint8 destBlend, uint8 bank, uint8 offset, uint8 size, uint8 source, uint8 srcOffset)
 {
                   uint32 value = 0;
                   if (enable)
                   value |= 1 << 31;
                   value |= 3 << 29;
                   value |= (srcOffset & 0x3) << 26;
                   value |= (source & 0x3) << 24;
                   value |= (size & 0x3) << 20;
                   value |= (offset & 0x3) << 18;
                   value |= (bank & 0x3) << 16;
                   value |= (srcBlend & 0xF) << 8;
                   value |= (destBlend & 0xF) << 0;
   
                   REG_CAPTURE = value;
 }

 int LoadGLTextures()
 {
                glGenTextures( 1, &cafe_texid );
                glBindTexture( 0, cafe_texid );
                glTexImage2D( 0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, GL_TEXTURE_WRAP_S|GL_TEXTURE_WRAP_T|TEXGEN_NORMAL, (u8*)cafe_bin );

                return TRUE;
 }
 //-----------------------------------------

#62099 - Darkflame - Sun Nov 27, 2005 12:17 pm

The 9th Sage wrote:
Hm...someone was asking about games that do 3D on two screens...I think Feel the Magic and Mario (in some of the minigames) do it, I know for a fact that Viewtiful Joe does it (and quite handily I might add).


Mario Kart does it spectacularly. ;)

#62195 - lambi1982 - Mon Nov 28, 2005 6:06 am

Mario Kart does so it very well :)

Now a Question: If a developer was to disable one of the screens, would it be possible to boost the graphic power to the one screen, or is it going to be the same (less stress on arm9)?
_________________
Who, Me?

#62203 - chishm - Mon Nov 28, 2005 6:57 am

There are 3 separate graphics cores, 2D main, 2D sub, and 3D. The rendering capabilities of the cores are separate, and not combinable, with the exception of 2D main using 3D rendered layers, or either 2d core using captured 3D data. This is what is done for the 2 screen 3D. They do share VRAM, so if one core is only doing simple stuff, more VRAM can be allocated to another core. Also, reducing the amount of detail on one screen will mean the CPU has to process less objects for it (in the sense of characters, menu buttons, etc) and this extra time can be put into making the scene on the other screen more complex.

However, the way things are currently done in many games (3D main world on top screen, 2D control / map interface on touch screen) already dedicates most of the CPU power and VRAM to the main screen anyway, and there would be no significant gain to be had by disabling the other screen.

Of course, I am just talking out of my a**e here, so please correct me if I'm wrong.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#63350 - Marill - Mon Dec 12, 2005 5:53 am

ecurtz wrote:
Work in progress
[edit] Better version up in the same spot. Are there any other VRAM banks that can be used for Sub Background besides C? I think it would work at that point, at the expense of using up a ton of our video RAM. [/edit]


how about trying the rest like E, F, G...? i think it should work


Last edited by Marill on Mon Dec 12, 2005 6:15 am; edited 1 time in total

#63351 - Marill - Mon Dec 12, 2005 6:04 am

ninogenio wrote:
your right its strange that everything has to be rendered to the two screen from the sub 2d core its kind of like the capturing code isnt working quite as it should.ive spent most of 2 day playing with this trying to get it going and for the most part it does ive managed to render from one vram bank but the top display is ever so slightly faded.

the way i though this would have worked would have been to render to the main screen directly from the 3d core and inbtween frames to screen capture the object you want to display on the sub screen to to blit it to the sub bg.

any ideas any one!!!!!!!!!!!!



what about a method to do some "double bufferer"-ish kinda thing....

like instead of using only 1 bank, use 2.

so, for example,

this frame you capture to VRAM C and at the same time, display as 2D the contents of VRAM D.

next frame, capture to VRAM D and at the same time, display as 2D the contents of VRAM C.

I think your output looks slightly faded coz you can't display and capture to the same bank at the same time, so the display is disabled in that frame. So you could use 2 banks instead of 1 and probbly it will work.

#63425 - ninogenio - Tue Dec 13, 2005 12:56 am

i tried a ton of stuff with this your right atm you need two banks to make it work and i tried E F G but the only area of memory that worked was oam which is strange.

they way i thought this would work would only need one vram bank and thats what i was aming for would be to display to the main screen using the 3d chip and to the sub screen through main screen capture on the 2d core.

but the way it works is to use the sub 2d core to draw to both screens and it just lcd flips.

its strange and not quite right but hey its damn close

#70339 - Lino - Sun Feb 05, 2006 7:27 pm

StoneCyqh wrote:

.
.
capture source is 24-25
capture source offset is 26-27
.
.


What is the source? A memory bank? Or other form
Do you know it? Thanks

#100660 - iainprice - Tue Aug 29, 2006 11:39 am

I want to display a 3d model in vram, get the touch screen coords, index into vram to find the colour of the pixel, then draw the 3d model into the screen.

I assume I enable setregcapture using 5 for bank F which is setup for LCD.

I draw my model.

I disable setregcapture.

I draw my model.

If this is all OK, how do I index into vram? Is it just stored 1 bit for each pixel....

Cheers.

#100664 - Payk - Tue Aug 29, 2006 12:45 pm

As far as i know the reg just allows u to capture to vram a-d.
When its in vram A as a 256x192 pic it should be ordered like x+(y*256)
so if vramA is main bg u could just grap right pixel like:
u16 color=(u16*)BG_GFX[x+(y*256)]...
but this method would mean that this BG is displayed...better use Vram_A instead...not shure if and how that works exactly...didnt tried it...but should work.

The reg disables it self automatically after succesfully capturing...that takes till next frame as far as i know. so capture it. after next swiwaitforvlb u can grap the color and make with it what u would want.