Sign in to follow this  
littlekid

Cube mapping not working right

Recommended Posts

I am trying to do a cubic mapping on to a cube object. Here is the shader code that i have, I reference it out from the SDK effect sample.
VS_OUTPUT vs_skinning(in VS_INPUT In)
{
    VS_OUTPUT Out;
    Out.Position = mul(float4(SkinOut.Position, 1.0f), mul(World, View));
    float3 Normal = normalize(mul(SkinOut.Normal, (float3x3)mul(World, View)));
    float3 EyeReverse = normalize(Out.Position);
    Out.Position = mul(Out.Position, Projection);
    Out.Texture = 2 * dot(EyeReverse, Normal) * Normal - EyeReverse;
    Out.Color = Ambient + Diffuse + float4(1.0f, 1.0f, 1.0f, 1.0f);
    return Out;
}

PS_OUTPUT ps_skinning(in VS_OUTPUT In)
{
    PS_OUTPUT Out;
    Out.Color0 = texCUBE(CubeEnvSampler, In.Texture) * In.Color;
    return Out;
}
Issue 1: The reflection is not in order and I able to see the distinction between the 2 triangles that make up the quad of the object. Issue 2: The shader code is from the SDK, how is it that they don't need the Eye Position to do the reflection?

Share this post


Link to post
Share on other sites
the eye position in view space is 0 0 0 , so the vector from vertex to eye , is eye-vertex , wich means 0-vertex that's what they did in this line
float3 EyeReverse = normalize(Out.Position);
since the position was transformed to view space , the shader looks right , you should check your model how did you feed the normals to the shader , the matrices , and your cube map image file.

Share this post


Link to post
Share on other sites
I realise the problem i have is that when looking at a reflective surface, if i am to hover around it and look at it, the reflection turns along with the camera.

E.g
This is the reflection image of the celling I have when I look at the top reflective surface of my cube.

Reflection
|---|
| ^ |
|---|

Celling
|---|
| ^ |
|---|

I rotate my camera 90 degrees CW, the reflection rotates 90 degrees CW along with the camera, hence it appear upright too:

Reflection
|---|
| ^ |
|---|

Celling
|---|
| < |
|---|

Shouldn't the reflection stays as it is and not rotate? Where does the problem arises from, how do i fix this?

Share this post


Link to post
Share on other sites

ok here's your vertex shader in a different way , you'll have to provied the eye position, name it eyePos

VS_OUTPUT vs_skinning(in VS_INPUT In)

{

VS_OUTPUT Out;

float4 p=mul(float4(SkinOut.Position, 1.0f),World);
Out.Position = mul(p, mul(View, Proj));

float3 Normal = normalize(mul(SkinOut.Normal,World));

float3 EyeReverse = normalize(eyePos-p);



Out.Texture = 2*Normal*dot(EyeReverse,Normal)-EyeReverse;

Out.Color = Ambient + Diffuse + float4(1.0f, 1.0f, 1.0f, 1.0f);

return Out;

}

Share this post


Link to post
Share on other sites
Whenever I move my camera around, the reflective image seems to warp at the edge of the triangles.
How do i get rid of the warping at the edges of each triangles?

I have included a image that shows the problem circled in red

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