Sign in to follow this  
xytor

Specular Highlight in the wrong place?

Recommended Posts

I am calculating my specular highlights in world space, in HLSL.
There is an XZ plane and a light slightly above the plane.

The problem is, the farther the light is from the origin of world space, the farther the highlight on the plane is from the light (and closer to the origin). (If the light moves right, the highlight also moves right but slower, so it is somewhere between the origin and the light).

When the camera moves, although the highlights change shape, they stay in the same place.

What could cause this problem?

Share this post


Link to post
Share on other sites
1. Is your view vector more than just float3(0, 0, 1)?
2. Are you world space normals calculated from float3 object space normals? If you would use float4's they would get translated (position) into world space and not only rotated.
3. Is everything properly normalized?
4. Are your dot products properly clamped between 0 and 1?
5. Are you sure your view vector is in world space (also check for 2. here)?

If this doesn't solve your problems, I'd recommend posting your code.

Share this post


Link to post
Share on other sites
Quote:
Original post by DarkChris
1. Is your view vector more than just float3(0, 0, 1)?
2. Are you world space normals calculated from float3 object space normals? If you would use float4's they would get translated (position) into world space and not only rotated.
3. Is everything properly normalized?
4. Are your dot products properly clamped between 0 and 1?
5. Are you sure your view vector is in world space (also check for 2. here)?

If this doesn't solve your problems, I'd recommend posting your code.


No, I don't think those are the problem...


[Edited by - xytor on October 15, 2010 7:21:08 PM]

Share this post


Link to post
Share on other sites
Well I've read through your first post again and also found no mistakes in your shader... But the only thing that could cause this problems and explains why there's no mistake in the shader would be, if the cameras position would always be (0,0,0) in world space...

Share this post


Link to post
Share on other sites
Quote:
Original post by DarkChris
Well I've read through your first post again and also found no mistakes in your shader... But the only thing that could cause this problems and explains why there's no mistake in the shader would be, if the cameras position would always be (0,0,0) in world space...


No, it's not. However, in the vertex shader, doing Vert.posWorld.xz*=0.5; makes it better. What's going on?

Share this post


Link to post
Share on other sites
Ok than you should either try debugging it by using PIX or visualizing every line of the code step by step, by returning the calculated values as the resulting color... You could at least try if the ViewVector colors change when moving the camera...

Share this post


Link to post
Share on other sites
Quote:
Original post by knighty
A wild guess: Maybe posCam in

float3 view = normalize(posCam-IN.posWorld);

is not properly initialized?


posCam is indeed properly initialized, I checked.

Actually, the problem seems to be IN.posWorld. This is a TEXCOORD1 that is passed from the vertex shader. For some reason, shader model 3 doesn't like POSITION to be used in the pixel shader.

Anyway, is it possible that the shader is interpolating the posWorld in a weird way?

Share this post


Link to post
Share on other sites
Quote:
Original post by Rubicon
Have you tried labelling all your vs out and ps in as TEXCOORDn ?


Doesn't the Vertex Shader need to output at least POSITION?
I tried labeling everything else as TEXCOORDn, but that changed nothing.

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