跳到主要内容
← Advanced Rendering

Advanced Rendering

NDC in perspective projection

shader-learning 自学第 5 课:NDC in perspective projection

实时渲染 · 网格 GLSL

第 5 课:NDC in perspective projection

实现

uniform sampler2D iChannel0;

in vec4 vColor;
in vec3 vNormal;
in vec4 vPosProj;
in vec4 clipPos;

out vec4 FragColor;

const vec3 lightColor = vec3(2.0);
const vec3 lightDir   = normalize(vec3(1.0));

void main() {
  vec3 ndc = clipPos.xyz / clipPos.w;
  vec2 screenTexPos = ndc.xy * 0.5 + 0.5;
  vec4 screenTexel = texture(iChannel0, screenTexPos);


  vec3 normal = normalize(vNormal);
  float diffuse = max(0.0, dot(lightDir, normal));

  FragColor = screenTexel;
}