Understanding how texCUBE works and writing cubemaps properly into a cube rendertarget
- by cubrman
My goal is to create accurate reflections, sampled from a dynamic cubemap, for specific 3d objects (mostly lights) in XNA 4.0.
To sample the cubemap I compute the 3d reflection vector in a classic way:
half3 ReflectionVec = reflect(-directionToCamera, Normal.rgb);
I then use the vector to get the actual reflected color:
half3 ReflectionCol = texCUBElod(ReflectionSampler, float4(ReflectionVec, 0));
The cubemap I am sampling from is a RenderTarget with 6 flat faces.
So my question is, given the 3d world position of an arbitrary 3d object, how can I make sure that I get accurate reflections of this object, when I re-render the cubemap. Should I build the ViewProjection matrix in a specific way? Or is there any other approach?