游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1888|回复: 1

PSSM and deferred shading (unfilled shadow)

[复制链接]

414

主题

611

帖子

621

积分

高级会员

Rank: 4

积分
621
发表于 2009-3-16 15:14:00 | 显示全部楼层 |阅读模式
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:


  1. void VS_RenderShadowMap(
  2.                                                 float4 vPos : POSITION,
  3.                                                 out float4 vPosOut : POSITION,
  4.                                                 out float3 vPixelOut : TEXCOORD0)
  5. {
  6.         // pass vertex position through as usual
  7.         vPosOut = mul(vPos, wvp);
  8.         // output pixel pos
  9.         vPixelOut=vPosOut.xyz;
  10. }

  11. float4 PS_RenderShadowMap(float3 vPixelPos : TEXCOORD0): COLOR
  12. {
  13.         // write z coordinate (linearized depth) to texture
  14.         return vPixelPos.z;
  15. }


  16. // This technique is used when rendering meshes to the shadowmap
  17. //
  18. technique RenderShadowMap
  19. {
  20.         pass p0
  21.         {
  22.                 // render back faces to hide artifacts
  23.                 CullMode = CW;
  24.                 ZWriteEnable=TRUE;
  25.                 ZEnable=TRUE;
  26.                 VertexShader = compile vs_3_0 VS_RenderShadowMap();
  27.                 PixelShader = compile ps_3_0 PS_RenderShadowMap();
  28.         }
  29. }

  30. void VS_SRT(
  31.                         in float4 vPos : POSITION,
  32.                         in float3 vNormal : NORMAL,
  33.                         in float4 vDiffuseTex : TEXCOORD0,
  34.                         out float4 vPosOut : POSITION,
  35.                         out float4 vShadowTex : TEXCOORD0,
  36.                         out float4 vDiffuseTexOut : TEXCOORD1
  37.                         )
  38. {
  39.         // pass vertex position through as usual
  40.         vPosOut = mul(vPos, wvp);

  41.         // coordinates for shadowmap
  42.         vShadowTex = mul(vPos, g_mShadowMap);
  43.         vDiffuseTexOut=vDiffuseTex;
  44. }

  45. float4 PS_SRT(
  46.                           float4 vShadowTex : TEXCOORD0,
  47.                           float4 vDiffuseTex: TEXCOORD1
  48.                           ) : COLOR
  49. {

  50.         float4 Color=tex2D(DiffuseMapSampler1, vDiffuseTex);
  51.         if (Color.a<0.5f)
  52.         {
  53.                 discard;
  54.         }
  55.        
  56.         //float fTexelSize=1.0f/g_fShadowMapSize;

  57.         // project texture coordinates
  58.         vShadowTex.xy/=vShadowTex.w;

  59. .......
  60.         if (g_bUseColorfulSplit==true)
  61.         {
  62. .......

  63. #ifdef _RETURN_FLOAT4_
  64.                 return float4(fLightingFactor,1.0f,1.0f,1.0f);
  65. #else
  66.                 return fLightingFactor;
  67. #endif
  68.         }
  69.        
  70. }

  71. technique generateSRT
  72. {
  73.         pass p0
  74.         {
  75.                 // render front faces
  76.                 //CullMode = CCW;
  77.                 CullMode=CCW;
  78.                 ZWriteEnable=TRUE;
  79.                 ZEnable=TRUE;               
  80.                        
  81.                 VertexShader = compile vs_3_0 VS_SRT();
  82.                 PixelShader = compile ps_3_0 PS_SRT();
  83.         }
  84. }
复制代码

0

主题

56

帖子

62

积分

注册会员

Rank: 2

积分
62
发表于 2009-3-16 21:22:00 | 显示全部楼层

Re:PSSM and deferred shading (unfilled shadow)

If your map editor and game share share the same shader, most likely your shader is correct.  You should check whether you have passed in some wrong parameters.  It seems to be difficult to figure out the root cause of the aliasing.  I recommend you debug it with PIX.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-20 02:30

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表