Skip to content

Commit

Permalink
refactor: add COMPAT comment on pre-r156 compats addressed in #1304
Browse files Browse the repository at this point in the history
also removed an impossible compat code path
  • Loading branch information
0b5vr committed Jan 15, 2024
1 parent 82b3f09 commit 3deb0b8
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/three-vrm-materials-mtoon/src/shaders/mtoon.frag
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,12 @@ vec3 getDiffuse(
return col;
}

// COMPAT: pre-r156 uses a struct GeometricContext
#if THREE_VRM_THREE_REVISION >= 157
void RE_Direct_MToon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in MToonMaterial material, const in float shadow, inout ReflectedLight reflectedLight ) {
float dotNL = clamp( dot( geometryNormal, directLight.direction ), -1.0, 1.0 );
vec3 irradiance = directLight.color;

#if THREE_VRM_THREE_REVISION < 132
#ifndef PHYSICALLY_CORRECT_LIGHTS
irradiance *= PI;
#endif
#endif

// directSpecular will be used for rim lighting, not an actual specular
reflectedLight.directSpecular += irradiance;

Expand Down Expand Up @@ -611,11 +606,12 @@ void main() {
// Since we want to take shadows into account of shading instead of irradiance,
// we had to modify the codes that multiplies the results of shadowmap into color of direct lights.

// COMPAT: pre-r156 uses a struct GeometricContext
#if THREE_VRM_THREE_REVISION >= 157
vec3 geometryPosition = - vViewPosition;
vec3 geometryNormal = normal;
vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );

vec3 geometryClearcoatNormal;

#ifdef USE_CLEARCOAT
Expand Down Expand Up @@ -654,6 +650,7 @@ void main() {

pointLight = pointLights[ i ];

// COMPAT: pre-r156 uses a struct GeometricContext
#if THREE_VRM_THREE_REVISION >= 157
getPointLightInfo( pointLight, geometryPosition, directLight );
#elif THREE_VRM_THREE_REVISION >= 132
Expand All @@ -668,6 +665,7 @@ void main() {
shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
#endif

// COMPAT: pre-r156 uses a struct GeometricContext
#if THREE_VRM_THREE_REVISION >= 157
RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, shadow, reflectedLight );
#else
Expand All @@ -691,6 +689,7 @@ void main() {

spotLight = spotLights[ i ];

// COMPAT: pre-r156 uses a struct GeometricContext
#if THREE_VRM_THREE_REVISION >= 157
getSpotLightInfo( spotLight, geometryPosition, directLight );
#elif THREE_VRM_THREE_REVISION >= 132
Expand All @@ -705,6 +704,7 @@ void main() {
shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
#endif

// COMPAT: pre-r156 uses a struct GeometricContext
#if THREE_VRM_THREE_REVISION >= 157
RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, shadow, reflectedLight );
#else
Expand All @@ -728,6 +728,7 @@ void main() {

directionalLight = directionalLights[ i ];

// COMPAT: pre-r156 uses a struct GeometricContext
#if THREE_VRM_THREE_REVISION >= 157
getDirectionalLightInfo( directionalLight, directLight );
#elif THREE_VRM_THREE_REVISION >= 132
Expand All @@ -742,6 +743,7 @@ void main() {
shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
#endif

// COMPAT: pre-r156 uses a struct GeometricContext
#if THREE_VRM_THREE_REVISION >= 157
RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, shadow, reflectedLight );
#else
Expand Down Expand Up @@ -774,6 +776,8 @@ void main() {

vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );

// COMPAT: pre-r156 uses a struct GeometricContext
// COMPAT: pre-r156 doesn't have a define USE_LIGHT_PROBES
#if THREE_VRM_THREE_REVISION >= 157
#if defined( USE_LIGHT_PROBES )
irradiance += getLightProbeIrradiance( lightProbe, geometryNormal );
Expand All @@ -789,6 +793,7 @@ void main() {
#pragma unroll_loop_start
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {

// COMPAT: pre-r156 uses a struct GeometricContext
#if THREE_VRM_THREE_REVISION >= 157
irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );
#elif THREE_VRM_THREE_REVISION >= 133
Expand Down

0 comments on commit 3deb0b8

Please sign in to comment.