lightsFragmentFunctions.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Do not edit.
  2. import { ShaderStore } from "../../Engines/shaderStore.js";
  3. const name = "lightsFragmentFunctions";
  4. const shader = `struct lightingInfo
  5. {vec3 diffuse;
  6. #ifdef SPECULARTERM
  7. vec3 specular;
  8. #endif
  9. #ifdef NDOTL
  10. float ndl;
  11. #endif
  12. };lightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {lightingInfo result;vec3 lightVectorW;float attenuation=1.0;if (lightData.w==0.)
  13. {vec3 direction=lightData.xyz-vPositionW;attenuation=max(0.,1.0-length(direction)/range);lightVectorW=normalize(direction);}
  14. else
  15. {lightVectorW=normalize(-lightData.xyz);}
  16. float ndl=max(0.,dot(vNormal,lightVectorW));
  17. #ifdef NDOTL
  18. result.ndl=ndl;
  19. #endif
  20. result.diffuse=ndl*diffuseColor*attenuation;
  21. #ifdef SPECULARTERM
  22. vec3 angleW=normalize(viewDirectionW+lightVectorW);float specComp=max(0.,dot(vNormal,angleW));specComp=pow(specComp,max(1.,glossiness));result.specular=specComp*specularColor*attenuation;
  23. #endif
  24. return result;}
  25. lightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {lightingInfo result;vec3 direction=lightData.xyz-vPositionW;vec3 lightVectorW=normalize(direction);float attenuation=max(0.,1.0-length(direction)/range);float cosAngle=max(0.,dot(lightDirection.xyz,-lightVectorW));if (cosAngle>=lightDirection.w)
  26. {cosAngle=max(0.,pow(cosAngle,lightData.w));attenuation*=cosAngle;float ndl=max(0.,dot(vNormal,lightVectorW));
  27. #ifdef NDOTL
  28. result.ndl=ndl;
  29. #endif
  30. result.diffuse=ndl*diffuseColor*attenuation;
  31. #ifdef SPECULARTERM
  32. vec3 angleW=normalize(viewDirectionW+lightVectorW);float specComp=max(0.,dot(vNormal,angleW));specComp=pow(specComp,max(1.,glossiness));result.specular=specComp*specularColor*attenuation;
  33. #endif
  34. return result;}
  35. result.diffuse=vec3(0.);
  36. #ifdef SPECULARTERM
  37. result.specular=vec3(0.);
  38. #endif
  39. #ifdef NDOTL
  40. result.ndl=0.;
  41. #endif
  42. return result;}
  43. lightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float glossiness) {lightingInfo result;float ndl=dot(vNormal,lightData.xyz)*0.5+0.5;
  44. #ifdef NDOTL
  45. result.ndl=ndl;
  46. #endif
  47. result.diffuse=mix(groundColor,diffuseColor,ndl);
  48. #ifdef SPECULARTERM
  49. vec3 angleW=normalize(viewDirectionW+lightData.xyz);float specComp=max(0.,dot(vNormal,angleW));specComp=pow(specComp,max(1.,glossiness));result.specular=specComp*specularColor;
  50. #endif
  51. return result;}
  52. #define inline
  53. vec3 computeProjectionTextureDiffuseLighting(sampler2D projectionLightSampler,mat4 textureProjectionMatrix){vec4 strq=textureProjectionMatrix*vec4(vPositionW,1.0);strq/=strq.w;vec3 textureColor=texture2D(projectionLightSampler,strq.xy).rgb;return textureColor;}`;
  54. // Sideeffect
  55. ShaderStore.IncludesShadersStore[name] = shader;
  56. /** @internal */
  57. export const lightsFragmentFunctions = { name, shader };
  58. //# sourceMappingURL=lightsFragmentFunctions.js.map