Created
March 19, 2023 23:33
-
-
Save MisterSirCode/d0dc53a1cac6cc043da2b9202186531c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define MIN(x, y) ((x) < (y) ? (x) : (y)) | |
#define MAX(x, y) ((x) > (y) ? (x) : (y)) | |
shader BaGlass( | |
int Sharp_Beckmann_GGX = 1, | |
color Reflection_Color = color(0.8, 0.8, 0.8), | |
float Reflection_Strength = 1.0, | |
float Reflection_Roughness = 0.05, | |
int Reflection_FromBack = 1, | |
color Refraction_Color = color(0.8, 0.8, 0.8), | |
float Refraction_Strength = 1.0, | |
float Refraction_Roughness = 0.05, | |
float IOR = 1.52, | |
normal Normal = N, | |
output closure color BSDF = holdout()) | |
{ | |
float eta = backfacing() ? 1.0/IOR : IOR; | |
float A, B; | |
float c = fabs(dot(I, Normal)); | |
float g = eta * eta - 1 + c * c; | |
float Fr = 1.0; | |
int SharpStyle = MAX(MIN(Sharp_Beckmann_GGX,2),0); | |
int BackReflect = MAX(MIN(Reflection_FromBack,1),0); | |
if (!BackReflect) SharpStyle = 0; | |
if (g > 0) { | |
g = sqrt(g); | |
A = (g - c) / (g + c); | |
B = (c * (g + c) - 1) / (c * (g - c) + 1); | |
Fr = 0.5 * A * A * (1 + B * B); | |
} | |
if ( (!backfacing() && (Reflection_Strength > 0.001)) || | |
(backfacing() && BackReflect && (Reflection_Strength > 0.001)) ) | |
{ | |
if (SharpStyle == 0) | |
{ | |
BSDF = Reflection_Color * Fr * Reflection_Strength * reflection(Normal) + | |
Refraction_Color * (1.0 - Fr) * Refraction_Strength * refraction(Normal, eta); | |
} | |
else if (SharpStyle == 1) | |
{ | |
BSDF = Reflection_Color * Fr * Reflection_Strength * | |
microfacet_beckmann(Normal, Reflection_Roughness) + | |
Refraction_Color * (1.0 - Fr) * Refraction_Strength * | |
microfacet_beckmann_refraction(Normal, Refraction_Roughness, eta); | |
} | |
else if (SharpStyle == 2) | |
{ | |
BSDF = Reflection_Color * Fr * Reflection_Strength * | |
microfacet_ggx(Normal, Reflection_Roughness) + | |
Refraction_Color * (1.0 - Fr) * Refraction_Strength * | |
microfacet_ggx_refraction(Normal, Refraction_Roughness, eta); | |
} | |
} | |
else | |
{ | |
if (SharpStyle == 0) | |
{ | |
BSDF = Refraction_Color * (1.0 - Fr) * Refraction_Strength * | |
refraction(Normal, eta); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment