Home Forums Games202-高质量实时渲染 硬阴影结果诡异,不知哪里错了

Viewing 3 reply threads
  • Author
    Posts
    • #8211 Score: 0
      四上悠亚
      Participant

      `
      CalcLightMVP(translate, scale) {
      let lightMVP = mat4.create();
      let modelMatrix = mat4.create();
      let viewMatrix = mat4.create();
      let projectionMatrix = mat4.create();

      mat4.identity(modelMatrix);
      mat4.identity(lightMVP);
      mat4.identity(viewMatrix);
      mat4.identity(projectionMatrix);
      // Model transform
      // dest mat, source mat, operation mat
      mat4.translate(modelMatrix, modelMatrix, translate);
      mat4.scale(modelMatrix, modelMatrix, scale);
      // View transform
      mat4.lookAt(viewMatrix, this.lightPos, this.focalPoint, this.lightUp);
      // Projection transform
      mat4.ortho(projectionMatrix, -100, 100, -100, 100, -100, 100);

      mat4.multiply(lightMVP, projectionMatrix, viewMatrix);
      mat4.multiply(lightMVP, lightMVP, modelMatrix);

      return lightMVP;
      }
      }

      float useShadowMap(sampler2D shadowMap, vec4 shadowCoord){
      float shadowMapDepth = unpack(texture2D(shadowMap, shadowCoord.xy));
      if(shadowCoord.z > shadowMapDepth){
      return 0.0;
      }
      return 1.0;
      }

      void main(void) {

      float visibility;
      vec3 shadowCoord = vPositionFromLight.xyz / vPositionFromLight.w;
      shadowCoord = shadowCoord.xyz * 0.5 + vec3(0.5, 0.5, 0.5);
      visibility = useShadowMap(uShadowMap, vec4(shadowCoord, 1.0));
      //visibility = PCF(uShadowMap, vec4(shadowCoord, 1.0));
      //visibility = PCSS(uShadowMap, vec4(shadowCoord, 1.0));

      vec3 phongColor = blinnPhong();

      gl_FragColor = vec4(phongColor * visibility, 1.0);
      // gl_FragColor = vec4(phongColor, 1.0);
      }

      `

      Attachments:
      You must be logged in to view attached files.
    • #8361 Score: 0
      小夜子
      Participant

      先加个bias,if(shadowCoord.z-bias > shadowMapDepth),这样,bias设置成0.005,另外调整下正交矩阵的参数,感觉是范围太小了。

    • #8396 Score: 0
      Participant

      正交矩阵 near和far的问题,没有完全包围住场景

    • #16924 Score: 0
      remoo
      Participant

      far平面不够

Viewing 3 reply threads
  • You must be logged in to reply to this topic.