Jump to content
• Advertisement

# Specular Mapping with a doubles camera

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

If you intended to correct an error in the post then please contact us.

## 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

##### Share on other sites
Advertisement
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

##### Share on other sites
Yeah there are no projective transforms anywhere in the specular code. Maybe I can make a video, its hard to describe it I guess even with a picture.

Anyone else have any thoughts?

-Toaster

#### Share this post

##### Share on other sites
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

##### Share on other sites
Quote:
 Original post by macnihilistIf 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

##### Share on other sites
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

##### Share on other sites
Pulling Towards Poles

You can see how its pulled towards the poles. :/

I made sure everything was correct it just seems to do this.

-Toaster

#### Share this post

##### Share on other sites
What does this picture show? Object-space tangents? If so, they look wrong to me.
You can check what you really have in your buffers and shaders by using a Single Frame Capture in PIX.
Other than that I have no idea what could be wrong, sorry.

#### Share this post

##### Share on other sites

• Advertisement

### Announcements

• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5
• Advertisement

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631419
• Total Posts
2999983
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!