canslp
May 16, 2024, 12:33am
1
Godot Version
4.2.1
Question
In spatial shaders, I’ve been using VERTEX and some matrix multiplications to get the position of the fragment pixel. In the light function, I don’t have access to VERTEX. How can I get the worldspace coordinate in the ‘light’ function?
There is a light vertex in the unreleased Godot 4.3
godotengine:master
← basicer:light_vertex
opened 06:07AM - 25 Apr 24 UTC
Supersedes #90881
See also https://github.com/godotengine/godot-proposals/i… ssues/1942 , #65307 , #90115
After a good discussion in the weekly rendering meeting with @clayjohn and @BastiaanOlij the consensus was that adding a new variable for the position to use for lighting calculations was the best way to solve this class of problems.
Reconstructing the vertex from the depth buffer might not always be what the user wants, is slightly incorrect in the multi-view case, and is redundant when the shader likely already has that value available.
Making the VERTEX variable writable was considered, however there was concern user's would think writing this would change the visual appearance of the fragment.
_bugsquad edit: Closes https://github.com/godotengine/godot-proposals/issues/974; Closes https://github.com/godotengine/godot-proposals/issues/1942; Supersedes https://github.com/godotengine/godot/pull/65307; Supersedes https://github.com/godotengine/godot/pull/90115_
1 Like
oh, that’s perfect. though i guess that means there’s no way to access it until 4.3 then, right?
You can download the dev release.
btw there is also the varying keyword if you want to try and pass the vertex down to the light function.
shader_type spatial;
varying vec3 some_color;
void vertex() {
some_color = NORMAL; // Make the normal the color.
}
void fragment() {
ALBEDO = some_color;
}
void light() {
DIFFUSE_LIGHT = some_color * 100; // optionally
}
1 Like
canslp
May 16, 2024, 12:49pm
6
oh that’s interesting, does the ‘varying’ key word just create a persistent variable?
I think so, there is a concept on GPUs called work groups. So in theory that variable should be shared only within the workgroup. And it should all align to a single pixel, or group of pixels? Don’t quote me on that I’m still learning.
I saw it in the docs here.
I guess pixels and fragments.
1 Like
okay this totally worked thanks
system
Closed
June 16, 2024, 1:39am
9
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.