diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-04-14 19:47:58 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-04-14 19:47:58 +0300 |
commit | 80859a6cb2726a39fb22cb49f06e0355dc9390a7 (patch) | |
tree | fd3f8ead5a247a79ea11e4aacc720843bbc5e2c2 /source/blender/gpu/shaders/material/gpu_shader_material_eevee_specular.glsl | |
parent | 66dc4d4efb88ecf2d18bfa08ab9c43b024ebd2fb (diff) |
GPU: Make nodetree GLSL Codegen render engine agnostic
This commit removes all EEVEE specific code from the `gpu_shader_material*.glsl`
files. It defines a clear interface to evaluate the closure nodes leaving
more flexibility to the render engine.
Some of the long standing workaround are fixed:
- bump mapping support is no longer duplicating a lot of node and is instead
compiled into a function call.
- bump rewiring to Normal socket is no longer needed as we now use a global
`g_data.N` for that.
Closure sampling with upstread weight eval is now supported if the engine needs
it.
This also makes all the material GLSL sources use `GPUSource` for better
debugging experience. The `GPUFunction` parsing now happens in `GPUSource`
creation.
The whole `GPUCodegen` now uses the `ShaderCreateInfo` and is object type
agnostic. Is has also been rewritten in C++.
This patch changes a view behavior for EEVEE:
- Mix shader node factor imput is now clamped.
- Tangent Vector displacement behavior is now matching cycles.
- The chosen BSDF used for SSR might change.
- Hair shading may have very small changes on very large hairs when using hair
polygon stripes.
- ShaderToRGB node will remove any SSR and SSS form a shader.
- SSS radius input now is no longer a scaling factor but defines an average
radius. The SSS kernel "shape" (radii) are still defined by the socket default
values.
Appart from the listed changes no other regressions are expected.
Diffstat (limited to 'source/blender/gpu/shaders/material/gpu_shader_material_eevee_specular.glsl')
-rw-r--r-- | source/blender/gpu/shaders/material/gpu_shader_material_eevee_specular.glsl | 101 |
1 files changed, 45 insertions, 56 deletions
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_eevee_specular.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_eevee_specular.glsl index 0941482df45..c81880184e3 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_eevee_specular.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_eevee_specular.glsl @@ -1,80 +1,69 @@ -#ifndef VOLUMETRICS - -CLOSURE_EVAL_FUNCTION_DECLARE_3(node_eevee_specular, Diffuse, Glossy, Glossy) void node_eevee_specular(vec4 diffuse, vec4 specular, float roughness, vec4 emissive, float transp, - vec3 normal, + vec3 N, float clearcoat, float clearcoat_roughness, - vec3 clearcoat_normal, + vec3 CN, float occlusion, - float ssr_id, + float weight, + const float use_clearcoat, out Closure result) { - CLOSURE_VARS_DECLARE_3(Diffuse, Glossy, Glossy); - - in_common.occlusion = occlusion; - - in_Diffuse_0.N = normal; /* Normalized during eval. */ - in_Diffuse_0.albedo = diffuse.rgb; + N = safe_normalize(N); + CN = safe_normalize(CN); + vec3 V = cameraVec(g_data.P); - in_Glossy_1.N = normal; /* Normalized during eval. */ - in_Glossy_1.roughness = roughness; + ClosureEmission emission_data; + emission_data.weight = weight; + emission_data.emission = emissive.rgb; - in_Glossy_2.N = clearcoat_normal; /* Normalized during eval. */ - in_Glossy_2.roughness = clearcoat_roughness; + ClosureTransparency transparency_data; + transparency_data.weight = weight; + transparency_data.transmittance = vec3(transp); + transparency_data.holdout = 0.0; - CLOSURE_EVAL_FUNCTION_3(node_eevee_specular, Diffuse, Glossy, Glossy); + float alpha = (1.0 - transp) * weight; - result = CLOSURE_DEFAULT; + ClosureDiffuse diffuse_data; + diffuse_data.weight = alpha; + diffuse_data.color = diffuse.rgb; + diffuse_data.N = N; + diffuse_data.sss_id = 0u; - vec3 V = cameraVec(worldPosition); - - { - /* Diffuse. */ - out_Diffuse_0.radiance = render_pass_diffuse_mask(vec3(1), out_Diffuse_0.radiance); - out_Diffuse_0.radiance *= in_Diffuse_0.albedo; - result.radiance += out_Diffuse_0.radiance; - } - { - /* Glossy. */ - float NV = dot(in_Glossy_1.N, V); - vec2 split_sum = brdf_lut(NV, in_Glossy_1.roughness); + ClosureReflection reflection_data; + reflection_data.weight = alpha; + if (true) { + float NV = dot(N, V); + vec2 split_sum = brdf_lut(NV, roughness); vec3 brdf = F_brdf_single_scatter(specular.rgb, vec3(1.0), split_sum); - out_Glossy_1.radiance = closure_mask_ssr_radiance(out_Glossy_1.radiance, ssr_id); - out_Glossy_1.radiance *= brdf; - out_Glossy_1.radiance = render_pass_glossy_mask(specular.rgb, out_Glossy_1.radiance); - closure_load_ssr_data( - out_Glossy_1.radiance, in_Glossy_1.roughness, in_Glossy_1.N, ssr_id, result); + reflection_data.color = specular.rgb * brdf; + reflection_data.N = N; + reflection_data.roughness = roughness; } - { - /* Clearcoat. */ - float NV = dot(in_Glossy_2.N, V); - vec2 split_sum = brdf_lut(NV, in_Glossy_2.roughness); + + ClosureReflection clearcoat_data; + clearcoat_data.weight = alpha * clearcoat * 0.25; + if (true) { + float NV = dot(CN, V); + vec2 split_sum = brdf_lut(NV, clearcoat_roughness); vec3 brdf = F_brdf_single_scatter(vec3(0.04), vec3(1.0), split_sum); - out_Glossy_2.radiance *= brdf * clearcoat * 0.25; - out_Glossy_2.radiance = render_pass_glossy_mask(vec3(1), out_Glossy_2.radiance); - result.radiance += out_Glossy_2.radiance; - } - { - /* Emission. */ - vec3 out_emission_radiance = render_pass_emission_mask(emissive.rgb); - result.radiance += out_emission_radiance; + clearcoat_data.color = brdf; + clearcoat_data.N = CN; + clearcoat_data.roughness = clearcoat_roughness; } - float alpha = 1.0 - transp; - result.transmittance = vec3(transp); - result.radiance *= alpha; - result.ssr_data.rgb *= alpha; + if (use_clearcoat != 0.0f) { + result = closure_eval(diffuse_data, reflection_data, clearcoat_data); + } + else { + result = closure_eval(diffuse_data, reflection_data); + } + result = closure_add(result, closure_eval(emission_data)); + result = closure_add(result, closure_eval(transparency_data)); } - -#else -/* Stub specular because it is not compatible with volumetrics. */ -# define node_eevee_specular(a, b, c, d, e, f, g, h, i, j, k, result) (result = CLOSURE_DEFAULT) -#endif |