Sign in to follow this  
toasterthegamer

Specular Mapping with a doubles camera

Recommended Posts

Hello,

I've been working on a planet rendering system for a while now. We just recently implemented a doubles camera, and what I mean by that is to compensate for the lack of precision we setup a system where the meshes would move around the camera instead of the camera moving. So the camera is at 0, 0, 0 and all the meshes positions are based off of camerapos - meshpos.


Now my problem lies with specular right now. I calculate the view vector like so:

mul(float3(0, 0, 0) - WorldPosition, WorldTangentSpace);

This is ofc normalized as well. I use a point light for my light source and I calculate the light vector like so:

mul(LightPos - WorldPosition, WorldTangentSpace);

The lighting works great, and I have no issues with it however when I applied the specular I get lots of weird errors. Here's my specular code:

float CalculateLyon(float3 VV, float3 LV, float3 NV)
{
float3 HalfWay = normalize(VV + LV);
float3 Difference = HalfWay - NV;
float SS = saturate(dot(Difference, Difference) * 1.5);
return pow(1 - SS, 25);
}

Where VV is the View Vector, LV is the Light Vector, and NV is the Normal Vector from the normal map.

This code has worked before when I have used it previously. I also tried another method of calculating and I get the same results. The specular appears to be warped and off center. It can only really be described by posting a picture.

Image 1
Image 2

As you can see they look rather horrible, the second one is decent but obviously offset from where it should be I believe.

My sphere is created in 3DS max and it has auto generated tangents from XNA. My only guess is that the doubles camera is interfering with the specular some way I cant figure out on my own.

Thanks for any help you guys can give me!

-Toaster

[Edited by - toasterthegamer on October 11, 2010 12:00:42 PM]

Share this post


Link to post
Share on other sites
rubicondev    296
Are you sure there's no perspective transform in here?

The way the light bends in in the first image suggests that the point is moving away the closer to screen centre it gets.

But it's just a guess. As you see for yourself, guessing whats wrong with lighting in a picture is a lot harder than just knowing it isn't right!

Share this post


Link to post
Share on other sites
macnihilist    377
If you're using XNA you could try to debug the shader with PIX.

Things that I would check first:
Are the tangents correct? (This strange 'screw' in the lighting could be the result of screwed tangents -- in general I would light in world space, because tangent and object space can be non-uniformly distorted.)
Are VV and LV normalized prior to the calculation of HalfWay?

Out of curiosity: Is this some strange 'wrap-around' specular model you are using? I have never seen this before.

Share this post


Link to post
Share on other sites
Quote:
Original post by macnihilist
If you're using XNA you could try to debug the shader with PIX.

Things that I would check first:
Are the tangents correct? (This strange 'screw' in the lighting could be the result of screwed tangents -- in general I would light in world space, because tangent and object space can be non-uniformly distorted.)
Are VV and LV normalized prior to the calculation of HalfWay?

Out of curiosity: Is this some strange 'wrap-around' specular model you are using? I have never seen this before.


Okay first off the tangents SHOULD be fine cause they are auto generated with XNA, however I learned now to trust automated systems so I will look into this. I light in world tangent space and its always worked for me before in the past.

This is just lyon specular nothing special or "wrapped-around" about it, its similar to blinn and phong. I've tried those two and they produce this same error although differently, but the same type of error.

I always make sure to normalize my light vector and view vector, and I double checked this to make sure. However I found a different way of calculating the view vector and I want to try that to see if it works(there's a way to do it on the CPU).

-Toaster

Share this post


Link to post
Share on other sites
macnihilist    377
Quote:

I light in world tangent space and its always worked for me before in the past.

Usually this isn't a problem, what I meant was the following:
As long as only orthogonal matrices with uniform scaling are involved and the vectors are normalized after the transformation there is no problem. Typically one enforces an orthonormal (in world space) tangent frame to meet this condition. (Transform tangents/normal into world space, _orthonormalize_, then use these vectors as the basis for tangent space.)
But if there's e.g. a non-uniform scaling somewhere along the way from world to object/tangent space you can get wrong results. The reason is that for lighting calculations you typically want your dot-products to measure angles in world space, but dot-products in a distorted space won't necessarily do this. [At least that's what I think, somebody correct me if I'm wrong.]

Quote:

This is just lyon specular

I didn't know this model. It looks interesting, though. I'll read the paper tomorrow.

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