Light Pre-Pass Renderer

  1. Geometry Pass
    Depth(xy), Normal(xy) Geometry Buffer(이하 G-Buffer) 저장
  2. Light Properties Pass
    아래 최종 색상 식에 미리 계산된 항목을 Light Buffer(이하 L-Buffer)
    최종 색상 = Ambient + Shadow * Att * (N.L * diffuseColor * diffuseIntensity * diffuseLightColor + R.V^n * specularColor * specularIntensity * specularLightColor )

    Light Properties
    - N.L
    - LightColor (Diffuse, Specular)
    - R.V^n
    - Attenuation

    Light Texture(A8R8G8B8 format)
    - Channel 1 : diffuseLightColor.r * N.L * Att
    - Channel 2 : diffuseLightColor.g * N.L * Att
    - Channel 3 : diffuseLightColor.b * N.L * Att
    - Channel 4 : R.V^n * N.L *Att

    아래는 관련 Shader Code 입니다.

    half4 ps_main( PS_INPUT Input ) : COLOR
    {
    half4 G_Buffer = tex2D( G_Buffer, Input.texCoord );

    // Compute pixel position
    half Depth = UnpackFloat16( G_Buffer.zw );
    float3 PixelPos = normalize(Input.EyeScreenRay.xyz) * Depth;

    // Compute normal
    half3 Normal;
    Normal.xy = G_Buffer.xy*2-1;
    Normal.z = -sqrt(1-dot(Normal.xy,Normal.xy));

    // Computes light attenuation and direction
    float3 LightDir = (Input.LightPos – PixelPos)*InvSqrLightRange;
    half Attenuation = saturate(1-dot(LightDir / LightAttenuation_0, LightDir / LightAttenuation_0));
    LightDir = normalize(LightDir);

    // R.V == Phong
    float specular = pow(saturate(dot(reflect(normalize(-float3(0.0, 1.0, 0.0)), Normal), LightDir)), SpecularPower_0);

    float NL = dot(LightDir, Normal)*Attenuation;

    return float4(DiffuseLightColor_0.x*NL, DiffuseLightColor_0.y*NL, DiffuseLightColor_0.z*NL, specular * NL);

    }


  3. Geometry-2 Pass
    G-Buffer와 L-Buffer에 값을 가지고 최종 색상을 계산

    아래는 관련 Shader Code입니다.

    float4 ps_main( PS_INPUT Input ) : COLOR0

    {
    float4 Light = tex2D( Light_Buffer, Input.texCoord );
    float3 NLATTColor = float3(Light.x, Light.y, Light.z);
    float3 Lighting = NLATTColor + Light.www;

    return float4(Lighting, 1.0f);
    }


  4. Forward Rendering
    Translucency Objects Rendering(back to front)

댓글

이 블로그의 인기 게시물

고유가 자동차 5부제 2부제 기상천외 에피소드

야구 WBC 한국 대표팀 외국계 선수 출전 가능한 이유 (혈통 규정 완벽 정리)

대기업 프론트엔드(frontend) 프레임워크 성향