tutorials/shaders/shader_reference/spatial_shader #218
Replies: 5 comments 2 replies
-
There's an issue with the if (false) {
ALPHA_SCISSOR_THRESHOLD = alpha_scissor_threshold;
} ...still activates the scissor threshold, despite there being nothing written to it. Same with |
Beta Was this translation helpful? Give feedback.
-
I spent a lot of time understanding the content related to VERTEX, NORMAL, TANGENT, BITANGENT, and POSITION. The following notes can help you save some time. Term explanation:
Main related variables:
Discussion: Note: MODELVIEW_MATRIX = MODEL_MATRIX * VIEW_MATRIX, where MODEL_MATRIX transforms model space to world space, and VIEW_MATRIX transforms world space to view space. Thus, MODELVIEW_MATRIX internally includes the transformation matrix from model space to world space. When the world_vertex_coords mode is enabled, VERTEX is automatically transformed to world space coordinates using MODEL_MATRIX before the vertex function is executed. Between the vertex and fragment functions, the calculation process for POSITION's NDC value changes: the VERTEX value is extracted, transformed from [world space] to [view space] using VIEW_MATRIX, then to [clip space] using PROJECTION_MATRIX, and finally to [NDC] through perspective division. The VERTEX variable passed to the fragment function remains in world space coordinates. When the skip_vertex_transform mode is enabled, the automatic transformation of VERTEX from model space to view space is disabled. The world_vertex_coords mode handles the transformation of VERTEX from model space to view space, so it may not be usable (unverified). Users need to manually calculate the VERTEX value transformed to [view space] and assign it to VERTEX before the end of the vertex function. Between the vertex and fragment functions, the calculation process for POSITION's NDC value changes: the VERTEX value is extracted, transformed to [clip space] using PROJECTION_MATRIX, and then to [NDC] through perspective division. The VERTEX variable passed to the fragment function remains in view space coordinates. If the POSITION variable is manually written in the vertex function, Godot assumes that POSITION has already obtained the correct clip space data. Between the vertex and fragment functions, the calculation process for POSITION's NDC value is no longer based on extracting and computing the VERTEX value. Instead, it becomes: extracting the POSITION value and transforming it to [NDC] through perspective division. The VERTEX variable passed to the fragment function remains the same data as at the end of the vertex function. |
Beta Was this translation helpful? Give feedback.
-
I found this cheet sheet recently that is very useful: |
Beta Was this translation helpful? Give feedback.
-
For example, if you need the position of the model in world coordinates: varying vec3 model_position;
void vertex() {
// Position of the model in world coordinates.
model_position = (MODEL_MATRIX * vec4(0.0, 0.0, 0.0, 1.0)).xyz;
}
void fragment() {
// Use model_position here
} |
Beta Was this translation helpful? Give feedback.
-
Note that there is an additional |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
tutorials/shaders/shader_reference/spatial_shader
Spatial shaders are used for shading 3D objects. They are the most complex type of shader Godot offers. Spatial shaders are highly configurable with different render modes and different rendering o...
https://docs.godotengine.org/en/stable/tutorials/shaders/shader_reference/spatial_shader.html
Beta Was this translation helpful? Give feedback.
All reactions