Here is the shader:
Code: Select all
float4 NearColor = {1.0f, 1.0f, 1.0f, 1.0f};
float4 FarColor = {0.0f, 0.0f, 0.0f, 1.0f};
float Hither = 0.1;
float Yon = 1000.0;
float Gamma = 1.0;
void depthVS(
in float4 Position : POSITION,
out float4 HPosition : POSITION,
out float4 Color : COLOR0,
uniform float4x4 worldViewProj)
{
float4 Po = float4(Position.xyz, 1.0);
float4 hpos = mul(worldViewProj, Po);
float dl = (hpos.z - Hither) / (Yon - Hither);
dl = min(dl, 1.0);
dl = max(dl, 0.0);
dl = pow(dl, Gamma);
Color = lerp(NearColor, FarColor, dl);
HPosition = hpos;
}
float4 depthFS(in float4 color : COLOR) : COLOR0
{
return(color);
}
Here is the .program file:
Code: Select all
vertex_program Depth_VS cg
{
source depth.cg
entry_point depthVS
profiles vs_1_1 arbvp1
//This block saves us from manually setting parameters in code
default_params
{
//Ogre will put the worldviewproj into our 'worldViewProj' parameter for us.
param_named_auto worldViewProj worldviewproj_matrix
//Note that 'worldViewProj' is a parameter in the cg code.
}
}
fragment_program Depth_FS cg
{
source depth.cg
entry_point depthFS
profiles ps_1_1
}
Code: Select all
material tile
{
technique
{
pass
{
vertex_program_ref Depth_VS
{
}
fragment_program_ref Depth_FS
{
}
//lighting off
//ambient 0 0 0 1
//diffuse 1 1 1 1
//specular 0 0 0 1
//emissive 0 0 0
//texture_unit
//{
// texture tile.tga
// tex_coord_set 0
// colour_op modulate
// scale 1 1
// scroll 0 0
// rotate 0
//}
}
}
}
The result is a grey model no matter the distance from the camera. There are no errors reported in Ogre.log either. I have been trying to solve this all day with no luck. I hope I am just missing some small syntax error or something.