| 1 |
#if defined(TARGET_MOBILE) |
| 2 |
// min roughness such that (MIN_PERCEPTUAL_ROUGHNESS^4) > 0 in fp16 (i.e. 2^(-14/4), rounded up) |
| 3 |
#define MIN_PERCEPTUAL_ROUGHNESS 0.089 |
| 4 |
#define MIN_ROUGHNESS 0.007921 |
| 5 |
#else |
| 6 |
#define MIN_PERCEPTUAL_ROUGHNESS 0.045 |
| 7 |
#define MIN_ROUGHNESS 0.002025 |
| 8 |
#endif |
| 9 |
|
| 10 |
#define MIN_N_DOT_V 1e-4 |
| 11 |
|
| 12 |
float clampNoV(float NoV) { |
| 13 |
// Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886" |
| 14 |
return max(NoV, MIN_N_DOT_V); |
| 15 |
} |
| 16 |
|
| 17 |
vec3 computeDiffuseColor(const vec4 baseColor, float metallic) { |
| 18 |
return baseColor.rgb * (1.0 - metallic); |
| 19 |
} |
| 20 |
|
| 21 |
vec3 computeF0(const vec4 baseColor, float metallic, float reflectance) { |
| 22 |
return baseColor.rgb * metallic + (reflectance * (1.0 - metallic)); |
| 23 |
} |
| 24 |
|
| 25 |
float computeDielectricF0(float reflectance) { |
| 26 |
return 0.16 * reflectance * reflectance; |
| 27 |
} |
| 28 |
|
| 29 |
float computeMetallicFromSpecularColor(const vec3 specularColor) { |
| 30 |
return max3(specularColor); |
| 31 |
} |
| 32 |
|
| 33 |
float computeRoughnessFromGlossiness(float glossiness) { |
| 34 |
return 1.0 - glossiness; |
| 35 |
} |
| 36 |
|
| 37 |
float perceptualRoughnessToRoughness(float perceptualRoughness) { |
| 38 |
return perceptualRoughness * perceptualRoughness; |
| 39 |
} |
| 40 |
|
| 41 |
float roughnessToPerceptualRoughness(float roughness) { |
| 42 |
return sqrt(roughness); |
| 43 |
} |
| 44 |
|
| 45 |
float iorToF0(float transmittedIor, float incidentIor) { |
| 46 |
return sq((transmittedIor - incidentIor) / (transmittedIor + incidentIor)); |
| 47 |
} |
| 48 |
|
| 49 |
float f0ToIor(float f0) { |
| 50 |
float r = sqrt(f0); |
| 51 |
return (1.0 + r) / (1.0 - r); |
| 52 |
} |
| 53 |
|
| 54 |
vec3 f0ClearCoatToSurface(const vec3 f0) { |
| 55 |
// Approximation of iorTof0(f0ToIor(f0), 1.5) |
| 56 |
// This assumes that the clear coat layer has an IOR of 1.5 |
| 57 |
#if FILAMENT_QUALITY == FILAMENT_QUALITY_LOW |
| 58 |
return saturate(f0 * (f0 * 0.526868 + 0.529324) - 0.0482256); |
| 59 |
#else |
| 60 |
return saturate(f0 * (f0 * (0.941892 - 0.263008 * f0) + 0.346479) - 0.0285998); |
| 61 |
#endif |
| 62 |
} |