|
@@ -2,102 +2,59 @@ 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
|
|
|
+ uniform float refractionRatio;
|
|
|
|
|
|
- // force the bias high to get the last LOD level as it is the most blurred.
|
|
|
- vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );
|
|
|
+ #endif
|
|
|
|
|
|
- #endif
|
|
|
+ vec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {
|
|
|
|
|
|
- envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
|
|
|
+ #if defined( ENVMAP_TYPE_CUBE_UV )
|
|
|
|
|
|
- #elif defined( ENVMAP_TYPE_CUBE_UV )
|
|
|
+ vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );
|
|
|
|
|
|
vec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );
|
|
|
|
|
|
+ return PI * envMapColor.rgb * envMapIntensity;
|
|
|
+
|
|
|
#else
|
|
|
|
|
|
- vec4 envMapColor = vec4( 0.0 );
|
|
|
+ return vec3( 0.0 );
|
|
|
|
|
|
#endif
|
|
|
|
|
|
- return PI * envMapColor.rgb * envMapIntensity;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // Trowbridge-Reitz distribution to Mip level, following the logic of http://casual-effects.blogspot.ca/2011/08/plausible-environment-lighting-in-two.html
|
|
|
- float getSpecularMIPLevel( const in float roughness, const in int maxMIPLevel ) {
|
|
|
-
|
|
|
- float maxMIPLevelScalar = float( maxMIPLevel );
|
|
|
-
|
|
|
- float sigma = PI * roughness * roughness / ( 1.0 + roughness );
|
|
|
- float desiredMIPLevel = maxMIPLevelScalar + log2( sigma );
|
|
|
-
|
|
|
- // 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 roughness, const in int maxMIPLevel ) {
|
|
|
-
|
|
|
- #ifdef ENVMAP_MODE_REFLECTION
|
|
|
-
|
|
|
- vec3 reflectVec = reflect( -viewDir, normal );
|
|
|
-
|
|
|
- // Mixing the reflection with the normal is more accurate and keeps rough objects from gathering light from behind their tangent plane.
|
|
|
- reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );
|
|
|
-
|
|
|
- #else
|
|
|
-
|
|
|
- vec3 reflectVec = refract( -viewDir, normal, refractionRatio );
|
|
|
+ vec3 getLightProbeIndirectRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in int maxMIPLevel ) {
|
|
|
|
|
|
- #endif
|
|
|
-
|
|
|
- reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
|
|
|
-
|
|
|
- float specularMIPLevel = getSpecularMIPLevel( roughness, maxMIPLevel );
|
|
|
+ #if defined( ENVMAP_TYPE_CUBE_UV )
|
|
|
|
|
|
- #ifdef ENVMAP_TYPE_CUBE
|
|
|
+ vec3 reflectVec;
|
|
|
|
|
|
- vec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );
|
|
|
+ #ifdef ENVMAP_MODE_REFLECTION
|
|
|
|
|
|
- #ifdef TEXTURE_LOD_EXT
|
|
|
+ reflectVec = reflect( - viewDir, normal );
|
|
|
|
|
|
- vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );
|
|
|
+ // Mixing the reflection with the normal is more accurate and keeps rough objects from gathering light from behind their tangent plane.
|
|
|
+ reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );
|
|
|
|
|
|
#else
|
|
|
|
|
|
- vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );
|
|
|
+ reflectVec = refract( - viewDir, normal, refractionRatio );
|
|
|
|
|
|
#endif
|
|
|
|
|
|
- envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
|
|
|
-
|
|
|
- #elif defined( ENVMAP_TYPE_CUBE_UV )
|
|
|
+ reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
|
|
|
|
|
|
vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );
|
|
|
|
|
|
- #endif
|
|
|
+ return envMapColor.rgb * envMapIntensity;
|
|
|
|
|
|
- return envMapColor.rgb * envMapIntensity;
|
|
|
+ #else
|
|
|
+
|
|
|
+ return vec3( 0.0 );
|
|
|
+
|
|
|
+ #endif
|
|
|
|
|
|
}
|
|
|
|