123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- export default /* glsl */`
- #if defined( USE_ENVMAP )
- #ifdef ENVMAP_MODE_REFRACTION
- uniform float refractionRatio;
- #endif
- vec3 getLightProbeIndirectIrradiance( /*const in SpecularLightProbe specularLightProbe,*/ const in GeometricContext geometry, const in int maxMIPLevel ) {
- vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );
- #ifdef ENVMAP_TYPE_CUBE
- vec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );
- // TODO: replace with properly filtered cubemaps and access the irradiance LOD level, be it the last LOD level
- // of a specular cubemap, or just the default level of a specially created irradiance cubemap.
- #ifdef TEXTURE_LOD_EXT
- vec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );
- #else
- // force the bias high to get the last LOD level as it is the most blurred.
- vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );
- #endif
- envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
- #elif defined( ENVMAP_TYPE_CUBE_UV )
- vec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );
- vec4 envMapColor = textureCubeUV( envMap, queryVec, 1.0 );
- #else
- vec4 envMapColor = vec4( 0.0 );
- #endif
- return PI * envMapColor.rgb * envMapIntensity;
- }
- // taken from here: http://casual-effects.blogspot.ca/2011/08/plausible-environment-lighting-in-two.html
- float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {
- //float envMapWidth = pow( 2.0, maxMIPLevelScalar );
- //float desiredMIPLevel = log2( envMapWidth * sqrt( 3.0 ) ) - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );
- float maxMIPLevelScalar = float( maxMIPLevel );
- float desiredMIPLevel = maxMIPLevelScalar + 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );
- // clamp to allowable LOD ranges.
- return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );
- }
- vec3 getLightProbeIndirectRadiance( /*const in SpecularLightProbe specularLightProbe,*/ const in vec3 viewDir, const in vec3 normal, const in float blinnShininessExponent, const in int maxMIPLevel ) {
- #ifdef ENVMAP_MODE_REFLECTION
- vec3 reflectVec = reflect( -viewDir, normal );
- #else
- vec3 reflectVec = refract( -viewDir, normal, refractionRatio );
- #endif
- reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
- float specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );
- #ifdef ENVMAP_TYPE_CUBE
- vec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );
- #ifdef TEXTURE_LOD_EXT
- vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );
- #else
- vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );
- #endif
- envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
- #elif defined( ENVMAP_TYPE_CUBE_UV )
- vec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );
- vec4 envMapColor = textureCubeUV( envMap, queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent ));
- #elif defined( ENVMAP_TYPE_EQUIREC )
- vec2 sampleUV;
- sampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
- sampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;
- #ifdef TEXTURE_LOD_EXT
- vec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );
- #else
- vec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );
- #endif
- envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
- #elif defined( ENVMAP_TYPE_SPHERE )
- vec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );
- #ifdef TEXTURE_LOD_EXT
- vec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );
- #else
- vec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );
- #endif
- envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
- #endif
- return envMapColor.rgb * envMapIntensity;
- }
- #endif
- `;
|