我用来计算片段sgader中阴影因子的代码是:
"float readShadowMap(){"
" int cascadeIdx = 0;"
" for(int i = 0; i < NUM_CASCADES - 1; ++i){"
" if(FViewPos.z < cascadeEndSpace[i]){"
" cascadeIdx = i + 1;"
" }"
" }"
" vec3 ProjCoords = LightSpacePos[cascadeIdx].xyz / LightSpacePos[cascadeIdx].w;"
" vec2 UVCoords;"
" UVCoords.x = 0.5f * ProjCoords.x + 0.5f; "
" UVCoords.y = 0.5f * ProjCoords.y + 0.5f; "
" float Depth = 0.0f;"
" if(cascadeIdx == 0)"
" Depth = texture(map_shadow[0], UVCoords).x;"
" else if(cascadeIdx == 1)"
" Depth = texture(map_shadow[1], UVCoords).x;"
" else if(cascadeIdx == 2)"
" Depth = texture(map_shadow[2], UVCoords).x;"
" const float bias = 0.0;"
" if (Depth < (ProjCoords.z * 0.5 + 0.5 + 0.0001))"
" return 0.5;"
" else"
" return 1.0;"
"}"
我注意到,如果我降低投影中的远值,则分辨率几乎不会提高,但仍然很差
camera = new Cameras::Camera(peye, ptarget, width, height, 1.0f, 200.0f, 45.0f);
和级联拆分为:
GLfloat cascadeSplits[NUM_CASCADES+1] = {nearClip,(farClip-nearClip)*0.08f,(farClip-nearClip)*0.2f,(farClip-nearClip)*0.6f,farClip-nearClip};