I am trying to make a Fresnel shader, the problem is that if I move the object from the [0,0,0] position , it looks broken.
I am using 3d Max 2008.
string ParamID = "0x003"; // this string tells 3ds Max to use the DXSAS compiler
float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >;
float4x4 ViewInverse : ViewInverse < string UIWidget = "None"; >;
float4x4 World : WORLD < string UIWidget = "None"; >;
struct app2vertex
{
float4 position : POSITION;
float4 normal : NORMAL;
};
struct vertex2pixel
{
float4 position : POSITION;
float3 eyeVec : TEXCOORD0;
float4 normal : TEXCOORD1;
};
vertex2pixel vertex(app2vertex In)
{
vertex2pixel Out = (vertex2pixel)0;
Out.position = mul(In.position, wvp);
Out.normal = mul(In.normal, World);
//--------------------------------------
float3 worldP = mul(In.position, World);
Out.eyeVec = (ViewInverse[3].xyz-worldP);
return Out;
}
float4 pixel(vertex2pixel In) : COLOR
{
float3 P = normalize(In.eyeVec);
float3 N = normalize(In.normal);
float col = 1-dot(P,N);
return float4(col,col,col,1);
}
technique Complete
{
pass simple
{
VertexShader = compile vs_1_1 vertex();
ZEnable = true;
ZWriteEnable = true;
CullMode = cw;
AlphaBlendEnable = false;
PixelShader = compile ps_2_0 pixel();
}
}
Thanks.
Replies
you are multiplying a float4 with a float4x4 matrix, which means rotation/scale AND translation is applied. But: "Thou shalt not translate your model's normals"
feed your normals as float3 (thats what they are!) and maybe you need to cast the float4x4 to float3x3 in that mul.
You are the Man CrazyButcher
Thanks!!