|
|
I meet a problem about using PSSM(Parallel-Split Shadow Maps) to render the shadow to a shadow result texture (restore the shadow pixel, 1 means lighted, 0 means shadowed). The shadow result texture is a render target texture with the format of R32F. My problem is that if I render a flag model in PS_SRT (pixel shader to generate shadow result texture) and using "return fLightingFactor;", I will see the nofilled shadow. If I using "return float4(fLightingFactor,1.0f,1.0f,1.0f);" in PS_SRT, I will see the filled shadow.
The filled shadow: http://cid-fbeb6373d9321a7f.skydrive.live.com/self.aspx/Questions/shadow/PSSM%7C_shadow%7C_fill.JPG
The unfilled shadow: http://cid-fbeb6373d9321a7f.skydrive.live.com/self.aspx/Questions/shadow/PSSM%7C_shadow%7C_notfill.JPG
The filled shadow also has a stranger aliasing problem. The program is written by my lowerclassman. I implement PSSM into this program. I also implement the PSSM into my MapEditor, but my MapEditor has no this stranger shadow aliasing and no unfilled problem---no matter the return statement ("return fLightingFactor;" or "return float4(fLightingFactor,1.0f,1.0f,1.0f);" ).(My MapEditor's flag shadow : http://cid-fbeb6373d9321a7f.skydrive.live.com/self.aspx/Questions/shadow/PSSM%7C_shadow%7C_fill%7C_ME%7C_no%7C_aliasing.JPG).
These are my partial shader code:
- void VS_RenderShadowMap(
- float4 vPos : POSITION,
- out float4 vPosOut : POSITION,
- out float3 vPixelOut : TEXCOORD0)
- {
- // pass vertex position through as usual
- vPosOut = mul(vPos, wvp);
- // output pixel pos
- vPixelOut=vPosOut.xyz;
- }
- float4 PS_RenderShadowMap(float3 vPixelPos : TEXCOORD0): COLOR
- {
- // write z coordinate (linearized depth) to texture
- return vPixelPos.z;
- }
- // This technique is used when rendering meshes to the shadowmap
- //
- technique RenderShadowMap
- {
- pass p0
- {
- // render back faces to hide artifacts
- CullMode = CW;
- ZWriteEnable=TRUE;
- ZEnable=TRUE;
- VertexShader = compile vs_3_0 VS_RenderShadowMap();
- PixelShader = compile ps_3_0 PS_RenderShadowMap();
- }
- }
- void VS_SRT(
- in float4 vPos : POSITION,
- in float3 vNormal : NORMAL,
- in float4 vDiffuseTex : TEXCOORD0,
- out float4 vPosOut : POSITION,
- out float4 vShadowTex : TEXCOORD0,
- out float4 vDiffuseTexOut : TEXCOORD1
- )
- {
- // pass vertex position through as usual
- vPosOut = mul(vPos, wvp);
- // coordinates for shadowmap
- vShadowTex = mul(vPos, g_mShadowMap);
- vDiffuseTexOut=vDiffuseTex;
- }
- float4 PS_SRT(
- float4 vShadowTex : TEXCOORD0,
- float4 vDiffuseTex: TEXCOORD1
- ) : COLOR
- {
- float4 Color=tex2D(DiffuseMapSampler1, vDiffuseTex);
- if (Color.a<0.5f)
- {
- discard;
- }
-
- //float fTexelSize=1.0f/g_fShadowMapSize;
- // project texture coordinates
- vShadowTex.xy/=vShadowTex.w;
- .......
- if (g_bUseColorfulSplit==true)
- {
- .......
- #ifdef _RETURN_FLOAT4_
- return float4(fLightingFactor,1.0f,1.0f,1.0f);
- #else
- return fLightingFactor;
- #endif
- }
-
- }
- technique generateSRT
- {
- pass p0
- {
- // render front faces
- //CullMode = CCW;
- CullMode=CCW;
- ZWriteEnable=TRUE;
- ZEnable=TRUE;
-
- VertexShader = compile vs_3_0 VS_SRT();
- PixelShader = compile ps_3_0 PS_SRT();
- }
- }
复制代码 |
|