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