How can i get the pixel position in a light shader?

Godot Version



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

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

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