Blender V5.3
eevee_surf_common.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10#include "eevee_uniform.bsl.hh"
13
14namespace eevee {
15
16/* Common interface */
18 /* World Position. */
20 /* World Normal. */
22 /* Resource ID. */
24};
25
28};
29
34
38 [[smooth]] float time;
39 [[smooth]] float time_width;
40 [[smooth]] float radius;
41 [[smooth]] float point_id; /* Smooth to be used for barycentric. */
42 [[flat]] int strand_id;
43};
44
46 [[smooth]] float radius;
48 [[flat]] int id;
49};
50
55
58};
59
60struct ClipPlane {
61 [[uniform(CLIP_PLANE_BUF)]] ClipPlaneData &clip_plane;
62};
63
64struct GeomShadow {
66 read)]] const ShadowRenderView (&render_view_buf)[SHADOW_VIEW_MAX];
67};
68
69void init_globals_mesh(const VertOutCommon &interp, ShadingData &sd, float3 barycentric_co)
70{
71 float wp_delta = 0.0f;
72 float bc_delta = 0.0f;
73#if defined(GPU_FRAGMENT_SHADER) || defined(GLSL_CPP_STUBS)
74 wp_delta = length(gpu_dfdx(interp.P)) + length(gpu_dfdy(interp.P));
75 bc_delta = length(gpu_dfdx(barycentric_co)) + length(gpu_dfdy(barycentric_co));
76#endif
77 float rate_of_change = wp_delta * safe_rcp(bc_delta);
78 sd.barycentric_dists = rate_of_change * (1.0f - barycentric_co);
79 sd.barycentric_coords = barycentric_co.xy;
80}
81
83 const VertOutCurves &curve_interp,
84 ShadingData &sd,
85 const ViewMatrices view)
86{
87 /* Shade as a cylinder. */
88 float cos_theta = curve_interp.time_width / curve_interp.radius;
90 sd.N = sd.Ni = normalize(interp.N * sin_theta + curve_interp.binormal * cos_theta);
91
92 /* Costly, but follows cycles per pixel tangent space (not following curve shape). */
94 sd.curve_T = -curve_interp.tangent;
95 sd.curve_B = cross(V, sd.curve_T);
97
98 sd.is_strand = true;
99 sd.hair_diameter = curve_interp.radius * 2.0;
100 sd.hair_strand_id = curve_interp.strand_id;
101 sd.barycentric_coords.y = fract(curve_interp.point_id);
103}
104
106{
107 sd.point_position = ptcloud_interp.position;
108 sd.point_radius = ptcloud_interp.radius;
109 sd.point_id = ptcloud_interp.id;
110}
111
113 const eevee::Uniform &uni,
114 const VertOutCommon &interp,
115 const ViewMatrices view,
116 bool front_face,
117 float4 fragment_co)
118{
119 ShadingData sd;
120 /* Default values. */
121 sd.frag_co = fragment_co;
122 sd.front_facing = front_face;
123 sd.P = interp.P;
124 sd.Ni = interp.N;
125 sd.N = safe_normalize(interp.N);
126 sd.Ng = sd.N;
127 sd.is_strand = false;
128 sd.hair_diameter = 0.0f;
129 sd.hair_strand_id = 0;
130 sd.point_position = float3(0.0f);
131 sd.point_radius = 0.0f;
132 sd.point_id = 0;
133 if (pipe.is_shadow_pipe) [[static_branch]] {
135 }
136 else if (pipe.is_capture_pipe) [[static_branch]] {
138 }
139 else {
140 sd.ray_type = uni.pipeline_buf.ray_type;
141 }
142 sd.ray_depth = 0.0f;
143 sd.ray_length = distance(sd.P, view.position());
144 sd.barycentric_coords = float2(0.0f);
145 sd.barycentric_dists = float3(0.0f);
147 sd.resource_id_raw = interp.resource_id_raw;
148
149 sd.N = (front_face) ? sd.N : -sd.N;
150 sd.Ni = (front_face) ? sd.Ni : -sd.Ni;
151#if defined(GPU_FRAGMENT_SHADER) || defined(GLSL_CPP_STUBS)
152 sd.Ng = safe_normalize(cross(gpu_dfdx(sd.P), gpu_dfdy(sd.P)));
153 if (uni.pipeline_buf.is_main_view_inverted) {
154 sd.Ng = -sd.Ng;
155 }
156#endif
157 return sd;
158}
159
160/* Avoid some compiler issue with non set interface parameters. */
161void init_interface(VertOutCommon &interp, uint resource_id_raw)
162{
163 interp.P = float3(0.0f);
164 interp.N = float3(0.0f);
165 interp.resource_id_raw = resource_id_raw;
166}
167
168float3 gsplat_amend_transmittance([[maybe_unused]] const VertOutGSplat &gsplat_interp,
169 float3 transmittance)
170{
171 float alpha = draw::gsplat::evaluate_gaussian(gsplat_interp.billboard_co, gsplat_interp.opacity);
172 alpha = saturate(alpha * (256.0f / 255.0f));
173 return float3(1.0f) - alpha * saturate(float3(1.0f) - transmittance);
174}
175
176} // namespace eevee
177
178float3 shadow_position_vector_get(float3 view_position, ShadowRenderView view)
179{
180 if (view.is_directional) {
181 return float3(0.0f, 0.0f, -view_position.z - view.clip_near);
182 }
183 return view_position;
184}
185
186/* In order to support physical clipping, we pass a vector to the fragment shader that then clips
187 * each fragment using a unit sphere test. This allows to support both point light and area light
188 * clipping at the same time. */
189float3 shadow_clip_vector_get(float3 view_position, float clip_distance_inv)
190{
191 if (clip_distance_inv == 0.0f) {
192 /* No clipping. */
193 return float3(2.0f);
194 }
195 /* Punctual shadow case. */
196 return view_position * clip_distance_inv;
197}
ccl_device_inline float cos_theta(const float3 w)
ccl_device_inline float sin_theta(const float3 w)
static Thickness zero()
#define SHADOW_RENDER_VIEW_BUF_SLOT
#define CLIP_PLANE_BUF
float3 shadow_position_vector_get(float3 view_position, ShadowRenderView view)
float3 shadow_clip_vector_get(float3 view_position, float clip_distance_inv)
#define uniform(slot)
#define storage(slot, qualifiers)
#define flat
#define smooth
#define static_branch
T fract(T) RET
T gpu_dfdx(T) RET
VecBase< float, D > normalize(VecOp< float, D >) RET
float distance(float, float) RET
T gpu_dfdy(T) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
float length(VecOp< float, D >) RET
float sin_from_cos(float c)
float safe_rcp(float a)
VecT safe_normalize(VecT vector)
ccl_device_inline float interp(const float a, const float b, const float t)
Definition math_base.h:549
float evaluate_gaussian(float2 x_min_mu, float opacity)
ShadingData init_globals(const eevee::PipelineConstants &pipe, const eevee::Uniform &uni, const VertOutCommon &interp, const ViewMatrices view, bool front_face, float4 fragment_co)
float3 gsplat_amend_transmittance(const VertOutGSplat &gsplat_interp, float3 transmittance)
void init_globals_mesh(const VertOutCommon &interp, ShadingData &sd, float3 barycentric_co)
void init_globals_pointcloud(const VertOutPointcloud &ptcloud_interp, ShadingData &sd)
void init_interface(VertOutCommon &interp, uint resource_id_raw)
void init_globals_curves(const VertOutCommon &interp, const VertOutCurves &curve_interp, ShadingData &sd, const ViewMatrices view)
#define saturate(a)
Definition smaa.cc:319
packed_float3 barycentric_dists
packed_float2 barycentric_coords
packed_float3 curve_N
packed_float3 curve_T
packed_float3 curve_B
packed_float3 point_position
float3 position() const
float3 world_incident_vector(float3 P) const
ClipPlaneData & clip_plane
const ShadowRenderView(& render_view_buf)[SHADOW_VIEW_MAX]
const PipelineInfoData & pipeline_buf
float x
float y
float z
Definition sky_math.h:136
CCL_NAMESPACE_BEGIN struct Window V