Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
| #pragma BLENDER_REQUIRE(common_math_lib.glsl) | #pragma BLENDER_REQUIRE(common_math_lib.glsl) | ||||
| vec3 diffuse_dominant_dir(vec3 N, vec3 vis_cone_dir, float vis_cone_aperture_cos) | |||||
| { | |||||
| /* TODO(fclem) revisit this. bent too much towards vis_cone_dir. */ | |||||
| vis_cone_aperture_cos *= sqr(vis_cone_aperture_cos); | |||||
| N = mix(vis_cone_dir, N, vis_cone_aperture_cos); | |||||
| return normalize(N); | |||||
| } | |||||
| vec3 specular_dominant_dir(vec3 N, vec3 V, float roughness) | vec3 specular_dominant_dir(vec3 N, vec3 V, float roughness) | ||||
| { | { | ||||
| vec3 R = -reflect(V, N); | vec3 R = -reflect(V, N); | ||||
| float smoothness = 1.0 - roughness; | float smoothness = 1.0 - roughness; | ||||
| float fac = smoothness * (sqrt(smoothness) + roughness); | float fac = smoothness * (sqrt(smoothness) + roughness); | ||||
| return normalize(mix(N, R, fac)); | return normalize(mix(N, R, fac)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | vec3 F_color_blend(float eta, float fresnel, vec3 f0_color) | ||||
| return mix(f0_color, vec3(1.0), fac); | return mix(f0_color, vec3(1.0), fac); | ||||
| } | } | ||||
| /* Fresnel split-sum approximation. */ | /* Fresnel split-sum approximation. */ | ||||
| vec3 F_brdf_single_scatter(vec3 f0, vec3 f90, vec2 lut) | vec3 F_brdf_single_scatter(vec3 f0, vec3 f90, vec2 lut) | ||||
| { | { | ||||
| /* Unreal specular matching : if specular color is below 2% intensity, | /* Unreal specular matching : if specular color is below 2% intensity, | ||||
| * treat as shadowning */ | * treat as shadowning */ | ||||
| return saturate(50.0 * dot(f0, vec3(0.3, 0.6, 0.1))) * lut.y * abs(f90) + lut.x * f0; | return lut.y * f90 + lut.x * f0; | ||||
| } | } | ||||
| /* Multi-scattering brdf approximation from : | /* Multi-scattering brdf approximation from : | ||||
| * "A Multiple-Scattering Microfacet Model for Real-Time Image-based Lighting" | * "A Multiple-Scattering Microfacet Model for Real-Time Image-based Lighting" | ||||
| * by Carmelo J. Fdez-Agüera. */ | * by Carmelo J. Fdez-Agüera. */ | ||||
| vec3 F_brdf_multi_scatter(vec3 f0, vec3 f90, vec2 lut) | vec3 F_brdf_multi_scatter(vec3 f0, vec3 f90, vec2 lut) | ||||
| { | { | ||||
| vec3 FssEss = F_brdf_single_scatter(f0, f90, lut); | vec3 FssEss = lut.y * f90 + lut.x * f0; | ||||
| /* Hack to avoid many more shader variations. */ | |||||
| if (f90.g < 0.0) { | |||||
| return FssEss; | |||||
| } | |||||
| float Ess = lut.x + lut.y; | float Ess = lut.x + lut.y; | ||||
| float Ems = 1.0 - Ess; | float Ems = 1.0 - Ess; | ||||
| vec3 Favg = f0 + (1.0 - f0) / 21.0; | vec3 Favg = f0 + (1.0 - f0) / 21.0; | ||||
| vec3 Fms = FssEss * Favg / (1.0 - (1.0 - Ess) * Favg); | vec3 Fms = FssEss * Favg / (1.0 - (1.0 - Ess) * Favg); | ||||
| /* We don't do anything special for diffuse surfaces because the principle bsdf | /* We don't do anything special for diffuse surfaces because the principle bsdf | ||||
| * does not care about energy conservation of the specular layer for dielectrics. */ | * does not care about energy conservation of the specular layer for dielectrics. */ | ||||
| return FssEss + Fms * Ems; | return FssEss + Fms * Ems; | ||||
| } | } | ||||
| #define F_brdf(f0, f90, lut) F_brdf_multi_scatter(f0, f90, lut) | |||||
| /* GGX */ | /* GGX */ | ||||
| float D_ggx_opti(float NH, float a2) | float D_ggx_opti(float NH, float a2) | ||||
| { | { | ||||
| float tmp = (NH * a2 - NH) * NH + 1.0; | float tmp = (NH * a2 - NH) * NH + 1.0; | ||||
| return M_PI * tmp * tmp; /* Doing RCP and mul a2 at the end */ | return M_PI * tmp * tmp; /* Doing RCP and mul a2 at the end */ | ||||
| } | } | ||||
| float G1_Smith_GGX(float NX, float a2) | float G1_Smith_GGX(float NX, float a2) | ||||
| ▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines | |||||