12345678910111213141516171819202122232425262728293031323334353637383940 |
- // Do not edit.
- import { ShaderStore } from "../../Engines/shaderStore.js";
- import "./samplerFragmentDeclaration.js";
- const name = "bumpFragmentFunctions";
- const shader = `#if defined(BUMP)
- #include<samplerFragmentDeclaration>(_DEFINENAME_,BUMP,_VARYINGNAME_,Bump,_SAMPLERNAME_,bump)
- #endif
- #if defined(DETAIL)
- #include<samplerFragmentDeclaration>(_DEFINENAME_,DETAIL,_VARYINGNAME_,Detail,_SAMPLERNAME_,detail)
- #endif
- #if defined(BUMP) && defined(PARALLAX)
- 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++)
- {currSampledHeight=texture2D(bumpSampler,texCoord+vCurrOffset).w;if (!keepWorking)
- {}
- else if (currSampledHeight>currRayHeight)
- {float delta1=currSampledHeight-currRayHeight;float delta2=(currRayHeight+stepSize)-lastSampledHeight;float ratio=delta1/(delta1+delta2);vCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;keepWorking=false;}
- else
- {currRayHeight-=stepSize;vLastOffset=vCurrOffset;
- #ifdef PARALLAX_RHS
- vCurrOffset-=stepSize*vMaxOffset;
- #else
- vCurrOffset+=stepSize*vMaxOffset;
- #endif
- lastSampledHeight=currSampledHeight;}}
- return vCurrOffset;}
- vec2 parallaxOffset(vec3 viewDir,float heightScale)
- {float height=texture2D(bumpSampler,vBumpUV).w;vec2 texCoordOffset=heightScale*viewDir.xy*height;
- #ifdef PARALLAX_RHS
- return texCoordOffset;
- #else
- return -texCoordOffset;
- #endif
- }
- #endif
- `;
- // Sideeffect
- ShaderStore.IncludesShadersStore[name] = shader;
- /** @internal */
- export const bumpFragmentFunctions = { name, shader };
- //# sourceMappingURL=bumpFragmentFunctions.js.map
|