Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default /* glsl */`
export default /* glsl */ `
#if defined( USE_ENVMAP )

#ifdef ENVMAP_MODE_REFRACTION
Expand Down Expand Up @@ -44,26 +44,28 @@ export default /* glsl */`

}

// 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 );
// 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 desiredMIPLevel = maxMIPLevelScalar + 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );

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 blinnShininessExponent, const in int maxMIPLevel ) {
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 );
Expand All @@ -72,7 +74,7 @@ export default /* glsl */`

reflectVec = inverseTransformDirection( reflectVec, viewMatrix );

float specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );
float specularMIPLevel = getSpecularMIPLevel( roughness, maxMIPLevel );

#ifdef ENVMAP_TYPE_CUBE

Expand All @@ -93,7 +95,7 @@ export default /* glsl */`
#elif defined( ENVMAP_TYPE_CUBE_UV )

vec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );
vec4 envMapColor = textureCubeUV( envMap, queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent ));
vec4 envMapColor = textureCubeUV( envMap, queryReflectVec, roughness );

#elif defined( ENVMAP_TYPE_EQUIREC )

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default /* glsl */`
export default /* glsl */ `
#if defined( RE_IndirectDiffuse )

#ifdef USE_LIGHTMAP
Expand All @@ -25,11 +25,11 @@ export default /* glsl */`

#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )

radiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, geometry.normal, Material_BlinnShininessExponent( material ), maxMipLevel );
radiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, geometry.normal, material.specularRoughness, maxMipLevel );

#ifdef CLEARCOAT

clearcoatRadiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, geometry.clearcoatNormal, Material_Clearcoat_BlinnShininessExponent( material ), maxMipLevel );
clearcoatRadiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, geometry.clearcoatNormal, material.clearCoatRoughness, maxMipLevel );

#endif

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default /* glsl */`
export default /* glsl */ `
struct PhysicalMaterial {

vec3 diffuseColor;
Expand Down Expand Up @@ -161,9 +161,6 @@ void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradia
#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical
#define RE_IndirectSpecular RE_IndirectSpecular_Physical

#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )
#define Material_Clearcoat_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.clearcoatRoughness )

// ref: https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {

Expand Down