Try to use the shader with an entity or attach it in the script:
my.material=Ambient;
Finally I was able to make it work with entities by attaching it in the script or through the WED (both works now) But it still don't work with blocks.
Lite-C code
#include <acknex.h>
#include <default.c>
MATERIAL* MtlAmbient=
{
ambient_red = 250; // The ambient color.
ambient_green = 64;
ambient_blue = 64;
effect = "ambient.fx";
}
MATERIAL ShadedAmb = MtlAmbient; /*This line was a must for the material to appear in the WEB materials list*/
function main()
{
level_load("shop.wmb");
wait(2);
}
action shadedEntity()
{
my.material = MtlAmbient;
}
ambient.fx
/***********************************************************************************************
/ Copyright 2006 by Taco Cohen. All rights reserved
/***********************************************************************************************/
/***********************************************************************************************
/ Ambient Lighting Shader
/
/ OUTLINE:
/ This shader draws the object in a solid color given by the materials ambient color.
/
/ IMPLEMENTATION:
/ The vertex shader transforms the vertex to clip space. The pixel shader multiplies the
/ ambient color by the ambient intensity and returns that as the final pixel color.
/
/ NOTES:
/ -
/***********************************************************************************************/
/***********************************************************************************************
/ Global Variables:
/***********************************************************************************************/
// Tweakables:
static const float AmbientIntensity = 1.0f; // The intensity of the ambient light.
// Application fed data:
const float4x4 matWorldViewProj; // World*view*projection matrix.
const float4 vecAmbient; // Ambient color, passed by the engine.
/***********************************************************************************************
/ Vertex Shader:
/***********************************************************************************************/
void AmbientVS( in float4 InPos : POSITION,
out float4 OutPos : POSITION)
{
// Transform the vertex from object space to clip space:
OutPos = mul(InPos, matWorldViewProj);
}
/***********************************************************************************************
/ Pixel Shader:
/***********************************************************************************************/
float4 AmbientPS() : COLOR
{
return AmbientIntensity * vecAmbient;
}
/***********************************************************************************************
/ Technique:
/***********************************************************************************************/
technique AmbientTechnique
{
pass P0
{
VertexShader = compile vs_1_1 AmbientVS();
PixelShader = compile ps_1_1 AmbientPS();
}
}
Beside the fact that this didn't work with Blocks (which I'm using for walls) I have a concern here
The Material definition never appeared in the materials list in the WED
MATERIAL* MtlAmbient=
{
ambient_red = 250; // The ambient color.
ambient_green = 64;
ambient_blue = 64;
effect = "ambient.fx";
}
To solve this problem I added the following line
MATERIAL ShadedAmb = MtlAmbient;
Now one thing at a time, I just need to konw why it didn't work with blocks and did work with entities, does this has any relation to the version which I'm using