PDA

View Full Version : reflection mapping. Strange problem.Please help.



DSA
01-19-2004, 11:41 AM
Hi!

I want to create reflection mapping by cubemap.

Next source works fine (all geometry
defined in world space.) :

struct indata
{
float4 POS : POSITION;
float4 NORM : NORMAL;
float2 TEX0 : TEXCOORD0;
float4 TEX1 : TEXCOORD1;

};


struct outdata
{
float4 HPOS : POSITION;
float2 TEX0 : TEXCOORD0;
float3 TEX1 : TEXCOORD1;
float4 COL : COLOR0;

};

outdata main(indata IN )
{
outdata OUT;


OUT.HPOS = mul(glstate.matrix.mvp, IN.POS);
OUT.TEX0 = IN.TEX0;

//meshes defined in world space. instancing
//matrix is identity. This code works perfect!

float3 tr_normal=IN.NORM.xyz;
float3 eye_to_vert=EyePos-IN.POS.xyz;

eye_to_vert=normalize(eye_to_vert);
OUT.TEX1=reflect(eye_to_vert,tr_normal);

OUT.COL=float4(1.0,1.0,1.0,1.0);
return OUT;
}
----------------------------------------
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
But, next code not works correctly!
I can't understand why !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


struct indata
{
float4 POS : POSITION;
float4 NORM : NORMAL;
float2 TEX0 : TEXCOORD0;
float4 TEX1 : TEXCOORD1;

};


struct outdata
{
float4 HPOS : POSITION;
float2 TEX0 : TEXCOORD0;
float3 TEX1 : TEXCOORD1;
float4 COL : COLOR0;

};

outdata main(indata IN )
{
outdata OUT;


OUT.HPOS = mul(glstate.matrix.mvp, IN.POS);
OUT.TEX0 = IN.TEX0;

//another equivalent way to do reflection
//but this code gives wrong results.

float3 tr_normal=normalize(mul( glstate.matrix.invtrans.modelview[0],IN.NORM).xyz);

float3 eye_to_vert=normalize(mul(glstate.matrix.modelview[0], IN.POS).xyz);

OUT.TEX1=reflect(-eye_to_vert,tr_normal);

OUT.COL=float4(1.0,1.0,1.0,1.0);
return OUT;
}

Please , heeelp! Thaks!



[This message has been edited by DSA (edited 01-19-2004).]

v3gaz
01-21-2004, 03:02 PM
Hello,
The result of the reflect() is a vector expressed in the eye coordinates, which is not good if you want to access a cubemap (representing the world environment). All you have to do is to transform back the relected vector in world space.
By the way, no need to normalize the vectors!