oren-nayar-diffuse.glsl 812 B

123456789101112131415161718192021
  1. // (c) 2014 Mikola Lysenko. MIT License
  2. // https://github.com/glslify/glsl-diffuse-oren-nayar
  3. #define PI 3.14159265
  4. float orenNayarDiffuse(const in vec3 lightDirection, const in vec3 viewDirection, const in vec3 surfaceNormal, const in float roughness, const in float albedo) {
  5. float LdotV = dot(lightDirection, viewDirection);
  6. float NdotL = dot(lightDirection, surfaceNormal);
  7. float NdotV = dot(surfaceNormal, viewDirection);
  8. float s = LdotV - NdotL * NdotV;
  9. float t = mix(1.0, max(NdotL, NdotV), step(0.0, s));
  10. float sigma2 = roughness * roughness;
  11. float A = 1.0 + sigma2 * (albedo / (sigma2 + 0.13) + 0.5 / (sigma2 + 0.33));
  12. float B = 0.45 * sigma2 / (sigma2 + 0.09);
  13. return albedo * max(0.0, NdotL) * (A + B * s / t) / PI;
  14. }
  15. #pragma glslify: export(orenNayarDiffuse)