Im learning shaders in Godot, and I need to read the value of a variable from a shader. I currently have a similar setup to the following:
shader_type canvas_item;
varying float value;
void fragment()
{
value = some_data;
}
Now, having a GDScript attached to the same Node, how can I read value?
Ive tried using custom Viewports and ComputeBuffers, but I cant get them to work.
What I am trying to do is to create a kind of like "light" shader, so that the alpha from each pixel decreases as the mouse gets further from that pixel. However, I wasnt able to get it to work, and so I was trying to print said distance from a GDScript, and that lead to this question. The following is my current attempt to that shader:
shader_type canvas_item;
uniform vec2 mousePos; //This variable is filled from another GDScript
uniform float lightRadius = 10.0;
void fragment() {
// Called for every pixel the material is visible on.
//COLOR = vec4(sin(UV.x), cos(UV.y), 0.0, 1.0);
COLOR = texture(TEXTURE, UV);
float dist = distance(mousePos, FRAGCOORD.xy);
COLOR.a = dist;
}
Since I couldnt get it to work, I was trying to print dist from another script.
Edit: explanation of my problem. Thanks in advance!
valuefrom the same logic ofsome_datain your script. If you elaborate more and provide details, we will be able to give a more precise solution to your issue.