bumpFragmentFunctions.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Do not edit.
  2. import { ShaderStore } from "../../Engines/shaderStore.js";
  3. import "./samplerFragmentDeclaration.js";
  4. const name = "bumpFragmentFunctions";
  5. const shader = `#if defined(BUMP)
  6. #include<samplerFragmentDeclaration>(_DEFINENAME_,BUMP,_VARYINGNAME_,Bump,_SAMPLERNAME_,bump)
  7. #endif
  8. #if defined(DETAIL)
  9. #include<samplerFragmentDeclaration>(_DEFINENAME_,DETAIL,_VARYINGNAME_,Detail,_SAMPLERNAME_,detail)
  10. #endif
  11. #if defined(BUMP) && defined(PARALLAX)
  12. const float minSamples=4.;const float maxSamples=15.;const int iMaxSamples=15;vec2 parallaxOcclusion(vec3 vViewDirCoT,vec3 vNormalCoT,vec2 texCoord,float parallaxScale) {float parallaxLimit=length(vViewDirCoT.xy)/vViewDirCoT.z;parallaxLimit*=parallaxScale;vec2 vOffsetDir=normalize(vViewDirCoT.xy);vec2 vMaxOffset=vOffsetDir*parallaxLimit;float numSamples=maxSamples+(dot(vViewDirCoT,vNormalCoT)*(minSamples-maxSamples));float stepSize=1.0/numSamples;float currRayHeight=1.0;vec2 vCurrOffset=vec2(0,0);vec2 vLastOffset=vec2(0,0);float lastSampledHeight=1.0;float currSampledHeight=1.0;bool keepWorking=true;for (int i=0; i<iMaxSamples; i++)
  13. {currSampledHeight=texture2D(bumpSampler,texCoord+vCurrOffset).w;if (!keepWorking)
  14. {}
  15. else if (currSampledHeight>currRayHeight)
  16. {float delta1=currSampledHeight-currRayHeight;float delta2=(currRayHeight+stepSize)-lastSampledHeight;float ratio=delta1/(delta1+delta2);vCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;keepWorking=false;}
  17. else
  18. {currRayHeight-=stepSize;vLastOffset=vCurrOffset;
  19. #ifdef PARALLAX_RHS
  20. vCurrOffset-=stepSize*vMaxOffset;
  21. #else
  22. vCurrOffset+=stepSize*vMaxOffset;
  23. #endif
  24. lastSampledHeight=currSampledHeight;}}
  25. return vCurrOffset;}
  26. vec2 parallaxOffset(vec3 viewDir,float heightScale)
  27. {float height=texture2D(bumpSampler,vBumpUV).w;vec2 texCoordOffset=heightScale*viewDir.xy*height;
  28. #ifdef PARALLAX_RHS
  29. return texCoordOffset;
  30. #else
  31. return -texCoordOffset;
  32. #endif
  33. }
  34. #endif
  35. `;
  36. // Sideeffect
  37. ShaderStore.IncludesShadersStore[name] = shader;
  38. /** @internal */
  39. export const bumpFragmentFunctions = { name, shader };
  40. //# sourceMappingURL=bumpFragmentFunctions.js.map