GOT IT! Many thanks, you've send me in the right direction.
The solution was doing the Normal with WorldMatrix multiplication in the Diffuse calculation.
Here it is:
[source lang="cpp"]/****************************************************/
/** VARS NOT CONTROLLED BY CREALYSM ENGINE YET **/
/****************************************************/
// directional lighting
float3 DirLightDir < string UIDirectional = "Light Direction"; > = {0.0, 0.0, 1.0};
float4 DirLightDiffuse = { 1.0f, 1.0f, 1.0f, 0.5f }; // light diffuse
// modelfile, just for effectedit
string XFile = "objects\\house.x"; // model
/****************************************************/
/** VARS CONTROLLED BY CREALYSM ENGINE **/
/****************************************************/
struct VS_OUTPUT
{
float4 Pos : POSITION;
float4 Diff : COLOR0;
// float3 Norm : TEXCOORD1;
float2 Tex : TEXCOORD0;
};
float4x4 World : WORLD;
float4x4 ViewProj : VIEWPROJECTION;
float4 AmbientLight;
float4 MatAmb : MATERIALAMBIENT;
float4 MatDiff: MATERIALDIFFUSE;
texture Tex0 < string name = "textures\\wdplanks.png"; >;
/****************************************************/
/** THE ACTUAL VERTEXSHADER PROGRAM **/
/****************************************************/
VS_OUTPUT VS(
float4 Pos : POSITION,
float4 Diff: COLOR0,
float3 Norm: NORMAL,
float2 Tex : TEXCOORD0)
{
VS_OUTPUT Out = (VS_OUTPUT)0;
// calculate the WorldViewProj matrix
float4x4 WorldViewProj = mul(World, ViewProj);
// output final pos = pos * WorldViewProj
Out.Pos = mul(Pos, WorldViewProj);
Out.Diff = AmbientLight * MatAmb + DirLightDiffuse * MatDiff * max(0, dot(mul(Norm, World), -DirLightDir)); // diffuse + ambient
// Out.Norm = mul(Norm, WorldViewProj);
Out.Tex = Tex;
return Out;
}
/****************************************************/
/** SAMPLER STATES FOR TEXTURING **/
/****************************************************/
sampler Sampler = sampler_state
{
Texture = (Tex0);
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
};
/****************************************************/
/** BASIC VERTEXSHADER TECHNIQUE **/
/****************************************************/
technique BasicVertexShader
{
pass P0
{
zEnable = TRUE;
CullMode = CCW;
Lighting = TRUE;
SpecularEnable = FALSE;
Sampler[0] = (Sampler);
VertexShader = compile vs_2_0 VS();
PixelShader = NULL;
}
}[/source]
(not 100% right yet, it's now giving the ambient lighting value as diffuse but with all normals correct, so tweaking it now it will be easy).
Thanks again.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement