diff options
Diffstat (limited to 'source/blender/gpu/shaders/material/gpu_shader_material_glass.glsl')
-rw-r--r-- | source/blender/gpu/shaders/material/gpu_shader_material_glass.glsl | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_glass.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_glass.glsl index c328b4800bc..ba02ae6d886 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_glass.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_glass.glsl @@ -1,4 +1,7 @@ #ifndef VOLUMETRICS + +CLOSURE_EVAL_FUNCTION_DECLARE_2(node_bsdf_glass, Glossy, Refraction) + void node_bsdf_glass(vec4 color, float roughness, float ior, @@ -7,32 +10,38 @@ void node_bsdf_glass(vec4 color, float ssr_id, out Closure result) { - N = normalize(N); - vec3 out_spec, out_refr, ssr_spec; - vec3 refr_color = (refractionDepth > 0.0) ? color.rgb * color.rgb : - color.rgb; /* Simulate 2 transmission event */ - eevee_closure_glass(N, - vec3(1.0), - /* HACK: Pass the multiscatter flag as the sign to not add closure - * variations or increase register usage. */ - (use_multiscatter != 0.0) ? vec3(1.0) : -vec3(1.0), - int(ssr_id), - roughness, - 1.0, - ior, - true, - out_spec, - out_refr, - ssr_spec); - float fresnel = F_eta(ior, dot(N, cameraVec)); - vec3 vN = mat3(ViewMatrix) * N; + CLOSURE_VARS_DECLARE_2(Glossy, Refraction); + + in_Glossy_0.N = N; /* Normalized during eval. */ + in_Glossy_0.roughness = roughness; + + in_Refraction_1.N = N; /* Normalized during eval. */ + in_Refraction_1.roughness = roughness; + in_Refraction_1.ior = ior; + + CLOSURE_EVAL_FUNCTION_2(node_bsdf_glass, Glossy, Refraction); + result = CLOSURE_DEFAULT; - result.radiance = render_pass_glossy_mask(refr_color, out_refr * refr_color) * (1.0 - fresnel); - result.radiance += render_pass_glossy_mask(color.rgb, out_spec * color.rgb) * fresnel; + float fresnel = F_eta(in_Refraction_1.ior, dot(in_Glossy_0.N, cameraVec)); + + vec2 split_sum = brdf_lut(dot(in_Glossy_0.N, cameraVec), in_Glossy_0.roughness); + vec3 brdf = (use_multiscatter != 0.0) ? F_brdf_multi_scatter(vec3(1.0), vec3(1.0), split_sum) : + F_brdf_single_scatter(vec3(1.0), vec3(1.0), split_sum); + out_Glossy_0.radiance = closure_mask_ssr_radiance(out_Glossy_0.radiance, ssr_id); + out_Glossy_0.radiance *= brdf; + out_Glossy_0.radiance = render_pass_glossy_mask(vec3(1.0), out_Glossy_0.radiance); + out_Glossy_0.radiance *= color.rgb * fresnel; closure_load_ssr_data( - ssr_spec * color.rgb * fresnel, roughness, N, viewCameraVec, int(ssr_id), result); + out_Glossy_0.radiance, in_Glossy_0.roughness, in_Glossy_0.N, ssr_id, result); + + out_Refraction_1.radiance = render_pass_glossy_mask(vec3(1.0), out_Refraction_1.radiance); + out_Refraction_1.radiance *= color.rgb * (1.0 - fresnel); + /* Simulate 2nd absorption event. */ + out_Refraction_1.radiance *= (refractionDepth > 0.0) ? color.rgb : vec3(1.0); + result.radiance += out_Refraction_1.radiance; } + #else /* Stub glass because it is not compatible with volumetrics. */ # define node_bsdf_glass(a, b, c, d, e, f, result) (result = CLOSURE_DEFAULT) |