Godot Version
4.3
Question
I’m trying to learn to use shaders for the first time and I have the effect I want. A sort of random spiral that changes colour over time and it looks okay, but I’ve attached it to an area 2D in its node then tried to put it into my game and the spiral just occurs at the origin of the level rather than where I place the scene. Is there a way to pass the global position of the node to the shader language to add onto the transform or something.
I’ve attached the code I tried below:
Shader Material:
// Code above sets CUSTOM. xy to a random number based of the particles seed and applies an initial movement in the corresponding random direction
void process() {
float elapsedTime = TIME - CUSTOM.w;
// Spiral movement
float speed = 1.0; // Speed of outward movement
float spiral_strength = 2.0 - abs(CUSTOM.y * CUSTOM.x / 15.0) * elapsedTime; // How tight the spiral is spinning
float spiral_growth = 1.0; // How fast the spiral expands
// Calculate the angle based on time
float angle = PI * (CUSTOM.x + CUSTOM.y) + spiral_strength * elapsedTime;
// Calculate distance from the center based on time
float centerDistance = speed * pow(elapsedTime, spiral_growth);
// Update particle position based on angle and distance
vec2 local_position = vec2(cos(angle), sin(angle)) * centerDistance;
// Set the particle position by adding the origin
TRANSFORM[3].xy = origin + local_position;
// Code below changed the colour of the spiral over time
I tried to pass the origin variable as a uniform vec2 from a GD script attached to the area 2D parent but couldn’t get it to work. has anyone had experience with this before?
I would really appreciate the help.