PBR.hlsl 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. #include "BRDF.hlsl"
  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. float3 GetBRDF(float3 lightDir, float3 lightVec, float3 toCamera, float3 normal, float roughness, float3 diffColor, float3 specColor)
  12. {
  13. const float3 Hn = normalize(toCamera + lightDir);
  14. const float vdh = clamp((dot(toCamera, Hn)), M_EPSILON, 1.0);
  15. const float ndh = clamp((dot(normal, Hn)), M_EPSILON, 1.0);
  16. const float ndl = clamp((dot(normal, lightVec)), M_EPSILON, 1.0);
  17. const float ndv = clamp((dot(normal, toCamera)), M_EPSILON, 1.0);
  18. const float3 diffuseFactor = Diffuse(diffColor, roughness, ndv, ndl, vdh);
  19. float3 specularFactor = 0;
  20. #ifdef SPECULAR
  21. const float3 fresnelTerm = Fresnel(specColor, vdh) ;
  22. const float distTerm = Distribution(ndh, roughness);
  23. const float visTerm = Visibility(ndl, ndv, roughness);
  24. specularFactor = distTerm * visTerm * fresnelTerm / M_PI;
  25. #endif
  26. return diffuseFactor + specularFactor;
  27. }
  28. #endif