Does anybody have some expr in HLSL + Mogre?

issingle

04-06-2010 18:43:11

hi,everybody,i am newbia to HLSL. my test code and material as follow.it's seemed that ogre loaded test material and no error and warning.
i want use vs and ps to simulate Specular effect.but the surface's color is white. How to?


material:

vertex_program VS_TEST hlsl
{
source VS_TEST.hlsl
entry_point vs_main
target vs_1_1

}

fragment_program PS_TEST hlsl
{
source PS_TEST.hlsl
entry_point ps_main
target ps_2_0
}

material HLSL_TEST
{
technique
{
pass
{
ambient 1 0.917647 0.211765 1
diffuse 1 0.917647 0.211765 1
//specular 0.72 0.72 0.72 10 0

vertex_program_ref VS_TEST
{
param_named_auto matWorldViewProjection worldviewproj_matrix
param_named_auto matWorldInverse inverse_transpose_world_matrix
param_named_auto matWorld world_matrix
param_named_auto vViewPosition camera_position
}
fragment_program_ref PS_TEST
{
param_named_auto vDiffuseColor surface_diffuse_colour
param_named_auto vAmbient surface_ambient_colour
//param_named vDiffuseColor float4 1.0 0 0 0 // although we manual set color,no effect too.
//param_named vAmbient float4 1.0 0 0 0 //
}
}

}

}




vertex shader:

float4x4 matWorldViewProjection;
float4x4 matWorldInverse;
float4x4 matWorld;
float4 vViewPosition;


struct VS_OUTPUT {
float4 P: POSITION;
float3 N: TEXCOORD0;
float3 ViewDir : TEXCOORD1;
float3 LightDir : TEXCOORD2;
};


VS_OUTPUT vs_main( float4 Pos : POSITION, float3 N : NORMAL )
{
VS_OUTPUT Output;

Output.P = mul(matWorldViewProjection ,Pos);
Output.N = mul(matWorldInverse,normalize(N)); // float3(1.0,0.0,0.0);

float3 pos = mul(matWorld,Pos);
float3 vdir = pos-vViewPosition; //float3(1.0,pos.y,vViewPosition.z);
Output.LightDir = normalize(vdir);
Output.ViewDir = normalize(vdir);
return( Output );

}



pixel shader

float4 vDiffuseColor;
float4 vAmbient;
float4 ps_main(
float3 N : TEXCOORD0,
float3 V : TEXCOORD1,
float3 L: TEXCOORD2) : COLOR
{
float3 Normal = normalize(N);
float3 LightDir = normalize(L);
float3 ViewDir = normalize(V);
float Diff = saturate(dot(Normal, LightDir));
// R = 2 * (N.L) * N – L float3
float3 Reflect = normalize(2 * Diff * Normal - LightDir);
float Specular = pow(saturate(dot(Reflect, ViewDir)), 15); // R.V^n
// I = A + Dcolor * Dintensity * N.L + Scolor * Sintensity * (R.V)n
return vAmbient + vDiffuseColor * Diff + vDiffuseColor * Specular;
}

smiley80

05-06-2010 11:10:20

It should work* if you use the Direct3d renderer.

*well it renders the entity bright orange without any specular lighting

issingle

06-06-2010 14:31:27

pass{
lighting off //<---add this,the shader works fine. but why? i don't understand.