pbrDirectLightingFalloffFunctions.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Do not edit.
  2. import { ShaderStore } from "../../Engines/shaderStore.js";
  3. const name = "pbrDirectLightingFalloffFunctions";
  4. const shader = `float computeDistanceLightFalloff_Standard(vec3 lightOffset,float range)
  5. {return max(0.,1.0-length(lightOffset)/range);}
  6. float computeDistanceLightFalloff_Physical(float lightDistanceSquared)
  7. {return 1.0/maxEps(lightDistanceSquared);}
  8. float computeDistanceLightFalloff_GLTF(float lightDistanceSquared,float inverseSquaredRange)
  9. {float lightDistanceFalloff=1.0/maxEps(lightDistanceSquared);float factor=lightDistanceSquared*inverseSquaredRange;float attenuation=saturate(1.0-factor*factor);attenuation*=attenuation;lightDistanceFalloff*=attenuation;return lightDistanceFalloff;}
  10. float computeDistanceLightFalloff(vec3 lightOffset,float lightDistanceSquared,float range,float inverseSquaredRange)
  11. {
  12. #ifdef USEPHYSICALLIGHTFALLOFF
  13. return computeDistanceLightFalloff_Physical(lightDistanceSquared);
  14. #elif defined(USEGLTFLIGHTFALLOFF)
  15. return computeDistanceLightFalloff_GLTF(lightDistanceSquared,inverseSquaredRange);
  16. #else
  17. return computeDistanceLightFalloff_Standard(lightOffset,range);
  18. #endif
  19. }
  20. float computeDirectionalLightFalloff_Standard(vec3 lightDirection,vec3 directionToLightCenterW,float cosHalfAngle,float exponent)
  21. {float falloff=0.0;float cosAngle=maxEps(dot(-lightDirection,directionToLightCenterW));if (cosAngle>=cosHalfAngle)
  22. {falloff=max(0.,pow(cosAngle,exponent));}
  23. return falloff;}
  24. float computeDirectionalLightFalloff_Physical(vec3 lightDirection,vec3 directionToLightCenterW,float cosHalfAngle)
  25. {const float kMinusLog2ConeAngleIntensityRatio=6.64385618977;
  26. float concentrationKappa=kMinusLog2ConeAngleIntensityRatio/(1.0-cosHalfAngle);vec4 lightDirectionSpreadSG=vec4(-lightDirection*concentrationKappa,-concentrationKappa);float falloff=exp2(dot(vec4(directionToLightCenterW,1.0),lightDirectionSpreadSG));return falloff;}
  27. float computeDirectionalLightFalloff_GLTF(vec3 lightDirection,vec3 directionToLightCenterW,float lightAngleScale,float lightAngleOffset)
  28. {float cd=dot(-lightDirection,directionToLightCenterW);float falloff=saturate(cd*lightAngleScale+lightAngleOffset);falloff*=falloff;return falloff;}
  29. float computeDirectionalLightFalloff(vec3 lightDirection,vec3 directionToLightCenterW,float cosHalfAngle,float exponent,float lightAngleScale,float lightAngleOffset)
  30. {
  31. #ifdef USEPHYSICALLIGHTFALLOFF
  32. return computeDirectionalLightFalloff_Physical(lightDirection,directionToLightCenterW,cosHalfAngle);
  33. #elif defined(USEGLTFLIGHTFALLOFF)
  34. return computeDirectionalLightFalloff_GLTF(lightDirection,directionToLightCenterW,lightAngleScale,lightAngleOffset);
  35. #else
  36. return computeDirectionalLightFalloff_Standard(lightDirection,directionToLightCenterW,cosHalfAngle,exponent);
  37. #endif
  38. }`;
  39. // Sideeffect
  40. ShaderStore.IncludesShadersStore[name] = shader;
  41. /** @internal */
  42. export const pbrDirectLightingFalloffFunctions = { name, shader };
  43. //# sourceMappingURL=pbrDirectLightingFalloffFunctions.js.map