cgprogram shadow map problem

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
nor
Posts: 7
Joined: Mon Jan 29, 2007 2:43 am

cgprogram shadow map problem

Post by nor »

hi friends,i'm using Nadro's cgprogram inferface to implement shadow map effect,i don't know where my code is incorrect,here is my result: [img]http://www.aimachine.cn/Uploads/Upimage/103_NUP9UMQ]ER75NF}V.jpg[/img]

and the render part of shadowmap shader program:

Code: Select all

void applyShadowVS(
float3 Position : POSITION,
float4 UV : TEXCOORD0, // provided for potential use
float4 Normal : NORMAL, // ignored if BLACK_SHADOW_PASS
uniform float4x4 WorldXform,
uniform float4x4 WorldITXform,
uniform float4x4 WVPXform,
uniform float4x4 ShadowVPXform,
uniform float4x4 ViewIXform,
uniform float Bias,

out float4 HPosition : POSITION,
out float4 BgUV : TEXCOORD0,
out float4 LProj : TEXCOORD1
)
{
float4 Po = float4(Position.xyz,(float)1.0); // "P" in object coords
float4 Pw = mul(WorldXform,Po); // "P" in world coordinates
float4 Pl = mul(ShadowVPXform,Pw); // "P" in light coords
// LProj = Pl; // ...for pixel-shader shadow calcs


float4x4 BiasXform = float4x4(
0.5f, 0.0f, 0.0f, 0.5,
0.0f, 0.5f, 0.0f, 0.5,
0.0f, 0.0f, 0.5f, 0.5-Bias,
0.0f, 0.0f, 0.0f, 1.0f );
LProj = mul(BiasXform,Pl); // bias to make texcoord

float4 hpos = mul(WVPXform,Po); // screen clipspace coords
HPosition = hpos;
BgUV = hpos;

}

void applyShadowPS(
float4 HPosition : POSITION,
float4 BgUV : TEXCOORD0,
float4 LProj : TEXCOORD1,
uniform sampler2D ShadDepthSampler,
uniform sampler2D SceneSampler,
uniform float SDensity,
out float4 ocolor :COLOR
)
{

float shadowed = tex2Dproj(ShadDepthSampler,LProj).x;
shadowed = 1.0 - (SDensity*(1.0-shadowed));
float2 sp = 0.5 * float2(BgUV.x/BgUV.w,BgUV.y/BgUV.w);
sp += float2(0.5,0.5);
float4 BgColor = tex2D(SceneSampler,sp);
ocolor = tex2Dproj(ShadDepthSampler,LProj);
// ocolor = float4(shadowed*BgColor.rgb,BgColor.a);
}
the model doesn't have colormap so it looks white but it's truly a model with emt_solid shader,i rendered the shadow before and stored in a texture,and it is correct,so i suspect the problem must be in line

Code: Select all

ocolor = tex2Dproj(ShadDepthSampler,LProj);
,based on the result above it could be looped many times rendering,i don't know how to fix it,
I'm extremely grateful to your help.
Viz_Fuerte
Posts: 91
Joined: Sun Oct 19, 2008 5:29 pm
Location: Valencia (Spain)
Contact:

Post by Viz_Fuerte »

Try this:

Code: Select all

node->getMaterial(0).TextureLayer[0].TextureWrap = ETC_CLAMP_TO_EDGE;
Possibly because the texture to reach their limit is repeated indefinitely.
With the code above, the texture follows the edge of the mesh.

I do not know if this is correct. :lol:
Post Reply