PBR.glsl 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. #include "BRDF.glsl"
  2. #ifdef COMPILEPS
  3. //Return the PBR BRDF value
  4. // lightDir = the vector to the light
  5. // lightVev = normalised lightDir
  6. // toCamera = vector to the camera
  7. // normal = surface normal of the pixel
  8. // roughness = roughness of the pixel
  9. // diffColor = the rgb color of the pixel
  10. // specColor = the rgb specular color of the pixel
  11. vec3 GetBRDF(vec3 lightDir, vec3 lightVec, vec3 toCamera, vec3 normal, float roughness, vec3 diffColor, vec3 specColor)
  12. {
  13. vec3 Hn = normalize(toCamera + lightDir);
  14. float vdh = clamp((dot(toCamera, Hn)), M_EPSILON, 1.0);
  15. float ndh = clamp((dot(normal, Hn)), M_EPSILON, 1.0);
  16. float ndl = clamp((dot(normal, lightVec)), M_EPSILON, 1.0);
  17. float ndv = clamp((dot(normal, toCamera)), M_EPSILON, 1.0);
  18. vec3 diffuseFactor = Diffuse(diffColor, roughness, ndv, ndl, vdh);
  19. vec3 specularFactor = vec3(0.0, 0.0, 0.0);
  20. #ifdef SPECULAR
  21. vec3 fresnelTerm = Fresnel(specColor, vdh) ;
  22. float distTerm = Distribution(ndh, roughness);
  23. float visTerm = Visibility(ndl, ndv, roughness);
  24. specularFactor = fresnelTerm * distTerm * visTerm / M_PI;
  25. #endif
  26. return diffuseFactor + specularFactor;
  27. }
  28. #endif