pbrIBLFunctions.fx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #if defined(REFLECTION) || defined(SS_REFRACTION)
  2. float getLodFromAlphaG(float cubeMapDimensionPixels, float microsurfaceAverageSlope) {
  3. float microsurfaceAverageSlopeTexels = microsurfaceAverageSlope * cubeMapDimensionPixels;
  4. float lod = log2(microsurfaceAverageSlopeTexels);
  5. return lod;
  6. }
  7. #endif
  8. #if defined(ENVIRONMENTBRDF) && defined(RADIANCEOCCLUSION)
  9. float environmentRadianceOcclusion(float ambientOcclusion, float NdotVUnclamped) {
  10. // Best balanced (implementation time vs result vs perf) analytical environment specular occlusion found.
  11. // http://research.tri-ace.com/Data/cedec2011_RealtimePBR_Implementation_e.pptx
  12. float temp = NdotVUnclamped + ambientOcclusion;
  13. return saturate(square(temp) - 1.0 + ambientOcclusion);
  14. }
  15. #endif
  16. #if defined(ENVIRONMENTBRDF) && defined(HORIZONOCCLUSION)
  17. float environmentHorizonOcclusion(vec3 view, vec3 normal) {
  18. // http://marmosetco.tumblr.com/post/81245981087
  19. vec3 reflection = reflect(view, normal);
  20. float temp = saturate(1.0 + 1.1 * dot(reflection, normal));
  21. return square(temp);
  22. }
  23. #endif
  24. // ___________________________________________________________________________________
  25. //
  26. // LEGACY
  27. // ___________________________________________________________________________________
  28. #if defined(LODINREFLECTIONALPHA) || defined(SS_LODINREFRACTIONALPHA)
  29. // To enable 8 bit textures to be used we need to pack and unpack the LOD
  30. //inverse alpha is used to work around low-alpha bugs in Edge and Firefox
  31. #define UNPACK_LOD(x) (1.0 - x) * 255.0
  32. float getLodFromAlphaG(float cubeMapDimensionPixels, float alphaG, float NdotV) {
  33. float microsurfaceAverageSlope = alphaG;
  34. // Compensate for solid angle change between half-vector measure (Blinn-Phong) and reflected-vector measure (Phong):
  35. // dWr = 4*cos(theta)*dWh,
  36. // where dWr = solid angle (delta omega) in environment incident radiance (reflection-vector) measure;
  37. // where dWh = solid angle (delta omega) in microfacet normal (half-vector) measure;
  38. // so the relationship is proportional to cosine theta = NdotV.
  39. // The constant factor of four is handled elsewhere as part of the scale/offset filter parameters.
  40. microsurfaceAverageSlope *= sqrt(abs(NdotV));
  41. return getLodFromAlphaG(cubeMapDimensionPixels, microsurfaceAverageSlope);
  42. }
  43. #endif