sebavan 6 éve
szülő
commit
3b0f0f84c4

+ 5 - 0
src/Shaders/ShadersInclude/helperFunctions.fx

@@ -68,6 +68,11 @@ float square(float value)
     return value * value;
 }
 
+float pow5(float value) {
+    float sq = value * value;
+    return sq * sq * value;
+}
+
 float getLuminance(vec3 color)
 {
     return clamp(dot(color, LuminanceEncodeApprox), 0., 1.);

+ 5 - 5
src/Shaders/ShadersInclude/pbrFunctions.fx

@@ -92,7 +92,7 @@ vec3 getReflectanceFromAnalyticalBRDFLookup_Jones(float VdotN, vec3 reflectance0
 {
     // Schlick fresnel approximation, extended with basic smoothness term so that rough surfaces do not approach reflectance90 at grazing angle
     float weight = mix(FRESNEL_MAXIMUM_ON_ROUGH, 1.0, smoothness);
-    return reflectance0 + weight * (reflectance90 - reflectance0) * pow(saturate(1.0 - VdotN), 5.0);
+    return reflectance0 + weight * (reflectance90 - reflectance0) * pow5(saturate(1.0 - VdotN));
 }
 
 vec3 getSheenReflectanceFromBRDFLookup(const vec3 reflectance0, float NdotV, float sheenAlphaG) {
@@ -274,12 +274,12 @@ float smithVisibility_GGXCorrelated_Anisotropic(float NdotL, float NdotV, float
 
 vec3 fresnelSchlickGGX(float VdotH, vec3 reflectance0, vec3 reflectance90)
 {
-    return reflectance0 + (reflectance90 - reflectance0) * pow(1.0 - VdotH, 5.0);
+    return reflectance0 + (reflectance90 - reflectance0) * pow5(1.0 - VdotH);
 }
 
 float fresnelSchlickGGX(float VdotH, float reflectance0, float reflectance90)
 {
-    return reflectance0 + (reflectance90 - reflectance0) * pow(1.0 - VdotH, 5.0);
+    return reflectance0 + (reflectance90 - reflectance0) * pow5(1.0 - VdotH);
 }
 
 // From beer lambert law I1/I0 = e −α′lc
@@ -300,8 +300,8 @@ vec3 computeColorAtDistanceInMedia(vec3 color, float distance) {
 float computeDiffuseTerm(float NdotL, float NdotV, float VdotH, float roughness) {
     // Diffuse fresnel falloff as per Disney principled BRDF, and in the spirit of
     // of general coupled diffuse/specular models e.g. Ashikhmin Shirley.
-    float diffuseFresnelNV = pow(saturateEps(1.0 - NdotL), 5.0);
-    float diffuseFresnelNL = pow(saturateEps(1.0 - NdotV), 5.0);
+    float diffuseFresnelNV = pow5(saturateEps(1.0 - NdotL));
+    float diffuseFresnelNL = pow5(saturateEps(1.0 - NdotV));
     float diffuseFresnel90 = 0.5 + 2.0 * VdotH * VdotH * roughness;
     float fresnel =
         (1.0 + (diffuseFresnel90 - 1.0) * diffuseFresnelNL) *

+ 6 - 6
src/Shaders/background.fragment.fx

@@ -107,7 +107,7 @@ varying vec3 vNormalW;
     {
         // Schlick fresnel approximation, extended with basic smoothness term so that rough surfaces do not approach reflectance90 at grazing angle
         float weight = mix(FRESNEL_MAXIMUM_ON_ROUGH, 1.0, smoothness);
-        return reflectance0 + weight * (reflectance90 - reflectance0) * pow(clamp(1.0 - VdotN, 0., 1.), 5.0);
+        return reflectance0 + weight * (reflectance90 - reflectance0) * pow5(saturate(1.0 - VdotN));
     }
 #endif
 
@@ -163,7 +163,7 @@ vec4 reflectionColor = vec4(1., 1., 1., 1.);
             reflectionLOD = reflectionLOD * log2(vReflectionMicrosurfaceInfos.x) * vReflectionMicrosurfaceInfos.y + vReflectionMicrosurfaceInfos.z;
             reflectionColor = sampleReflectionLod(reflectionSampler, reflectionCoords, reflectionLOD);
         #else
-            float lodReflectionNormalized = clamp(reflectionLOD, 0., 1.);
+            float lodReflectionNormalized = saturate(reflectionLOD);
             float lodReflectionNormalizedDoubled = lodReflectionNormalized * 2.0;
 
             vec4 reflectionSpecularMid = sampleReflection(reflectionSampler, reflectionCoords);
@@ -249,16 +249,16 @@ float finalAlpha = alpha;
     vec3 reflectionReflectance90 = vReflectionControl.zzz;
     float VdotN = dot(normalize(vEyePosition), normalW);
 
-    vec3 planarReflectionFresnel = fresnelSchlickEnvironmentGGX(clamp(VdotN, 0.0, 1.0), reflectionReflectance0, reflectionReflectance90, 1.0);
+    vec3 planarReflectionFresnel = fresnelSchlickEnvironmentGGX(saturate(VdotN), reflectionReflectance0, reflectionReflectance90, 1.0);
     reflectionAmount *= planarReflectionFresnel;
 
     #ifdef REFLECTIONFALLOFF
-        float reflectionDistanceFalloff = 1.0 - clamp(length(vPositionW.xyz - vBackgroundCenter) * vReflectionControl.w, 0.0, 1.0);
+        float reflectionDistanceFalloff = 1.0 - saturate(length(vPositionW.xyz - vBackgroundCenter) * vReflectionControl.w);
         reflectionDistanceFalloff *= reflectionDistanceFalloff;
         reflectionAmount *= reflectionDistanceFalloff;
     #endif
 
-    finalColor = mix(finalColor, reflectionColor.rgb, clamp(reflectionAmount, 0., 1.));
+    finalColor = mix(finalColor, reflectionColor.rgb, saturate(reflectionAmount));
 #endif
 
 #ifdef OPACITYFRESNEL
@@ -266,7 +266,7 @@ float finalAlpha = alpha;
 
     // Fade out the floor plane as the angle between the floor and the camera tends to 0 (starting from startAngle)
     const float startAngle = 0.1;
-    float fadeFactor = clamp(viewAngleToFloor/startAngle, 0.0, 1.0);
+    float fadeFactor = saturate(viewAngleToFloor/startAngle);
 
     finalAlpha *= fadeFactor * fadeFactor;
 #endif

+ 1 - 1
src/Shaders/pbr.fragment.fx

@@ -741,7 +741,7 @@ void main(void) {
         #endif
 
         #ifdef SHEEN_LINKWITHALBEDO
-            float sheenFactor = pow(1.0-sheenIntensity, 5.0);
+            float sheenFactor = pow5(1.0-sheenIntensity);
             vec3 sheenColor = baseColor.rgb*(1.0-sheenFactor);
             float sheenRoughness = sheenIntensity;
             // remap albedo.