-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Documentation for shader built-in include files (godotengine/godot#94193) #10703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -377,3 +377,81 @@ shaders. | |||||||||||||||
GPU separately, which lets you compare how a similar algorithm can be | ||||||||||||||||
implemented in two different ways (with the GPU implementation being faster | ||||||||||||||||
in most cases). | ||||||||||||||||
|
||||||||||||||||
Includes Database | ||||||||||||||||
----------------- | ||||||||||||||||
.. warning:: | ||||||||||||||||
|
||||||||||||||||
The feature is experimental. | ||||||||||||||||
|
||||||||||||||||
Godot provides some shader includes through ``ShaderIncludeDB`` class. Include | ||||||||||||||||
operation is done automatically by Godot. Shader includes are **not** files in | ||||||||||||||||
our system. | ||||||||||||||||
|
||||||||||||||||
To see what headers are available, use | ||||||||||||||||
``ShaderIncludeDB.list_built_in_include_files``. The contents of these files | ||||||||||||||||
can be found in Godot's Git repository or by calling | ||||||||||||||||
``ShaderIncludeDB.get_built_in_include_file``. | ||||||||||||||||
|
||||||||||||||||
The example below renders a transparent pulsating circle at the centre of the | ||||||||||||||||
screen. The corners of the screen are coloured fully white. The edge of the | ||||||||||||||||
Comment on lines
+396
to
+397
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Please use US English |
||||||||||||||||
circle is smoothed. | ||||||||||||||||
|
||||||||||||||||
.. code-block:: glsl | ||||||||||||||||
#[compute] | ||||||||||||||||
#version 450 | ||||||||||||||||
#define MAX_VIEWS 2 | ||||||||||||||||
#include "godot/scene_data_inc.glsl" | ||||||||||||||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; | ||||||||||||||||
layout(set = 0, binding = 0, std140) uniform SceneDataBlock { | ||||||||||||||||
SceneData data; | ||||||||||||||||
SceneData prev_data; | ||||||||||||||||
} scene_data_block; | ||||||||||||||||
layout(rgba16f, set = 0, binding = 1) uniform image2D screen; | ||||||||||||||||
void main(){ | ||||||||||||||||
ivec2 uv = ivec2(gl_GlobalInvocationID.xy); | ||||||||||||||||
vec4 color = imageLoad(screen, uv); | ||||||||||||||||
// Check UV is in the view. | ||||||||||||||||
if (uv.x >= scene_data_block.data.viewport_size.x || uv.y >= scene_data_block.data.viewport_size.y) { | ||||||||||||||||
return; | ||||||||||||||||
} | ||||||||||||||||
float maxlen = max(scene_data_block.data.viewport_size.x, scene_data_block.data.viewport_size.y); | ||||||||||||||||
vec2 center = vec2(scene_data_block.data.viewport_size.x / 2, scene_data_block.data.viewport_size.y / 2); | ||||||||||||||||
float r = length(abs(center - uv)); | ||||||||||||||||
float alpha = smoothstep(maxlen * (0.55 + 0.3 * sin(scene_data_block.data.time)), maxlen * (0.2 + 0.2 * sin(scene_data_block.data.time)), r); | ||||||||||||||||
// Calculate blend between full white and image's current color. | ||||||||||||||||
color = (1 - alpha) * vec4(1, 1, 1, 1) + alpha * color; | ||||||||||||||||
imageStore(screen, uv, color); | ||||||||||||||||
} | ||||||||||||||||
Comment on lines
+400
to
+436
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indentation here needs to be fixed to match the rest of the document, four spaces |
||||||||||||||||
The example includes ``godot/scene_data_inc.glsl``, which defines ``SceneData`` | ||||||||||||||||
data structure. ``SceneData`` needs ``MAX_VIEWS`` for some of its' members. | ||||||||||||||||
Uniform ``SceneDataBlock`` correspondence to buffer got from | ||||||||||||||||
Comment on lines
+438
to
+440
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
``p_render_data.get_render_scene_data()``. In ``_render_callback``, you can | ||||||||||||||||
bind scene data to a uniform. | ||||||||||||||||
|
||||||||||||||||
.. tabs:: | ||||||||||||||||
.. code-tab:: gdscript GDScript | ||||||||||||||||
|
||||||||||||||||
var scene_data_buffers = p_render_data.get_render_scene_data().get_uniform_buffer(); | ||||||||||||||||
var uniform = RDUniform.new() | ||||||||||||||||
uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_UNIFORM_BUFFER; | ||||||||||||||||
uniform.binding = 0; | ||||||||||||||||
uniform.add_id(scene_data_buffers); | ||||||||||||||||
|
||||||||||||||||
Shader uses ``SceneDataBlock.data`` members ``viewport_size`` and ``time`` | ||||||||||||||||
counter. Member ``viewport`` is currently the viewport's size. It is used to | ||||||||||||||||
calculate the centre of the screen. Counter ``time`` is an analogue of time | ||||||||||||||||
since the start of the game. It is used to make pulsating animation. | ||||||||||||||||
Comment on lines
+453
to
+456
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.