@@ -377,3 +377,62 @@ shaders.
377
377
GPU separately, which lets you compare how a similar algorithm can be
378
378
implemented in two different ways (with the GPU implementation being faster
379
379
in most cases).
380
+
381
+ Includes Database
382
+ -----------------
383
+ .. warning ::
384
+
385
+ The feature is experimental.
386
+
387
+ Godot provides some shader includes through ``ShaderIncludeDB `` class. Include
388
+ operation is done automatically by Godot. They are **not ** files in our
389
+ system.
390
+
391
+ To see what headers are available, use ``ShaderIncludeDB.list_built_in_include_files ``
392
+ . The source code of these files can be found in Godot's Git repository.
393
+
394
+ The example below includes "godot/scene_data_inc.glsl" which defines ``SceneData ``
395
+ structure. Uniform ``SceneDataBlock `` corresponce to buffer got from
396
+ ``p_render_data.get_render_scene_data() ``. Shader uses ``time `` in ``SceneData ``
397
+ to create ``CompositorEffect `` that colours the screens with changing shades.
398
+ Include needs ``MAX_VIEWS `` to be defined.
399
+
400
+ .. code-block :: glsl
401
+
402
+ #[compute]
403
+ #version 450
404
+
405
+ #define MAX_VIEWS 2
406
+ #include "godot/scene_data_inc.glsl"
407
+
408
+ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
409
+
410
+ layout(set = 0, binding = 0, std140) uniform SceneDataBlock {
411
+ SceneData data;
412
+ SceneData prev_data;
413
+ } scene_data_block;
414
+
415
+ layout(rgba16f, set = 0, binding = 1) uniform image2D color_image;
416
+
417
+ void main(){
418
+ ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
419
+
420
+ vec4 color = imageLoad(color_image, uv);
421
+
422
+ color.x = sin(scene_data_block.data.time) / 2 + 0.5;
423
+ color.y = 0.5 - cos(scene_data_block.prev_data.time) / 4;
424
+
425
+ imageStore(color_image, uv, color);
426
+ }
427
+
428
+ In ``_render_callback `` you can bind scene data to a uniform.
429
+
430
+ .. tabs ::
431
+ .. code-tab :: gdscript GDScript
432
+
433
+ var scene_data_buffers = p_render_data.get_render_scene_data().get_uniform_buffer();
434
+ var uniform = RDUniform.new()
435
+ uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_UNIFORM_BUFFER;
436
+ uniform.binding = 0;
437
+ uniform.add_id(scene_data_buffers);
438
+
0 commit comments