Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oppentech/three",
"version": "0.115.5",
"version": "0.115.6",
"description": "JavaScript 3D library",
"main": "build/three.js",
"module": "build/three.module.js",
Expand Down
2 changes: 2 additions & 0 deletions src/materials/MeshPhysicalMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function MeshPhysicalMaterial( parameters ) {
this.sheen = null; // null will disable sheen bsdf

this.transparency = 0.0;
this.refraction = 0.0;

this.setValues( parameters );

Expand All @@ -72,6 +73,7 @@ MeshPhysicalMaterial.prototype.copy = function ( source ) {
this.clearcoatRoughness = source.clearcoatRoughness;
this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
this.clearcoatNormalMap = source.clearcoatNormalMap;
this.refraction = source.refraction;
this.clearcoatNormalScale.copy( source.clearcoatNormalScale );

this.reflectivity = source.reflectivity;
Expand Down
1 change: 1 addition & 0 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,7 @@ function WebGLRenderer( parameters ) {

uniforms.reflectivity.value = material.reflectivity;
uniforms.refractionRatio.value = material.refractionRatio;
uniforms.refraction.value = material.refraction;

uniforms.maxMipLevel.value = properties.get( envMap ).__maxMipLevel || 0;

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

#ifdef ENVMAP_MODE_REFRACTION
uniform float refractionRatio;
#endif
uniform float refractionRatio;

vec3 getLightProbeIndirectIrradiance( /*const in SpecularLightProbe specularLightProbe,*/ const in vec3 geoNormal, const in int maxMIPLevel ) {

Expand Down Expand Up @@ -56,50 +54,37 @@ export default /* glsl */`

}

vec3 getLightProbeIndirectRadiance( /*const in SpecularLightProbe specularLightProbe,*/ const in vec3 viewDir, const in vec3 normal, const in float roughness, const in int maxMIPLevel ) {
vec3 getLightProbeIndirectRadiance( const in vec3 outVec, 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 );

#endif

reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
vec3 worldOutVec = inverseTransformDirection( outVec, viewMatrix );

float specularMIPLevel = getSpecularMIPLevel( roughness, maxMIPLevel );

#ifdef ENVMAP_TYPE_CUBE

vec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );
vec3 queryWorldOutVec = vec3( flipEnvMap * worldOutVec.x, worldOutVec.yz );

#ifdef TEXTURE_LOD_EXT

vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );
vec4 envMapColor = textureCubeLodEXT( envMap, queryWorldOutVec, specularMIPLevel );

#else

vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );
vec4 envMapColor = textureCube( envMap, queryWorldOutVec, specularMIPLevel );

#endif

envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;

#elif defined( ENVMAP_TYPE_CUBE_UV )

vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );
vec4 envMapColor = textureCubeUV( envMap, worldOutVec, roughness );

#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;
sampleUV.y = asin( clamp( worldOutVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
sampleUV.x = atan( worldOutVec.z, worldOutVec.x ) * RECIPROCAL_PI2 + 0.5;

#ifdef TEXTURE_LOD_EXT

Expand All @@ -115,15 +100,15 @@ export default /* glsl */`

#elif defined( ENVMAP_TYPE_SPHERE )

vec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );
vec3 worldOutView = normalize( ( viewMatrix * vec4( worldOutVec, 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 );
vec4 envMapColor = texture2DLodEXT( envMap, worldOutView.xy * 0.5 + 0.5, specularMIPLevel );

#else

vec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );
vec4 envMapColor = texture2D( envMap, worldOutView.xy * 0.5 + 0.5, specularMIPLevel );

#endif

Expand All @@ -135,5 +120,29 @@ export default /* glsl */`

}

vec3 getLightProbeIndirectRadianceReflection( /*const in SpecularLightProbe specularLightProbe,*/ const in vec3 viewDir, const in vec3 normal, const in float roughness, const in int maxMIPLevel ) {

vec3 reflectVec = reflect( -viewDir, normal );
reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );

return getLightProbeIndirectRadiance(reflectVec, roughness, maxMIPLevel);

}

vec3 refract2(vec3 viewVec, vec3 Normal, float IOR) {
float vn = dot(viewVec, Normal);
float k = 1.0 - IOR * IOR * (1.0 - vn * vn);
vec3 refrVec = IOR * viewVec - (IOR * vn + sqrt(k)) * Normal;
return refrVec;
}

vec3 getLightProbeIndirectRadianceRefraction( /*const in SpecularLightProbe specularLightProbe,*/ const in vec3 viewDir, const in vec3 normal, const in float roughness, const in int maxMIPLevel ) {

vec3 refractVec = refract2( -viewDir, normal, refractionRatio );

return getLightProbeIndirectRadiance(refractVec, roughness, maxMIPLevel);

}

#endif
`;
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ IncidentLight directLight;
#if defined( RE_IndirectSpecular )

vec3 radiance = vec3( 0.0 );
vec3 radianceRefraction = vec3( 0.0 );
vec3 clearcoatRadiance = vec3( 0.0 );

#endif
Expand Down
6 changes: 6 additions & 0 deletions src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ export default /* glsl */`
geometry, material, reflectedLight
);

#endif

#ifdef ENVMAP_MODE_REFLECTION

reflectedLight.indirectDiffuse = mix(reflectedLight.indirectDiffuse, radianceRefraction * diffuseColor.rgb, refraction);

#endif
`;
21 changes: 19 additions & 2 deletions src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,28 @@ export default /* glsl */`

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

radiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, splitGeoNormal, material.specularRoughness, maxMipLevel );
#ifdef ENVMAP_MODE_REFLECTION

radiance += getLightProbeIndirectRadianceReflection( /*specularLightProbe,*/ geometry.viewDir, splitGeoNormal, material.specularRoughness, maxMipLevel );
radianceRefraction += getLightProbeIndirectRadianceRefraction( /*specularLightProbe,*/ geometry.viewDir, splitGeoNormal, material.specularRoughness, maxMipLevel );

#else

radiance += getLightProbeIndirectRadianceRefraction( /*specularLightProbe,*/ geometry.viewDir, splitGeoNormal, material.specularRoughness, maxMipLevel );

#endif

#ifdef CLEARCOAT

clearcoatRadiance += getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry.viewDir, splitGeoClearcoatNormal, material.clearcoatRoughness, maxMipLevel );
#ifdef ENVMAP_MODE_REFLECTION

clearcoatRadiance += getLightProbeIndirectRadianceReflection( /*specularLightProbe,*/ geometry.viewDir, splitGeoClearcoatNormal, material.clearcoatRoughness, maxMipLevel );

#else

clearcoatRadiance += getLightProbeIndirectRadianceRefraction( /*specularLightProbe,*/ geometry.viewDir, splitGeoClearcoatNormal, material.clearcoatRoughness, maxMipLevel );

#endif

#endif

Expand Down
1 change: 1 addition & 0 deletions src/renderers/shaders/ShaderLib/meshphysical_frag.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ uniform vec3 emissive;
uniform float roughness;
uniform float metalness;
uniform float opacity;
uniform float refraction;

#ifdef TRANSPARENCY
uniform float transparency;
Expand Down
1 change: 1 addition & 0 deletions src/renderers/shaders/UniformsLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var UniformsLib = {
flipEnvMap: { value: - 1 },
reflectivity: { value: 1.0 },
refractionRatio: { value: 0.98 },
refraction: { value: 0.0 },
maxMipLevel: { value: 0 }

},
Expand Down