Jump to content

Realtime Cubemap Reflection


TylerH
 Share

Recommended Posts

After speaking with Josh, though he is busy, I think I am doing it the proper way (yet it still isn't working)

 

-- Create cubemap camera
cubemapcamera = CreateCamera()

-- Create cubemap
cubemap = CreateCubemap(512,512)

-- Create cubemap 'gbuffer'
cubemapbuffer = CreateBuffer(512,512,1+2+4+8)

-- Create six buffers to render each cube face to
cubemapbufferpx = CreateBuffer(512,512,1+2+4+8)
cubemapbuffernx = CreateBuffer(512,512,1+2+4+8)
cubemapbufferpy = CreateBuffer(512,512,1+2+4+8)
cubemapbufferny = CreateBuffer(512,512,1+2+4+8)
cubemapbufferpz = CreateBuffer(512,512,1+2+4+8)
cubemapbuffernz = CreateBuffer(512,512,1+2+4+8)

-- Bind each buffer to a face of the cubemap
SetColorBuffer(cubemapbufferpx, cubemap, 0, 0) -- positive x
SetColorBuffer(cubemapbuffernx, cubemap, 0, 1) -- negative x
SetColorBuffer(cubemapbufferpy, cubemap, 0, 2) -- positive y
SetColorBuffer(cubemapbufferny, cubemap, 0, 3) -- negative y
SetColorBuffer(cubemapbufferpz, cubemap, 0, 4) -- positive z
SetColorBuffer(cubemapbuffernz, cubemap, 0, 5) -- negative z

Then during rendering:

-- Realtime cubemap
CameraProjMode(camera, 0) -- Disable player cam
PositionEntity(cubecamera,mesh.position) -- Position cubemap camera at the center of the mesh
CameraProjMode(cubecamera, 1) -- Enable cubemap camera

--Render Positive X
SetBuffer(cubemapbuffer)
RotateEntity(cubecamera, Vec3(0, 90, 0))
world:Render()
SetBuffer(cubemapbufferpx)
world:RenderLights(cubemapbuffer)

-- Render Negative X
SetBuffer(cubemapbuffer)
RotateEntity(cubecamera, Vec3(0, -90, 0))
world:Render()
SetBuffer(cubemapbuffernx)
world:RenderLights(cubemapbuffer)

--Render Positive Y
SetBuffer(cubemapbuffer)
RotateEntity(cubecamera, Vec3(-90, 0, 0))
world:Render()
SetBuffer(cubemapbufferpy)
world:RenderLights(cubemapbuffer)

-- Render Negative Y
SetBuffer(cubemapbuffer)
RotateEntity(cubecamera, Vec3(90, 0, 0))
world:Render()
SetBuffer(cubemapbufferny)
world:RenderLights(cubemapbuffer)

--Render Positive Z
SetBuffer(cubemapbuffer)
RotateEntity(cubecamera, Vec3(0, 0, 0))
world:Render()
SetBuffer(cubemapbufferpz)
world:RenderLights(cubemapbuffer)

--Render Negative Z
SetBuffer(cubemapbuffer)
RotateEntity(cubecamera, Vec3(0, -180, 0))
world:Render()
SetBuffer(cubemapbuffernz)
world:RenderLights(cubemapbuffer)

CameraProjMode(cubecamera, 0) -- Disable cubemap camera
CameraProjMode(camera, 1) -- Enable player camera

SetShader(GetMaterialShader(mesh.material))
BindTexture(cubemap,0) -- Bind cubemap to material
SetShader(nil)

-- render world to GBuffer and draw to BackBuffer as usual.

 

This is the result (all 6 individual buffers are rendered to fine, but the cubemap doesn't seem to be getting rendered to):

realtimecubema.png

 

Full script is attached.

cubemap.lua

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

I have no idea - at first glance hide/unhide the entity which uses the cubemap but aint doing nothing so does switching materials from invisible.mat to cubemap.mat.

What i didnt tried is to bind a dummy cubemap in the material and use kind of a FreeTexture before using cubemap.material or a freeBuffer on the cubemap buffers each pass.

 

Cant give anymore time on this currently. :)

AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3

zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5

 

adv_banner-april2012_720x150_tex01.png

 

Xxploration FPS in progress ...

Link to comment
Share on other sites

Josh suggested it may be an nVidia drivers issues, which I researched and found plausible. I need people with ATI cards to test this and see if it works, to determine if the issue lies in the code, or in the GPU drivers.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

In my mind, SetColorBuffer is not doing this:

-- Bind each buffer to a face of the cubemap

but rather is doing this:

-- Set a face of the cubemap to a buffer

 

and then you are rendering the buffer and it shows up as a texture in DrawImage, but I do not see a place where you are assigning the individual textures created from the buffers back into the cubemap itself. You need a way to copy those buffers back to those individual cubemap indexes I suspect for this to work. Something like SetCubeMap(cubemap,texture,index) seems like it would be needed...

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Hmmm, the cubemap faces are fine. Replace to

 

-- REALTIME CUBE MAP

CameraProjMode(camera, 0)
PositionEntity(cubecamera, camera.position)
CameraProjMode(cubecamera, 1)

 

its the upload through the material pipeline which isnt working as aspected.

i.e. "SetShader(GetMaterialShader(mesh.material))" might be a little to lazy. :huh:

 

PS: Hmmm, so we have to sphere map, the opposite direction that we are looking, to the mesh, through the material pipeline and have the cubemap rotate counterclockwise just so that it is not too easy, right ?

AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3

zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5

 

adv_banner-april2012_720x150_tex01.png

 

Xxploration FPS in progress ...

Link to comment
Share on other sites

Hmmm, the cubemap faces are fine. Replace to

 

-- REALTIME CUBE MAP

CameraProjMode(camera, 0)
PositionEntity(cubecamera, camera.position)
CameraProjMode(cubecamera, 1)

that sets the position of the cubemap camera to the normal camera's postion... which is fine if he was trying something like a cctv screen, but since he is trying to do a reflection, the cubemap camera needs to look out from the cube not at it.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

I have a realtime "cubemap" (of a sort) as an object scripted model.

except I am hacking it by having a different material on each face, rendering to each face's buffer, and then setting the resulting colorbuffer to each face's material... effectively creating a "cubemap". Using the framework camera for the buffer renders gives it a nice crystal clear reflection and all of the nice framework effects rendered... but its a fps killer doing 6 faces. For actual use in a game, you could just use a normal camera for the render which will give a greater fps boost.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

I have a realtime "cubemap" (of a sort) as an object scripted model.

except I am hacking it by having a different material on each face, rendering to each face's buffer, and then setting the resulting colorbuffer to each face's material... effectively creating a "cubemap". Using the framework camera for the buffer renders gives it a nice crystal clear reflection and all of the nice framework effects rendered... but its a fps killer doing 6 faces. For actual use in a game, you could just use a normal camera for the render which will give a greater fps boost.

 

Very cool. Care to share how you did that?

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

Cool your idea macklebee, i think right now would be more appropriate. But how could the normal check that is being presented at the render?

 

Thanks gilmer. I am not sure I understand exactly what you are asking... If its what I think you are asking then right now I am just setting the camera up to a predefined surface normal vector in the object script using a correctly oriented pivot.

 

Very cool. Care to share how you did that?

 

yeah, its pretty straight forward. I was trying to figure out the 3d angle of incidence math to get the reflection right, cause right now it just "reflects" straight out from the cube face... which looks ok but gives more of an impression that its a video screen than an actual reflection. Let me clean up my code and comment it and I will post it.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Sounds great :)

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

Here is the same concept added to a mirror model. It still suffers from the same problem as the cube as it doesn't use the angle of incidence to calculate the reflected image... but I have to go work out of town for the next three days so I won't be able to work on it. Perhaps someone like Tyler can figure out the proper math needed to get the angle of incidence/reflection? :)

 

I can upload the cube but it really is a fps killer and I don't want anyone to complain when their editor locks up! :)

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Try calling:

-- Bind each buffer to a face of the cubemap
SetColorBuffer(cubemapbufferpx, cubemap, 0, 0) -- positive x
SetColorBuffer(cubemapbuffernx, cubemap, 0, 1) -- negative x
SetColorBuffer(cubemapbufferpy, cubemap, 0, 2) -- positive y
SetColorBuffer(cubemapbufferny, cubemap, 0, 3) -- negative y
SetColorBuffer(cubemapbufferpz, cubemap, 0, 4) -- positive z
SetColorBuffer(cubemapbuffernz, cubemap, 0, 5) -- negative z

after every render.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...