Three PBR 参数 (改版)

666 阅读1分钟

roughness

  • 高光流 通过光泽贴图
    • glossinessFactor是用户输入参数值
    • texelGlossiness是光泽贴图
    • roughness是 1-texelGlossiness
//
float glossinessFactor = glossiness;
#ifdef USE_GLOSSINESSMAP
    #if ! defined ( VERSION_1_0_0 )
        glossinessFactor = 1.0;
    #endif
    vec4 texelGlossiness = texture2D( glossinessMap, vUv );
    glossinessFactor *= texelGlossiness.x;
#else
    #ifdef USE_SPECULARMAP
        glossinessFactor *= texelSpecular.a;
    #endif
#endif
vec3 geometryNormal = normal;
vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );
float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
glossinessFactor *= smoothMultiplier;
material.specularRoughness = max( 1.0 - glossinessFactor, 0.0525 );// 0.0525 corresponds to the base mip of a 256 cubemap.
material.specularRoughness += geometryRoughness;
material.specularRoughness = min( material.specularRoughness, 1.0 );
material.specularRoughness = saturate(material.specularRoughness);
  • 金属流 直接从粗糙度贴图获取
    • roughnessFactor是用户输入参数值
    • roughness就是texelRoughness粗糙度贴图里的
float roughnessFactor = roughness;
#ifdef USE_ROUGHNESSMAP
    #if ! defined ( VERSION_1_0_0 )
        roughnessFactor = 1.;
    #endif
    vec4 texelRoughness = texture2D( roughnessMap, vUv );
    // reads channel G, compatible with a combined OcclusionRoughnessMetallic (RGB) texture
    roughnessFactor *= texelRoughness.g;
#endif
vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );
float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
roughnessFactor *= smoothMultiplier;
roughnessFactor = max( roughnessFactor, MIN_PERCEPTUAL_ROUGHNESS );
material.specularRoughness = roughnessFactor;
material.specularRoughness += geometryRoughness;
material.specularRoughness = min( material.specularRoughness, 1.0 );
material.specularRoughness = saturate(material.specularRoughness);

DiffuseColor metalness

  • 高光流
    • metalness通过高光贴图rgb最大值获取
    • DiffuseColor就是baseColor.rgb * (1.0 - metallic);
      • 金属值为1,就没有diffuceColor了
float max3(const vec3 v) {
    return max(v.x, max(v.y, v.z));
}
float computeMetallicFromSpecularColor(const vec3 specularColor) {
    return max3(specularColor);
}
vec3 computeDiffuseColor(const vec4 baseColor, float metallic) {
    return baseColor.rgb * (1.0 - metallic);
}
metalnessFactor = computeMetallicFromSpecularColor(specularFactor);
material.diffuseColor = computeDiffuseColor(diffuseColor, metalnessFactor);
  • 金属流
    • metalness通过金属贴图值获取的
    • DiffuseColor就是baseColor.rgb * (1.0 - metallic);
      • 金属值为1,就没有diffuceColor了
material.diffuseColor = computeDiffuseColor(diffuseColor, metalnessFactor);

SpecularColor metalness

  • 高光流 直接从高光贴图中获取
    • specularFactor使用户输入的参数
    • specularColor是texelSpecular是高光贴图里的
vec3 specularFactor = specular;
#ifdef USE_SPECULARMAP
    vec4 texelSpecular = texture2D( specularMap, vUv );
    texelSpecular = sRGBToLinear( texelSpecular );
    specularFactor *= texelSpecular.rgb;
#endif
material.specularColor = specularFactor.rgb;
#ifdef TYPE_GLASS
    specularFactor = vec3(iorToF0(ior, 1.0));
#endif
material.specularColor = specularFactor.rgb;
  • 金属流
    • metalnessFactor是用户输入的参数值
    • texelMetalness是金属贴图
    • metalness金属度就是金属贴图里的值
    • specularColor通过mix(0.04,baseColor,metallic)
      • 金属度为0的话,依然还是会有specular的,最小值0.04
#define MAXIMUM_SPECULAR_COEFFICIENT 0.16
#define DEFAULT_SPECULAR_COEFFICIENT 0.04
float metalnessFactor = metalness;
#ifdef USE_METALNESSMAP
    vec4 texelMetalness = texture2D( metalnessMap, vUv );
    // reads channel B, compatible with a combined OcclusionRoughnessMetallic (RGB) texture
    metalnessFactor *= texelMetalness.b;
#endif
#ifdef REFLECTIVITY
    // 0.04 = > 0.16
    material.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );
#else
    material.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );
#endif