Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: camera and shader

Hybrid View

  1. #1
    Junior Member Regular Contributor
    Join Date
    Apr 2010
    Posts
    110

    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

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: camera and shader

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •