Particles: How to pass variables from ProcessMaterial code to "pass 1 ShaderMaterial" code?

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

hi again,

how to pass variables in shader code?

In the particles-code I set my CUSTOM.x parameter:

shader_type particles;

void vertex() {
	if (RESTART) {
		CUSTOM.x = 0.9;
		COLOR = vec4(0.1,0.2,0.3,0.4);
	} else {
	}
}

How to pass this to the pass MaterialShader code:

shader_type spatial; // ShaderMaterial code

void vertex(){
	float c = CUSTOM.x; // doesn't work
	float c = INSTANCE_CUSTOM.x; // also doesn't work
	float my_x = COLOR.x; // works
}

void fragment() {
	ALBEDO = COLOR.rgb;
}

Any ideas?

Thanks

Mike

P.S.: COLOR is passed from the particles code to pass MaterialShader code, but COLOR gives me only 4 floats, I need more variables.

:bust_in_silhouette: Reply From: Inces
float c = INSTANCE_CUSTOM.x

This does work. However You set CUSTOM.x in shader particle right on particle restart. Did You remember default particle shader sets CUSTOM.xyz in code under it ? I guess your custom variable is overriden be default values. Find CUSTOM.x in default shader code and comment out the line where it is set.

Hi @Inces,

I am confused, I didn’t get INSTANCE_CUSTOM.x to work. Now this seams to work. I have to dig more.

Thanks

Mike

MikeMikeMike | 2022-02-12 17:37