CUBEMAP THINGY
Blitz3D Forums/Blitz3D Programming/CUBEMAP THINGY
| ||
..i'm playing around with different cubemap systems I find here on forums, as well as with my own cubemap system...anyway, I'm not trying to make any comparisons between different cubemapsystem I already try..I realized that all cubemap systems I try, start stuglling after I create third cubemap texture stored in VRAM (let say I wanna make 3 objects cubemapped at same time)...now..interesting thing is that if I have 3 cubemap textures in VRAM with 32x32 size, system struglling..and if I disable one and try system with two cubemap textures but this time size 512x512, system working 3 times faster even Video memory is used more than in previous case...first I'm thought its COPYRECT thingy what cousing slowdown, so I just disable updating one of the cubemaps from main loop...but I realized, system will be still slow until I actually disable creatinf one of the 3 cubemaps...I'm wondering if my card is not even 5% under pressure (if we talking about memory, its 256MBVRAM), whats happening then.. |
| ||
of course, updating a cubemap includes 6*RenderWorld. Depending on the complexity of your scene this may be slow. Copyrect will work with the same speed, no matter how big your scene is. Although Copyrect's not very fast, it's still bearably quick when you use the 256 texture flag (vram residence). In the code archives there's some code to make cubemapping faster. I think it uses 6 cameras, CameraViewport etc. to render the 6FOV in one Renderworld. (tho this limits the resolution of the cubemap somewhat). Finally I would suggest to render only one cubemap because there is no need to render mutliple cubemaps! IMHO it's a fatal mistake to assume you'd need to create cubemaps for every cubemapped object! The reason why is: whatever is reflected on an object, it's all relative to the player camera, and not to the object! So unless you have a splitscreen or something, you only need one cubemap, it may be used for all objects, no matter if they are near or far. I already discribed this some time ago: _________>o main game camera ______/ _________/___________________ground (not doublesided!) \....... \.........>o cubemapping camera so the cubemapping camera has to be positioned at the same x and z location as the player camera, but the Y position needs to be as much below the ground as the player camera is above the ground - something like that. But after all it's not an exact science, so be prepared to fiddle for a while. |
| ||
..yes..thats ok JFK..what I'm trying to say that it was just testing of my video card, but for example, 3 cubemaps with 32x32 is slower than 2 with 512x512, thats whats confusing me, even memory resources(VRAM) is much more saved in first case..and to be sure that copyrect/renderworld is not an issue, I disable it from main loop, but still leave creation of all 3 cubemap textures before main loop, and whats happen? Even i didnt update one of them in main loop (only two of them) system is same slow as in case with update in main loop...but, if I disable creation of third cubemap texture before main loop, system become very fast...point is..in both cases I didnt do third cubemap update, so why system goes down, and why is so fast with 2 cubemaps (created, not updated in main loop) even with much more bigger textures?? Whats the deal.. |
| ||
Have you tried what happens if you load 3 different cubemap textures before main loop instead creating them? |
| ||
I'm not sure what you think by 'load 3 different cubemap' since they depending from player camera perspective..anyway here is case.. when you do this before main loop tex1=CreateTexture(32,32,1+128+256) tex2=CreateTexture(32,32,1+128+256) tex3=CreateTexture(32,32,1+128+256) frame is instantly killed even if I updating only 2 of them.. now, if I delete any of previous cubemaps and leave things like this before main loop tex1=CreateTexture(512,512,1+128+256) tex2=CreateTexture(512,512,1+128+256) and updating both cubemaps within main loop, frame rate is excellent.. my question how come? In the last case I'm updating two 512x512 cubemaps what cousing bigger VRAM usage, but frame rate is excellent...in the first case I'm also updating just 2 of 3 cubemaps and much more smaller, but FPS is horrible..only difference is that I create one cubemap texture more before main loop, but I didnt update it in main loop...and for three 32x32 cubemaps, memory usage is smaller than for two 512x512 and at same time its faster than case with 32x32...I'm confused..whats happening ?? |
| ||
I think its caus' your calling RenderWorld so many times in a single loop. Try calling the update cubemap function once every three loops for each cubemap, so first loop cubemap 1 will be rendered, seccond number 2... third loop number 3. You could do it with something like this:Iterator = Iterator + 1 Select Iterator Case 1 UpdateCubeMap1() Case 2 UpdateCubeMap2() Case 3 UpdateCubeMap3() Iterator = 1 End Select Try that and see if there's any speed difference. |
| ||
Leiden...I did mention that I'm calling always two cubemap updates, in both cases..difference is only in number of created cubemaps... |
| ||
Ahh I see, your block paragraph was so poorly punctuated I skim read it ;) Memory leek possibly? Run you app and look at the memory usage in Task Manager. If it increases over time somethings wrong :( |
| ||
..but this is pretty weird...I mean, memory consumption is bigger in 512x512 case, with same number of updates (2)..so I'm wondering whats happening with FPS becouse of adding just one cubemap texture in to VRAM, even without update in main loop...strange.. |
| ||
Naughty, I was just meaning that check if there are difference between loaded and created texture, just basic debugging :) edit: I tried loading 3 cubemaps... works as smooth as 2 or 1.. (I know, I'n not updating them in main loop..) |
| ||
..well..there is difference..I got 'Texture doesnt exist'..I put some textures 512x512, but with 128 flag I'm getting error, or I miss something.. |
| ||
Those are naturally cube textures, try creating for example 384 x 64 size images on your favorite paint program. |
| ||
jfk EO-11110 , Your explanation makes my Cubemapping system not half as ueful ^.^ It still does the itteration thing. *points to sig* |
| ||
..ok, whats the proper order for this sequence in order to get proper cubemap texture Finjogi?? Left->Forward->Right->Backward->Up->Down?? |
| ||
Cygnus - I know, a lot of people refused to believe me this, just try it, you can gain a lot of speed when you need only one Map. And it really works, I even used it for water this way and things where reflected in correct angles, no matter what my Y position was. |
| ||
JFK, in my case I have one room (actually few of them, depend on floor), where every wall inside room is reflective...anyway, I solve this with only one camera per reflective surface with use in total two cubemaps, and working fine...I'm just curious is it any other better way to solve this and suddenly find out this weird thingy already explained before.. |
| ||
Order you mentioned is same as it in help file.. Mayby I did something wrong but I created them in order 0...5 but somehow visibly my order was Left(0)-Back(1)-Right(2)-Front(3)-Up(4)-Down(5) I Have to check this out why it seems to be that way.. |
| ||
ok..I'll give it a try... |
| ||
Sorry about confusion about the cubemap order, help file is right, viewer position is thought to INSIDE that cube, I was thinking order as it appears when you apply that map to object -> cubemaps back texture is projected to front.. confusing eh :) edit: I just tested updating all 3 cube textures in main loop everytime, works just fine, no slowdown at all. My combination: W2k, Sempron 2600+, Geforce 6600GT |
| ||
what graphic card you use for testing...I try things on nVidia 5600XT card with 256 MB RAM...can you post code u using for update in main loop? |
| ||
Naughty.. have you made any progress? I imagine you could have done testing code in one minute :) but anyway here it is. Gfx card I use is Geforce 6600GT like I mentioned previous post :) |
| ||
Please try this, on the way I already explain at begin...you know..try to disable one of the cubemaps update from main loop, but at same time leave it created all of them before main loop...nothing new in this code, I'm just wondering what will happen on your card..and take a look at AvailVidMem()...main reason why I did this tests is fact that I have plenty of reflective surfaces in the project I'm doing now...Cubemaps on this way is absolutely not an option so I figure out something with cameras positioned at specific place in order to have proper reflections for some surfaces...anyway, give it a try..I'm wondering what will happen.. Graphics3D 640,480,32,2 SetBuffer BackBuffer() camera=CreateCamera() cube_cam=CreateCamera() HideEntity cube_cam light=CreateLight() RotateEntity light,45,45, 0 ; Create sphere sphere1=CreateSphere() sphere2=CreateSphere() sphere3=CreateSphere() ;tex1=LoadTexture("cube1.bmp", 1+128+256) ;tex2=LoadTexture("cube2.bmp", 1+128+256) ;tex3=LoadTexture("cube3.bmp", 1+128+256) tex1 = CreateTexture(64,64, 1+128+256) tex2 = CreateTexture(64,64, 1+128+256) tex3 = CreateTexture(64,64, 1+128+256) PositionEntity sphere1,-2,0,0 PositionEntity sphere2,0,0,0 PositionEntity sphere3,2,0,0 EntityTexture sphere1, tex1 EntityTexture sphere2, tex2 EntityTexture sphere3, tex3 cube_mode=1 While Not KeyDown(1) ; Control camera ; mouse look mxs#=mxs#+(MouseXSpeed()/5.0) mys#=mys#+(MouseYSpeed()/5.0) RotateEntity cam,mys#,-mxs#,0 MoveMouse width/2,height/2 ; move camera forwards/backwards/left/right with cursor keys If KeyDown(200)=True Then MoveEntity cam,0,0,.2 ; move camera forward If KeyDown(208)=True Then MoveEntity cam,0,0,-.2 ; move camera back If KeyDown(205)=True Then MoveEntity cam,.2,0,0 ; move camera left If KeyDown(203)=True Then MoveEntity cam,-.2,0,0 ; move camera right ; If M key pressed then change cube mode If KeyHit(50) cube_mode=cube_mode+1 If cube_mode=4 Then cube_mode=1 SetCubeMode tex,cube_mode EndIf ; Turn ufo pivot, causing child ufo mesh to spin around it (and teapot) TurnEntity ufo_piv,0,2,0 ; Hide our main camera before updating cube map - we don't need it to be rendererd every time cube_cam is rendered HideEntity cam ; Update cubemap UpdateCubemap(tex1,cube_cam,sphere1) UpdateCubemap(tex2,cube_cam,sphere2) UpdateCubemap(tex3,cube_cam,sphere3) ; Show main camera again ShowEntity cam RenderWorld Text 0,0,"Use mouse to look around" Text 0,20,"Use cursor keys to change camera position" Text 0,40,"Press M to change cube mode" Text 0,60,"SetCubeMode tex,"+cube_mode Flip Wend Function UpdateCubemap(tex,camera,entity) tex_sz=TextureWidth(tex) ; Show the camera we have specifically created for updating the cubemap ShowEntity camera ; Hide entity that will have cubemap applied to it. This is so we can get cubemap from its position, without it blocking the view HideEntity entity ; Position camera where the entity is - this is where we will be rendering views from for cubemap PositionEntity camera,EntityX#(entity),EntityY#(entity),EntityZ#(entity) CameraClsMode camera,False,True ; Set the camera's viewport so it is the same size as our texture - so we can fit entire screen contents into texture CameraViewport camera,0,0,tex_sz,tex_sz ; Update cubemap ; do left view SetCubeFace tex,0 RotateEntity camera,0,90,0 RenderWorld CopyRect 0,0,tex_sz,tex_sz,0,0,BackBuffer(),TextureBuffer(tex) ; do forward view SetCubeFace tex,1 RotateEntity camera,0,0,0 RenderWorld CopyRect 0,0,tex_sz,tex_sz,0,0,BackBuffer(),TextureBuffer(tex) ; do right view SetCubeFace tex,2 RotateEntity camera,0,-90,0 RenderWorld CopyRect 0,0,tex_sz,tex_sz,0,0,BackBuffer(),TextureBuffer(tex) ; do backward view SetCubeFace tex,3 RotateEntity camera,0,180,0 RenderWorld CopyRect 0,0,tex_sz,tex_sz,0,0,BackBuffer(),TextureBuffer(tex) ; do up view SetCubeFace tex,4 RotateEntity camera,-90,0,0 RenderWorld CopyRect 0,0,tex_sz,tex_sz,0,0,BackBuffer(),TextureBuffer(tex) ; do down view SetCubeFace tex,5 RotateEntity camera,90,0,0 RenderWorld CopyRect 0,0,tex_sz,tex_sz,0,0,BackBuffer(),TextureBuffer(tex) ; Show entity again ShowEntity entity ; Hide the cubemap camera HideEntity camera End Function |
| ||
After fixing your code to get it running it worked just fine here at my work (here I have Radeon mobility 9000) all 3 cubemaps updated Ok without problems. Availvidmem() was about 19megs out of 32 I think. Anyway, here is fixed code in case someone wants to try it. I'll test it again when I get back to home. edit: Works fine on my home computer. |
| ||
..I'll give it a try when I get back home too.. |
| ||
A little note about cubemap textures : If the reflective surface is static (does not turn move) you can capture a cubemap texture (from the reflective surface point of view (front, back, left, right, up, down)) before the mainloop and then not have to capture it again. The turning moving entities will not be seen in the reflections but the reflections will be convincing enough and very fast to render comparing to have to render, each frame, 6 views for each reflective surface... |