camera and shader

Posted Today, 04:21 AM

float4x4 Matrix;
float4 NFactor;
float4 Ambient;
float4 MatDiff;

float4 LightDiff1;
float4 LightDir1;

float4 LightDiff2;
float4 LightDir2;

struct VS_INPUT
{
float4 Pos : POSITION;
float4 Normal : NORMAL;
float2 Tex0 : TEXCOORD0;
};

struct VS_OUTPUT
{
float4 Pos : POSITION;
float4 Color : COLOR;
float2 Tex0 : TEXCOORD0;
};

////////////////////////////////////////

VS_OUTPUT VShade(VS_INPUT In)
{
VS_OUTPUT Out = (VS_OUTPUT) 0;

    Out.Pos         = mul(Matrix,In.Pos);
    Out.Tex0        = In.Tex0;
    float4 Normal = In.Normal*NFactor;                      // N or -N

    // directional light 1

    float4 Color1 = max(0,dot(Normal,-LightDir1)) *MatDiff*LightDiff1;

    // directional light 2

    float4 Color2 = max(0,dot(Normal,-LightDir2)) *MatDiff*LightDiff2;

    // final color

    Out.Color       = Color1+Color2+Ambient;
    Out.Color.a   = MatDiff.a;

    return Out;

}

The shader is a front/back materials HLSL shader that i have converted to opengl cg , from:

http://www.fairyengi…ided.htm#sample

the problem is that if i move the camera position ,the geometry is deformed in wrong manner, instead if i don’t change camera position the geometry is correct.
How i can create a shader that support camera position changes?
thanks

What do you mean deformed in wrong manner?
Shader looks reasonable to me so can you explain your problem more clearly.