^DaNiEl^

04-04-2004, 07:50 AM

Hi, i've done a reflective bump mapping demo but i think there's something wrong in the code because if i move around the reflective object it reflects always rhe same part of enviroment. Please help me.

Here's the code:

VERTEX SHADER

struct vpin

{

float4 Position;

float3 Tangent;

float3 Binormal;

float3 Normal;

float2 TexCoord;

};

struct vpout

{

float4 Position : POSITION;

float2 TexCoord0 : TEXCOORD0;

float4 TexCoord1 : TEXCOORD1;

float4 TexCoord2 : TEXCOORD2;

float4 TexCoord3 : TEXCOORD3;

};

vpout main ( vpin IN,

uniform float4x4 ModelViewProj,

uniform float4x4 ModelView,

uniform float4x4 ModelViewIT,

uniform float4 EyePos,

uniform float BumpScale )

{

vpout OUT;

OUT.Position = mul( ModelViewProj, IN.Position );

float4 WSPosition = mul( ModelView, IN.Position );

float4 EyeVector = -WSPosition;

float3x3 TangentMatrix;

TangentMatrix[0] = IN.Tangent;

TangentMatrix[1] = IN.Binormal;

TangentMatrix[2] = IN.Normal;

OUT.TexCoord0 = IN.TexCoord;

OUT.TexCoord1.xyz = mul( TangentMatrix, ModelViewIT[0].xyz );

OUT.TexCoord2.xyz = mul( TangentMatrix, ModelViewIT[1].xyz );

OUT.TexCoord3.xyz = mul( TangentMatrix, ModelViewIT[2].xyz );

OUT.TexCoord1.w = EyeVector.x;

OUT.TexCoord2.w = EyeVector.y;

OUT.TexCoord3.w = EyeVector.z;

return OUT;

}

PIXEL SHADER

struct fpin

{

float2 TexCoord0 : TEXCOORD0;

float4 TexCoord1 : TEXCOORD1;

float4 TexCoord2 : TEXCOORD2;

float4 TexCoord3 : TEXCOORD3;

};

struct fpout

{

float3 Color : COLOR;

};

fpout main ( fpin IN,

uniform sampler2D NormalMap,

uniform samplerCUBE CubeMap,

uniform float4 Color )

{

fpout OUT;

float4 NormalTex = tex2D( NormalMap, IN.TexCoord0 ) * 2.0 - 1.0;

float3 EyeVector = float3( IN.TexCoord1.w, IN.TexCoord2.w, IN.TexCoord3.w );

float3 Normal = float3( dot( IN.TexCoord1.xyz, NormalTex.xyz ),

dot( IN.TexCoord2.xyz, NormalTex.xyz ),

dot( IN.TexCoord3.xyz, NormalTex.xyz ) );

float3 CubeTex = texCUBE( CubeMap, reflect( -EyeVector, Normal ) );

OUT.Color = CubeTex;

return OUT;

}

Here's the code:

VERTEX SHADER

struct vpin

{

float4 Position;

float3 Tangent;

float3 Binormal;

float3 Normal;

float2 TexCoord;

};

struct vpout

{

float4 Position : POSITION;

float2 TexCoord0 : TEXCOORD0;

float4 TexCoord1 : TEXCOORD1;

float4 TexCoord2 : TEXCOORD2;

float4 TexCoord3 : TEXCOORD3;

};

vpout main ( vpin IN,

uniform float4x4 ModelViewProj,

uniform float4x4 ModelView,

uniform float4x4 ModelViewIT,

uniform float4 EyePos,

uniform float BumpScale )

{

vpout OUT;

OUT.Position = mul( ModelViewProj, IN.Position );

float4 WSPosition = mul( ModelView, IN.Position );

float4 EyeVector = -WSPosition;

float3x3 TangentMatrix;

TangentMatrix[0] = IN.Tangent;

TangentMatrix[1] = IN.Binormal;

TangentMatrix[2] = IN.Normal;

OUT.TexCoord0 = IN.TexCoord;

OUT.TexCoord1.xyz = mul( TangentMatrix, ModelViewIT[0].xyz );

OUT.TexCoord2.xyz = mul( TangentMatrix, ModelViewIT[1].xyz );

OUT.TexCoord3.xyz = mul( TangentMatrix, ModelViewIT[2].xyz );

OUT.TexCoord1.w = EyeVector.x;

OUT.TexCoord2.w = EyeVector.y;

OUT.TexCoord3.w = EyeVector.z;

return OUT;

}

PIXEL SHADER

struct fpin

{

float2 TexCoord0 : TEXCOORD0;

float4 TexCoord1 : TEXCOORD1;

float4 TexCoord2 : TEXCOORD2;

float4 TexCoord3 : TEXCOORD3;

};

struct fpout

{

float3 Color : COLOR;

};

fpout main ( fpin IN,

uniform sampler2D NormalMap,

uniform samplerCUBE CubeMap,

uniform float4 Color )

{

fpout OUT;

float4 NormalTex = tex2D( NormalMap, IN.TexCoord0 ) * 2.0 - 1.0;

float3 EyeVector = float3( IN.TexCoord1.w, IN.TexCoord2.w, IN.TexCoord3.w );

float3 Normal = float3( dot( IN.TexCoord1.xyz, NormalTex.xyz ),

dot( IN.TexCoord2.xyz, NormalTex.xyz ),

dot( IN.TexCoord3.xyz, NormalTex.xyz ) );

float3 CubeTex = texCUBE( CubeMap, reflect( -EyeVector, Normal ) );

OUT.Color = CubeTex;

return OUT;

}