Cube maps and laziness

Blitz3D Forums/Blitz3D Programming/Cube maps and laziness

Picklesworth(Posted 2004) [#1]
When I set up a cube map around an object, do I honestly need to load in all those images? I plan to just use dynamic, realtime, cube maps no matter what; so I see no need to bother with loading images.
How do I do it anyway? Is there a tutorial somewhere?


Ken Lynch(Posted 2004) [#2]
No, there's no need to load images if you are generating them dynamically. Check the code archives or do a search to see if there's anything there - I remember seeing an example somewhere on these forums. The basic technique though is to render 6 images from a camera from the viewpoint of the object (up, down, left, right, back and front) and copy them to the texture.


Ken Lynch(Posted 2004) [#3]
Just did a quick search and found a function that should do the job:

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 



Ruz(Posted 2004) [#4]
how much of a speed hit would this be?
I was thinking of having a little bit of cube mapping in my 'duck pond'


Gabriel(Posted 2004) [#5]
Quite a lot, actually. Mark posted a demo of Markio with a cubemapped sphere in the castle. That was done realtime, and it shows the speed hit you can expect. I think it came with the 1.85 update, but if not, I'll see if I can find it.

The speedhit comes from having to CopyRect the rendered images to the texture. If it were possible to render to a texture, it would be much faster. Cubemapping itself is very fast, if you use a static texture. But a dynamic texture causes a fair amount of overhead, particularly for low end videocards, and you might want to consider only updating 1 face each frame or only updating every 5 frames or something like that.


Ruz(Posted 2004) [#6]
ah ok, so i will stick to the image method. haven't really tried it out fully yet, but will give it a go 'cause it does look really nice if done properly