@@ -11,8 +11,6 @@ SAMPLER2D(s_texF0Metallic, SAMPLER_DEFERRED_F0_METALLIC);
1111SAMPLER2D (s_texEmissiveOcclusion, SAMPLER_DEFERRED_EMISSIVE_OCCLUSION );
1212SAMPLER2D (s_texDepth, SAMPLER_DEFERRED_DEPTH );
1313
14- uniform vec4 u_camPos;
15-
1614uniform vec4 u_lightIndexVec;
1715# define u_lightIndex uint(u_lightIndexVec.x)
1816
@@ -21,7 +19,7 @@ void main()
2119 vec2 texcoord = gl_FragCoord.xy / u_viewRect.zw;
2220
2321 vec4 diffuseA = texture2D(s_texDiffuseA, texcoord);
24- vec3 N = texture2D(s_texNormal, texcoord).xyz * 2.0 - 1.0 ;
22+ vec3 N = unpackNormal( texture2D(s_texNormal, texcoord).xy) ;
2523 vec4 F0Metallic = texture2D(s_texF0Metallic, texcoord);
2624
2725 // unpack material parameters used by the PBR BRDF function
@@ -31,18 +29,18 @@ void main()
3129 mat.F0 = F0Metallic .xyz;
3230 mat.metallic = F0Metallic .w;
3331
34- // get fragment world position
32+ // get fragment position
33+ // rendering happens in view space
3534 vec4 screen = gl_FragCoord;
3635 screen.z = texture2D(s_texDepth, texcoord).x;
37- vec4 eyePos = screen2Eye(screen);
38- vec3 fragPos = mul(u_invView, eyePos).xyz;
36+ vec3 fragPos = screen2Eye(screen).xyz;
3937
40- vec3 camPos = u_camPos.xyz;
41- vec3 V = normalize(camPos - fragPos);
38+ vec3 V = normalize(- fragPos);
4239
4340 // lighting
4441
4542 PointLight light = getPointLight(u_lightIndex);
43+ light.position = mul(u_view, vec4(light.position, 1.0 )).xyz;
4644
4745 vec3 radianceOut = vec3_splat(0.0 );
4846 float dist = distance(light.position, fragPos);
0 commit comments