Shader Help Needed

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Lovehina
Posts: 21
Joined: Fri May 19, 2006 12:24 pm

Shader Help Needed

Post by Lovehina »

Iv just started learning shaders and Im having alot of problems with them... :cry: My number one problem (well number two compared to matrix math) is that Im having trouble with which variables I should send from IRRLicht to my shader... So I was wondering if someone could help me with this...

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 ) );
      
}
LovehinaX
Posts: 7
Joined: Wed Nov 08, 2006 12:38 pm

Post by LovehinaX »

Ahh...Never mind. I solved it my self, by using a different shader...
But I think that it would be good idea to have a list of IRRLicht variables, such as ETS_WORLD, plus what their use might be in different shaders...
Iv said this a million times before, IRRLicht has a very easy to use API, especially for those who are learning to program, but the tutorials and help for it are not so user-friendly... :(
needforhint
Posts: 322
Joined: Tue Aug 30, 2005 10:34 am
Location: slovakia

Post by needforhint »

gee, don't cry in there . Why don't you find some relation between call back and shaders here http://www.medeal.sk/irr . A lot of samples have code
what is this thing...
Post Reply