@@ -276,9 +276,9 @@ void main()
276
276
attenuation = 1.0 ;
277
277
#endif
278
278
279
- #if defined(r_lightGamma )
280
- lightColor = pow (lightColor, vec3 (r_lightGamma ));
281
- ambientColor = pow (ambientColor, vec3 (r_lightGamma ));
279
+ #if defined(USE_PBR )
280
+ lightColor = pow (lightColor, vec3 (2.2 ));
281
+ ambientColor = pow (ambientColor, vec3 (2.2 ));
282
282
#endif
283
283
284
284
#if defined(USE_NORMALMAP)
@@ -319,7 +319,7 @@ void main()
319
319
320
320
// Recover any unused light as ambient, in case attenuation is over 4x or
321
321
// light is below the surface
322
- ambientColor = clamp (ambientColor - lightColor * surfNL, 0.0 , 1.0 );
322
+ ambientColor = max (ambientColor - lightColor * surfNL, vec3 ( 0.0 ) );
323
323
#endif
324
324
325
325
vec3 reflectance;
@@ -335,21 +335,18 @@ void main()
335
335
336
336
specular *= u_SpecularScale;
337
337
338
- #if defined(r_materialGamma)
339
- diffuse.rgb = pow (diffuse.rgb, vec3 (r_materialGamma));
340
- #if ! defined(SPECULAR_IS_METALLIC)
341
- specular.rgb = pow (specular.rgb, vec3 (r_materialGamma));
342
- #endif
338
+ #if defined(USE_PBR)
339
+ diffuse.rgb = pow (diffuse.rgb, vec3 (2.2 ));
343
340
#endif
344
341
345
342
float gloss = specular.a;
346
- #if defined(GLOSS_IS_ROUGHNESS )
347
- float roughness = gloss ;
343
+ #if defined(USE_PBR )
344
+ float roughness = 1.0 - specular.r ;
348
345
#else
349
346
float roughness = exp2 (- 3.0 * gloss);
350
347
#endif
351
348
352
- #if defined(SPECULAR_IS_METALLIC )
349
+ #if defined(USE_PBR )
353
350
// diffuse is actually base color, and green of specular is metallicness
354
351
float metallic = specular.g;
355
352
@@ -374,7 +371,7 @@ void main()
374
371
// from http://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
375
372
vec3 parallax = u_CubeMapInfo.xyz + u_CubeMapInfo.w * viewDir;
376
373
377
- #if defined(GLOSS_IS_ROUGHNESS )
374
+ #if defined(USE_PBR )
378
375
vec3 cubeLightColor = textureCubeLod (u_CubeMap, R + parallax, 7.0 * roughness).rgb * u_EnableTextures.w;
379
376
#else
380
377
vec3 cubeLightColor = textureCubeLod (u_CubeMap, R + parallax, 7.0 - gloss * 7.0 ).rgb * u_EnableTextures.w;
@@ -385,8 +382,8 @@ void main()
385
382
// vec3 cubeLightDiffuse = max(textureCubeLod(u_CubeMap, N, 6.0).rgb, 0.5 / 255.0);
386
383
// cubeLightColor /= dot(cubeLightDiffuse, vec3(0.2125, 0.7154, 0.0721));
387
384
388
- #if defined(r_framebufferGamma )
389
- cubeLightColor = pow (cubeLightColor, vec3 (r_framebufferGamma ));
385
+ #if defined(USE_PBR )
386
+ cubeLightColor = pow (cubeLightColor, vec3 (2.2 ));
390
387
#endif
391
388
392
389
// multiply cubemap values by lighting
@@ -421,8 +418,8 @@ void main()
421
418
422
419
lightColor = u_PrimaryLightColor;
423
420
424
- #if defined(r_lightGamma )
425
- lightColor = pow (lightColor, vec3 (r_lightGamma ));
421
+ #if defined(USE_PBR )
422
+ lightColor = pow (lightColor, vec3 (2.2 ));
426
423
#endif
427
424
428
425
#if defined(USE_SHADOWMAP)
@@ -434,28 +431,21 @@ void main()
434
431
435
432
gl_FragColor .rgb += lightColor * reflectance * NL2;
436
433
#endif
434
+
435
+ #if defined(USE_PBR)
436
+ gl_FragColor .rgb = pow (gl_FragColor .rgb, vec3 (1.0 / 2.2 ));
437
+ #endif
438
+
437
439
#else
438
440
lightColor = var_Color.rgb;
439
441
440
442
#if defined(USE_LIGHTMAP)
441
443
lightColor *= lightmapColor.rgb;
442
444
#endif
443
445
444
- #if defined(r_lightGamma)
445
- lightColor = pow (lightColor, vec3 (r_lightGamma));
446
- #endif
447
-
448
- #if defined(r_materialGamma)
449
- diffuse.rgb = pow (diffuse.rgb, vec3 (r_materialGamma));
450
- #endif
451
-
452
446
gl_FragColor .rgb = diffuse.rgb * lightColor;
453
447
454
448
#endif
455
449
456
- #if defined(r_framebufferGamma)
457
- gl_FragColor .rgb = pow (gl_FragColor .rgb, vec3 (1.0 / r_framebufferGamma));
458
- #endif
459
-
460
450
gl_FragColor .a = diffuse.a * var_Color.a;
461
451
}
0 commit comments