Blender V5.3
gpu_shader_material_eevee_specular.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
9
10[[node]]
12 float4 specular,
13 float roughness,
14 float4 emissive,
15 float transp,
16 float3 N,
17 float clearcoat,
18 float clearcoat_roughness,
19 float3 CN,
20 float weight,
21 const float use_clearcoat,
23 ShadingData &sd,
24 Closure &result)
25{
26 diffuse = max(diffuse, float4(0));
27 specular = max(specular, float4(0));
28 roughness = saturate(roughness);
29 emissive = max(emissive, float4(0));
31 clearcoat = saturate(clearcoat);
32 clearcoat_roughness = saturate(clearcoat_roughness);
33 CN = safe_normalize(CN);
34
35 float3 V = coordinate_impl(kg, sd, sd.P, sd.N).incoming;
36
37 ClosureEmission emission_data;
38 emission_data.emission = emissive.rgb * weight;
39
40 ClosureTransparency transparency_data;
41 transparency_data.transmittance = float3(transp * weight);
42 transparency_data.holdout = 0.0f;
43
44 float alpha = (1.0f - transp) * weight;
45
46 ClosureDiffuse diffuse_data;
47 diffuse_data.color = diffuse.rgb * alpha;
48 diffuse_data.N = N;
49
50 ClosureReflection reflection_data;
51 {
52 float weight = alpha;
53 float3 brdf = brdf_lut(kg, specular.rgb, float3(1.0f), dot(N, V), roughness, false);
54
55 reflection_data.color = brdf * weight;
56 reflection_data.N = N;
57 reflection_data.roughness = roughness;
58 }
59
60 ClosureReflection clearcoat_data;
61 {
62 float weight = alpha * clearcoat * 0.25f;
63 float3 brdf = brdf_lut(
64 kg, float3(0.04f), float3(1.0f), dot(CN, V), clearcoat_roughness, false);
65
66 clearcoat_data.color = brdf * weight;
67 clearcoat_data.N = CN;
68 clearcoat_data.roughness = clearcoat_roughness;
69 }
70
71 if (use_clearcoat != 0.0f) {
72 result = closure_eval(kg, sd, diffuse_data, reflection_data, clearcoat_data);
73 }
74 else {
75 result = closure_eval(kg, sd, diffuse_data, reflection_data);
76 }
77 Closure emission_cl = closure_eval(kg, sd, emission_data);
78 Closure transparency_cl = closure_eval(kg, sd, transparency_data);
79 result = closure_add(result, emission_cl);
80 result = closure_add(result, transparency_cl);
81}
btScalar max
Closure closure_add(Closure, Closure)
float3 brdf_lut(KernelGlobals &kg, float3 F0, float3 F90, float cos_theta, float roughness, bool do_multiscatter)
Coordinates coordinate_impl(KernelGlobals &kg, const ShadingData &sd, float3 P, float3 N)
Closure closure_eval(KernelGlobals &kg, ShadingData &sd, ClosureDiffuse diffuse)
#define resource_table
float dot(VecOp< float, D >, VecOp< float, D >) RET
void node_eevee_specular(float4 diffuse, float4 specular, float roughness, float4 emissive, float transp, float3 N, float clearcoat, float clearcoat_roughness, float3 CN, float weight, const float use_clearcoat, KernelGlobals &kg, ShadingData &sd, Closure &result)
VecT safe_normalize(VecT vector)
#define N
#define saturate(a)
Definition smaa.cc:319
CCL_NAMESPACE_BEGIN struct Window V