Blender V5.3
gpu_shader_material_interface.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
13#include "gpu_shader_codegen_lib.glsl"
14
15/* This file must replaced at runtime. The following content is only a possible implementation. */
16#pragma runtime_generated
17
18struct Closure {};
19#define CLOSURE_DEFAULT \
20 { \
21 }
22
23enum eObjectInfoFlag : uint32_t {
24 OBJECT_SELECTED = (1u << 0u),
25 OBJECT_FROM_DUPLI = (1u << 1u),
26 OBJECT_FROM_SET = (1u << 2u),
27 OBJECT_ACTIVE = (1u << 3u),
29 OBJECT_HOLDOUT = (1u << 5u),
30 /* Implies all objects that match the current active object's mode and able to be edited
31 * simultaneously. Currently only applicable for edit mode. */
33 /* Avoid skipped info to change culling. */
35};
36
43
44/* Expected members of ViewMatrices. */
45struct ViewMatrices {
50};
51
52/* Expected members of ObjectMatrices. */
53struct ObjectMatrices {
56};
57
58/* Expected members of ObjectInfos. */
59struct ObjectInfos {
61 uint index;
62 float random;
64};
65
66struct ShadingData {
83 float hair_diameter;
88 float point_radius;
89 int point_id;
91 float ray_depth;
92 float ray_length;
95 bool is_strand;
97 bool front_facing;
98
99 /* TODO(fclem): Supposed to be an implementation detail. */
100 float holdout;
101};
102
103/* Should eventually carry the needed resource tables. */
104struct KernelGlobals {
105 /* Add dummy push constant to tag struct as resource table.. */
107
109 {
110 return {};
111 }
112
114 {
115 return {};
116 }
117
119 {
120 return {};
121 }
122
124 {
125 return {};
126 }
127
129 {
130 return {};
131 }
132};
133
134/* Closure Nodes. */
135
137{
138 return {};
139}
140Closure closure_mix(Closure /*cl1*/, Closure /*cl2*/, float /*fac*/)
141{
142 return {};
143}
144Closure closure_eval(KernelGlobals & /*kg*/, ShadingData & /*sd*/, ClosureDiffuse /*diffuse*/)
145{
146 return {};
147}
148Closure closure_eval(KernelGlobals & /*kg*/, ShadingData & /*sd*/, ClosureSubsurface /*diffuse*/)
149{
150 return {};
151}
153 ShadingData & /*sd*/,
154 ClosureTranslucent /*translucent*/)
155{
156 return {};
157}
159 ShadingData & /*sd*/,
160 ClosureReflection /*reflection*/)
161{
162 return {};
163}
165 ShadingData & /*sd*/,
166 ClosureRefraction /*refraction*/)
167{
168 return {};
169}
171 ShadingData & /*sd*/,
172 ClosureThinRefraction /*refraction*/)
173{
174 return {};
175}
176Closure closure_eval(KernelGlobals & /*kg*/, ShadingData & /*sd*/, ClosureEmission /*emission*/)
177{
178 return {};
179}
181 ShadingData & /*sd*/,
182 ClosureTransparency /*transparency*/)
183{
184 return {};
185}
187 ShadingData & /*sd*/,
188 ClosureVolumeScatter /*volume_scatter*/)
189{
190 return {};
191}
193 ShadingData & /*sd*/,
194 ClosureVolumeAbsorption /*volume_absorption*/)
195{
196 return {};
197}
198Closure closure_eval(KernelGlobals & /*kg*/, ShadingData & /*sd*/, ClosureHair /*hair*/)
199{
200 return {};
201}
203 ShadingData & /*sd*/,
204 ClosureReflection /*reflection*/,
205 ClosureRefraction /*refraction*/)
206{
207 return {};
208}
210 ShadingData & /*sd*/,
211 ClosureDiffuse /*diffuse*/,
212 ClosureReflection /*reflection*/)
213{
214 return {};
215}
217 ShadingData & /*sd*/,
218 ClosureReflection /*reflection*/,
219 ClosureReflection /*coat*/)
220{
221 return {};
222}
224 ShadingData & /*sd*/,
225 ClosureVolumeScatter /*volume_scatter*/,
226 ClosureVolumeAbsorption /*volume_absorption*/,
227 ClosureEmission /*emission*/)
228{
229 return {};
230}
232 ShadingData & /*sd*/,
233 ClosureDiffuse /*diffuse*/,
234 ClosureReflection /*reflection*/,
235 ClosureReflection /*coat*/)
236{
237 return {};
238}
240 ShadingData & /*sd*/,
241 ClosureDiffuse /*diffuse*/,
242 ClosureReflection /*reflection*/,
243 ClosureReflection /*coat*/,
244 ClosureRefraction /*refraction*/)
245{
246 return {};
247}
248
250 ShadingData & /*sd*/,
251 Closure /*closure*/)
252{
253 return float4(0);
254}
255
256template<typename T> float3 F_brdf_single_scatter(float3 /*f0*/, float3 /*f90*/, T /*lut*/)
257{
258 return float3(0);
259}
260
261template<typename T> float3 F_brdf_multi_scatter(float3 /*f0*/, float3 /*f90*/, T /*lut*/)
262{
263 return float3(0);
264}
265
267 float3 /*F0*/,
268 float3 /*F82*/,
269 float /*cos_theta*/,
270 float /*roughness*/,
271 bool /*do_multiscatter*/,
272 float3 & /*reflectance*/)
273{
274}
275
276void bsdf_lut([[resource_table]] const KernelGlobals & /*kg*/,
277 float3 /*F0*/,
278 float3 /*F90*/,
279 float3 /*transmission_tint*/,
280 float /*cos_theta*/,
281 float /*roughness*/,
282 float /*ior*/,
283 bool /*do_multiscatter*/,
284 float3 & /*reflectance*/,
285 float3 & /*transmittance*/)
286{
287}
288
290 float /*cos_theta*/,
291 float /*roughness*/,
292 float /*ior*/,
293 bool /*do_multiscatter*/)
294{
295 return float2(0);
296}
297
299 float3 /*F0*/,
300 float3 /*F90*/,
301 float /*cos_theta*/,
302 float /*roughness*/,
303 bool /*do_multiscatter*/)
304{
305 return float3(0.0f);
306}
307
308float f0_from_ior(float /*eta*/)
309{
310 return 0.0f;
311}
312
313float F0_from_ior(float /*eta*/)
314{
315 return 0.0f;
316}
317
318/* Coordinates. */
319
320struct Coordinates {
325};
326
328 const ShadingData & /*sd*/,
329 float3 /*P*/,
330 float3 /*N*/)
331{
332 return {};
333}
334
335/* Ambient occlusion node. */
336
338 const ShadingData & /*sd*/,
339 float3 /*normal*/,
340 float /*max_distance*/,
341 float /*inverted*/,
342 float /*sample_count*/)
343{
344 return 0.0f;
345}
346
347/* Attribute node occlusion node. */
348
350{
351 return attr;
352}
354{
355 return attr;
356}
357
358/* TODO remove attr as parameter. */
360 const ShadingData & /*sd*/,
361 float4 /*attr*/,
362 uint /*attr_hash*/)
363{
364 return float4(0);
365}
367 const uint /*attr_hash*/)
368{
369 return float4(0);
370}
372 int /*light_index*/,
373 uint /*attr_hash*/)
374{
375 return float4(0);
376}
378 int /*light_index*/)
379{
380 return false;
381}
383 int /*light_index*/)
384{
385 return false;
386}
388 int /*light_index*/)
389{
390 return false;
391}
393 int /*light_index*/)
394{
395 return false;
396}
398 int /*light_index*/)
399{
400 return float(0);
401}
402
403/* Scene Time Node. */
404
406 float & /*seconds*/,
407 float & /*frame*/)
408{
409}
410
411/* Shadow Ray-cast Node. */
412
414 const ShadingData & /*sd*/,
415 int /*light_index*/,
416 float3 /*position*/,
417 float /*softness*/,
418 float4 & /*color*/)
419{
420}
421
422/* Light Accumulation Node. */
423
425 ShadingData & /*sd*/,
426 int /*light_index*/,
427 float3 /*diffuse_light*/,
428 float3 /*diffuse_color*/,
429 float3 /*glossy_light*/,
430 float3 /*glossy_color*/,
431 float3 /*transmission_light*/,
432 float3 /*transmission_color*/,
433 float /*weight*/,
434 Closure & /*result*/)
435{
436}
437
438/* Light Info Node. */
439
441 const int /*light_index*/,
442 float4 & /*color*/,
443 float & /*power*/,
444 float3 & /*position*/)
445{
446}
447
448/* Light Evaluation Node. */
449
451 int /*light_index*/,
452 float3 /*position*/,
453 float3 & /*direction*/,
454 float & /*distance*/,
455 float & /*mask*/)
456{
457}
458
459template<bool use_diffuse>
461 const ShadingData & /*sd*/,
462 int /*light_index*/,
463 float3 /*position*/,
464 float3 /*normal*/,
465 float /*roughness*/,
466 float & /*factor*/)
467{
468}
469
471 KernelGlobals &, const ShadingData &, int, float3, float3, float, float &);
473 KernelGlobals &, const ShadingData &, int, float3, float3, float, float &);
474
475/* Ray-cast Node. */
476
478 const ShadingData & /*sd*/,
479 float3 /*position*/,
480 float3 /*direction*/,
481 float /*max_distance*/,
482 bool /*self_only*/,
483 bool & /*is_hit*/,
484 bool & /*self_hit*/,
485 float & /*hit_distance*/,
486 float3 & /*hit_position*/,
487 float3 & /*hit_normal*/)
488{
489}
490
491/* Image Texture Node. */
492
494{
495 return 0.0;
496}
497
499{
500 return 1.0;
501}
502
503/* AOV Output. */
504
506 int2 /*texel*/,
507 float4 /*color*/,
508 float /*value*/,
509 uint /*hash*/,
510 float /*holdout*/,
511 eObjectInfoFlag /*ob_flag*/)
512{
513}
514
515/* Matrices. */
@ OBJECT_NO_INFO
@ OBJECT_SELECTED
@ OBJECT_FROM_DUPLI
@ OBJECT_ACTIVE
@ OBJECT_ACTIVE_EDIT_MODE
@ OBJECT_FROM_SET
@ OBJECT_HOLDOUT
@ OBJECT_NEGATIVE_SCALE
float4 node_attribute_light_impl(KernelGlobals &kg, const int light_index, uint attr_hash)
void output_aov(KernelGlobals &kg, int2 texel, float4 color, float value, uint hash, float holdout, eObjectInfoFlag ob_flag)
float4 attr_load_uniform(KernelGlobals &kg, const ShadingData &sd, float4, const uint attr_hash)
float attr_load_temperature_post(KernelGlobals &kg, float attr)
void raycast_eval(KernelGlobals &kg, const ShadingData &sd, float3 position, float3 direction, float max_distance, bool self_only, bool &is_hit, bool &self_hit, float &hit_distance, float3 &hit_position, float3 &hit_normal)
void scene_time_uniforms(KernelGlobals &kg, float &seconds, float &frame)
float texture_lod_bias_get(KernelGlobals &kg)
void node_shadow_raycast_impl(KernelGlobals &kg, const ShadingData &sd, const int light_index, float3 position, float softness, float4 &color)
Closure closure_mix(Closure, Closure, float)
bool node_attribute_light_is_sun_impl(KernelGlobals &kg, const int light_index)
bool node_attribute_light_is_point_impl(KernelGlobals &kg, const int light_index)
float derivative_scale_get(KernelGlobals &kg)
Closure closure_add(Closure, Closure)
bool node_attribute_light_is_spot_impl(KernelGlobals &kg, const int light_index)
void node_light_info_impl(KernelGlobals &kg, const int light_index, float4 &color, float &power, float3 &position)
float3 brdf_lut(KernelGlobals &kg, float3 F0, float3 F90, float cos_theta, float roughness, bool do_multiscatter)
float ambient_occlusion_eval(const KernelGlobals &kg, const ShadingData &sd, float3 normal, float max_distance, const float inverted, const float sample_count)
void node_light_evaluation_impl(KernelGlobals &kg, const ShadingData &sd, int light_index, float3 position, float3 normal, float roughness, float &factor)
float3 F_brdf_multi_scatter(float3 f0, float3 f90, T lut)
void node_light_evaluation_common_impl(KernelGlobals &kg, int light_index, float3 position, float3 &direction, float &distance, float &mask)
void bsdf_lut(KernelGlobals &kg, float3 F0, float3 F90, float3 transmission_tint, float cos_theta, float roughness, float ior, bool do_multiscatter, float3 &reflectance, float3 &transmittance)
bool node_attribute_light_is_area_impl(KernelGlobals &kg, const int light_index)
void brdf_f82_tint_lut(KernelGlobals &kg, float3 F0, float3 F82, float cos_theta, float roughness, bool do_multiscatter, float3 &reflectance)
void node_light_accumulation_impl(KernelGlobals &kg, ShadingData &sd, const int light_index, float3 diffuse_light, float3 diffuse_color, float3 glossy_light, float3 glossy_color, float3 transmission_light, float3 transmission_color, float weight, Closure &result)
float3 F_brdf_single_scatter(float3 f0, float3 f90, T lut)
float4 attr_load_color_post(KernelGlobals &kg, float4 attr)
float4 node_attribute_layer_impl(KernelGlobals &kg, const uint attr_hash)
float F0_from_ior(float eta)
Coordinates coordinate_impl(KernelGlobals &kg, const ShadingData &sd, float3 P, float3 N)
Closure closure_eval(KernelGlobals &kg, ShadingData &sd, ClosureDiffuse diffuse)
float4 closure_to_rgba(KernelGlobals &kg, ShadingData &sd, Closure cl)
float f0_from_ior(float eta)
float node_attribute_light_cutoff_distance_impl(KernelGlobals &kg, const int light_index)
#define front_facing
#define push_constant
#define resource_table
MatBase< 4, 4 > float4x4
unsigned int uchar
float2 packed_float2
VecBase< float, 4 > float4
VecBase< float, 3 > float3
#define N
#define T
unsigned int uint
Definition BKE_text.h:55
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ViewMatrices camera_matrices_get(const ShadingData &)
ViewMatrices view_matrices_get(const ShadingData &)
ObjectMatrices light_matrices_get(int)
ObjectMatrices object_matrices_get(const ShadingData &)
ObjectInfos object_infos_get(const ShadingData &)
enum eObjectInfoFlag flag
packed_float3 barycentric_dists
packed_float2 barycentric_coords
packed_float3 curve_N
packed_float3 curve_T
packed_float3 curve_B
packed_float3 point_position