Jump to content
  • Advertisement
Sign in to follow this  
Tessellator

Projecting cubemaps

This topic is 4833 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I've projected 2D textures in the past (for spot lights and such), mostly with the FFP, but it seemed reasonably easy to move that thinking into a vertex/pixel shader. What i'd like to do is project a cube map using the programmable pipeline, alhough I'm not quite sure what it is I'm supposed to pass to the texCUBEproj instruction (in HLSL). In 2D, i'd multiply the world space pos back into the projector space (with texture offsets and biases included), and pass that along to the tex2Dproj instruction. I think what's confusing me is the fact im dealing with 3d coordinates, with a fourth for the divide. Can anyone give me a little pointer, or post a link to some info regarding this? I've googled but turned up very little info. Any help would be massively appreciated. :) Many thanks, T

Share this post


Link to post
Share on other sites
Advertisement
There is no 4th for the divide with a cubemap.

just do :

float4 cube_space_pos = world_space_pos - cubemap_pos;

half4 color = TexCUBEProj( cube_space_pos.xyz );

Share this post


Link to post
Share on other sites
I'm away from my home computer now so I can't give that a go, but I would think it would end up doing a divide by zero if in fact the docs are correct. I'll post back tomorrow once I've given it a go.

Edit: Just noticed the .xyz mask on the input, although the docs specify the input size as 4. Hopefully that'll work... as I said, I'll get back tomorrow. :)

Ta,
T

Share this post


Link to post
Share on other sites
I assume that TexCUBEProj() is merely there for completeness, as any cubetexture lookup for a vector should be equivalent to a lookup to the corresponding normalized vector.

Share this post


Link to post
Share on other sites
If you need it for a point-light projector, then just simply transform the surface point into light-space, and use this 3-vector for a cubemap lookup (texCUBE), no need to use the *proj variant.

Anyway, projected cubemaps work pretty much the same way as their planar counterparts : xyz is divided by w, and the standard cubemapping process applies from here : greatest (absolute) component is selected (face index), rest is divided by its absolute value, biased, and looked up.

Share this post


Link to post
Share on other sites
Well, texCUBE seems to work fine as suggested, so cheers guys! :)
I now do (the equivelant of):

float4 projLightVal = texCUBE(cubeSampler, mul(vLightToTexelDir, c_matToLightSpace));

Ta muchly,
T

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!