Sign in to follow this  
danromeo

HLSL Problem...ARGGHH!!!....I just don't get it!

Recommended Posts

danromeo    238
Hi. In the following abbreviated code, I'm sending Vector3 Position to the HLSL variable float3 EyePosition. Then in the vertex shader, the following three lines: reflPos[0] = EyePosition[0]; //INCORRECT reflPos[1] = -EyePosition[1] + (inPos[1] * 2); //CORRECT reflPos[2] = EyePosition[2]; //INCORRECT the value of reflPos is (0, -1000, 0), regardless of the value of Position....should be (512, -1000, 550). Can anybody explain WHY? public Vector3 Position = new Vector3(512.0f, 1000.0f, 550.0f); ... public void DrawTerrain() { ... effect.Parameters["EyePosition"].SetValue(Position); ... effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); GraphicsDevice.DrawUserIndexedPrimitives( clip.PrimitiveType, clip.Vertices, 0, clip.Vertices.Length, clip.Indices, 0, clip.Triangles); pass.End(); } effect.End(); } /////////////HLSL///////////////////// float3 reflPos; uniform const float3 EyePosition; .... VertexShaderOutput VertexShaderFunction(float4 inPos : POSITION) { VertexShaderOutput output = (VertexShaderOutput)0; ... reflPos[0] = EyePosition[0]; //INCORRECT reflPos[1] = -EyePosition[1] + (inPos[1] * 2); //CORRECT reflPos[2] = EyePosition[2]; //INCORRECT }

Share this post


Link to post
Share on other sites
panic    211
Is reflPos[0] and reflPos[2] used in the shader later? If not that may be the problem. Unused variables will most probably be discarded by the compiler.

Share this post


Link to post
Share on other sites
Hodgman    51335
IMO, the array notation is making that code very confusing.
reflPos[0] = EyePosition[0];
reflPos[1] = -EyePosition[1] + (inPos[1] * 2);
reflPos[2] = EyePosition[2];
The above is equivalent to:
reflPos.x = EyePosition.x;
reflPos.y = -EyePosition.y+ (inPos.y * 2);
reflPos.z = EyePosition.z;
What do your INCORRECT/CORRECT comments mean? Are you saying you should only initialise the y component and leave x/z undefined?

Share this post


Link to post
Share on other sites
danromeo    238
The CORRECT/INCORRECT means that the values of reflPos[0] and reflPos[2] appear to be incorrect....always 0, where the value of reflPos[1] seems to be correct.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this