HLSL Reflection

Started by
12 comments, last by Roadkill247 16 years ago
I believe I found out the problem

float3 NormalVec = normalize( mul( Normal, ViewProjMatrix) );


should of been:

 float3 NormalVec = normalize( mul( ViewProjMatrix, Normal ) );


[Edited by - Roadkill247 on April 4, 2008 2:47:01 PM]
Advertisement
ok, implemented a reflection but now I seem to have found a small bug that I thought would be easy enough to fix but is giving me problems.

My reflection is working partially, because the cubemap that reflects off the water surface stays the same, as in it follows the camera round, so the texture thats reflected off the water never changes.

This is my vertex shader:
// Reflection WaterOutput o;		// Compute normal in camera spacefloat3 NormalVec = normalize( mul( ViewProjMatrix, Normal ) );    // Obtain the reverse eye vectorfloat3 EyeVec = normalize( mul( Position, ViewProjMatrix ) );    // Store the reflection vector in texcoordo.ReflectCoord = reflect( -EyeVec, NormalVec );o.RefractCoord = refract( EyeVec, NormalVec, 0.8f );        // Apply the projectiono.Position = mul( Position, ViewProjMatrix );  // Pass coords through         o.TexCoord = TexCoord;            return o;    // End of Reflection   


then the pixel shader:
// Cut down for examplereturn ( texCUBE( EnvSampler, i.ReflectCoord ) / 2.0f );
Anything you're using to calculate your reflection or refraction should not be multiplied your projection matrix. In fact the only thing that should be transformed by this should be the vertex position that you place in the POSITION register. You can't perform calculations in clip-space (projection space), since it's non-linear.
Problem is though, if I remove the multiplication, then the model vanishes, so I must be missing a line of code or something ?

This topic is closed to new replies.

Advertisement