Projecting cubemaps

Started by
5 comments, last by Tessellator 18 years, 8 months ago
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
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 );
Edit: My mind a splode: SimmerD is...WRONG? http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/directx9_c_Oct_2004/directx/graphics/reference/highlevellanguageshaders/intrinsicfunctions/texcubeproj.asp

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
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.
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.
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

This topic is closed to new replies.

Advertisement