is it possible to set variable inside shader ONCE ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Inces

Hello,

I am trying to figure out shaders lately.
I tried to alter the direction of particles stream every time it restarts. I tried to set one random number to be shared by all particles. I failed, because other than in UNIFORM, there is no place to introduce variable, where it won’t be changed every frame, for every pixel, for every vertex. Like this pseudocode :

void vertex() {

uint simp_seed = uint(7);
    if RESTART : {
     VELOCITY.x  = rand_from_seed(simp_seed) }}

I want all individual particles to share one random velocity.x, but every individual particle runs its own vertex function randomizing its velocity anew. How and where should I introduce variable in shader, so I can set it unified for all instances ? Is uniform the only way ?

I run into similar problem with canvas_item shader. I wanted to set COLOR to SCREEN_TEXTURE when sin(TIME) was above 0.5, and at other times, set COLOR to another variable that was supposed to hold current screen color in frozen state. But because of shaders logic, COLOR,variables and screen_texture were being updated at all times, it was impossible to keep frozen COLOR like in print screen.

   
:bust_in_silhouette: Reply From: klaas

Hi
godot does not suport transform feedback shader.

Cant you just set a uniform random number from a gd script? This would be shader-wide … and for every particle/vertex the same.

I know uniforms are the way to deal with it. I am just afraid this problem with random particle stream is just a trailer of more problems related to value setting unelasticity. I am very sorry to hear that there is no other way.

Inces | 2021-09-22 18:46

I actually managed to do it :slight_smile:

It is possible to set value at the start of particle creation, by defining it right after the start of if (RESTART ) {
One random number can also be generated, if seed is introduced in this place.

Inces | 2021-09-27 14:46