Here Im using a simple shader from RenderMonkey. Now I know about 80% of whats going on in this shader, but I cant get it to work... And I think the main reason for this is that Im sending it the wrong information from IRRLicht...
So my main question would be, what variables from IRRLicht would I need to send to this shader to make it work...? More exactly, what would I need to put in "services->setVertexShaderConstant()" for each variable in the shader...?
This is the shader:
Code: Select all
float3 fvLightPosition;
float3 fvEyePosition;
float4x4 matView;
float4x4 matViewProjection;
struct VS_INPUT
{
float4 Position : POSITION0;
float2 Texcoord : TEXCOORD0;
float3 Normal : NORMAL0;
};
struct VS_OUTPUT
{
float4 Position : POSITION0;
float2 Texcoord : TEXCOORD0;
float3 ViewDirection : TEXCOORD1;
float3 LightDirection : TEXCOORD2;
float3 Normal : TEXCOORD3;
};
VS_OUTPUT vs_main( VS_INPUT Input )
{
VS_OUTPUT Output;
Output.Position = mul( matViewProjection, Input.Position );
Output.Texcoord = Input.Texcoord;
float3 fvObjectPosition = mul( matView, Input.Position );
Output.ViewDirection = fvEyePosition - fvObjectPosition;
Output.LightDirection = fvLightPosition - fvObjectPosition;
Output.Normal = mul( matView, Input.Normal );
return( Output );
}
float4 fvAmbient;
float4 fvSpecular;
float4 fvDiffuse;
float fSpecularPower;
sampler2D baseMap;
struct PS_INPUT
{
float2 Texcoord : TEXCOORD0;
float3 ViewDirection : TEXCOORD1;
float3 LightDirection: TEXCOORD2;
float3 Normal : TEXCOORD3;
};
float4 ps_main( PS_INPUT Input ) : COLOR0
{
float3 fvLightDirection = normalize( Input.LightDirection );
float3 fvNormal = normalize( Input.Normal );
float fNDotL = dot( fvNormal, fvLightDirection );
float3 fvReflection = normalize( ( ( 2.0f * fvNormal ) * ( fNDotL ) ) - fvLightDirection );
float3 fvViewDirection = normalize( Input.ViewDirection );
float fRDotV = max( 0.0f, dot( fvReflection, fvViewDirection ) );
float4 fvBaseColor = tex2D( baseMap, Input.Texcoord );
float4 fvTotalAmbient = fvAmbient * fvBaseColor;
float4 fvTotalDiffuse = fvDiffuse * fNDotL * fvBaseColor;
float4 fvTotalSpecular = fvSpecular * pow( fRDotV, fSpecularPower );
return( saturate( fvTotalAmbient + fvTotalDiffuse + fvTotalSpecular ) );
}