great work, but i cant get it to work with the provided scene. Could it be that it has to do with my graphics card? (ATI Mobility Radeon X1600 with 256mb ram). I would love to see this running.
edit:
I have found out something pretty interesting:
As soon as the shader calculates tex2D(k_Ldepthmap, shadowUV ); the smooth variable content seems to be lost…
Also the k_lightIntensity and the k_lightcolor variable are empty (black when set to o_color) after the above tex2D call…
Not to mention that trying to put the content to another variable first, clears the copy as well…
edit:
i have rewritten the shader so it works on my machine. However due to the above limitations it does not consider the light color. Maybe it is interesting to somebody with similar problems.
edit:
fixed the disortion mentioned in the following post.
//Cg
//Cg
void vshader(float4 vtx_position : POSITION,
float2 vtx_texcoord0: TEXCOORD0,
float3 vtx_normal: NORMAL,
uniform float4 mspos_light,
uniform float4x4 trans_model_to_clip_of_light,
uniform float4x4 mat_modelproj,
uniform float4 k_xOffset,
uniform float4 k_yOffset,
uniform float4 k_dOffset,
out float4 l_position : POSITION,
out float2 l_texcoord0 : TEXCOORD0,
out float4 l_texcoord1 : TEXCOORD1,
out float3 l_texcoord2 : TEXCOORD2,
out float4 l_smooth)
{
float OffsetX = .5 + k_xOffset.x;
float OffsetY = .5 + k_yOffset.x;
float OffsetDepth = .5 + k_dOffset.x;
float4x4 biasMatrix = {
0.5f,0.0f,0.0f, OffsetX,
0.0f,0.5f,0.0f, OffsetY,
0.0f,0.0f,0.5f, OffsetDepth,
0.0f,0.0f,0.0f, 1.0f};
// vertex position
l_position = mul(mat_modelproj, vtx_position);
// ------preserving smooth shading---------
// vector from vertex to the light
float4 lightvec = normalize(mspos_light - vtx_position);
l_smooth = dot(vtx_normal, lightvec);
// transformation to the light's clip space
float4x4 textureMat = mul(biasMatrix, trans_model_to_clip_of_light);
l_texcoord0 = vtx_texcoord0;
l_texcoord1 = mul(textureMat, vtx_position);
}
//uniform float4 k_lightcolor,
void fshader(float2 l_texcoord0 : TEXCOORD0,
float4 l_texcoord1 : TEXCOORD1,
float4 l_smooth,
uniform sampler2D tex_0 : TEXUNIT0,
in uniform float4 k_lightIntensity,
in uniform float4 k_lightcolor,
uniform sampler2D k_Ldepthmap,
uniform sampler2D k_cutout,
out float4 o_color:COLOR)
{
float3 l_texcoord2 = l_texcoord1.xyz / l_texcoord1.w;
float4 shadow = tex2D(k_Ldepthmap, l_texcoord2 ); // shadows
float4 light = tex2Dproj(k_Ldepthmap, l_texcoord1); // lightning
float4 cutout = tex2D(k_cutout,l_texcoord2); //*lightContrast; // // the light texture
float4 baseColor = tex2D(tex_0, l_texcoord0); // object texture
float4 lighted = (l_smooth * shadow * baseColor * cutout * 0.5);
float4 shadowed = baseColor * l_smooth;
if (l_texcoord2.x>0.0 && l_texcoord2.x<1.0 && l_texcoord2.y>0.0 && l_texcoord2.y<1.0) {
o_color = lighted * 0.9 + shadowed * 0.1;
} else {
o_color = shadowed * 0.1;
}
}