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

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

## Recommended Posts

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 on other sites
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 on other sites
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 on other sites
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.

• 32
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631350
• Total Posts
2999478
×