three
Version:
JavaScript 3D library
80 lines (47 loc) • 2.17 kB
JavaScript
export default /* glsl */`
PhysicalMaterial material;
material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );
float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
material.specularRoughness = max( roughnessFactor, 0.0525 );// 0.0525 corresponds to the base mip of a 256 cubemap.
material.specularRoughness += geometryRoughness;
material.specularRoughness = min( material.specularRoughness, 1.0 );
vec3 specularIntensityFactor = vec3( specularIntensity );
vec3 specularTintFactor = specularTint;
specularIntensityFactor *= texture2D( specularIntensityMap, vUv ).a;
specularTintFactor *= specularTintMapTexelToLinear( texture2D( specularTintMap, vUv ) ).rgb;
material.specularColorF90 = mix( specularIntensityFactor, vec3( 1.0 ), metalnessFactor );
vec3 specularIntensityFactor = vec3( 1.0 );
vec3 specularTintFactor = vec3( 1.0 );
material.specularColorF90 = vec3( 1.0 );
material.specularColor = mix( min( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ) * specularTintFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );
material.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );
material.specularColorF90 = vec3( 1.0 );
material.clearcoat = clearcoat;
material.clearcoatRoughness = clearcoatRoughness;
material.clearcoat *= texture2D( clearcoatMap, vUv ).x;
material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vUv ).y;
material.clearcoat = saturate( material.clearcoat ); // Burley clearcoat model
material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );
material.clearcoatRoughness += geometryRoughness;
material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );
material.sheenColor = sheen;
`;