pbrIBLFunctions.fx 2.6 KB

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