#Shader Usage

1 messages · Page 1 of 1 (latest)

sly heath
#

I am rendering a bunch of small sprites and using a shader to pick and replace its pallette in code, but it looks like each Sprite2D will need its own ShaderMaterial, is this intended or is it overkill and I'm missing something?

More details: I have a 24 x 24 grid of parts, and each part has some colors that need to be dynamically replaced to match data internal to each part every frame. I did this in GameMaker studio with a single shader and changed the shader's variables in the draw method of each object, but since I am not in control of the _draw method for Sprite2D by default this is not possible. Thoughts?

left wing
#

Sounds like you could use a CanvasGroup. Basically, it will render all child nodes of the canvasgroup in one pass. Importantly, this pass is sampleable from the canvasgroup itself. this means you can have the shader material on the canvasgroup and it will apply to the whole group. there may be difficulty if your shaders are dependent on ordering as the canvasgroup renders all its nodes at the same time so its good to look this option up before trying it.

sly heath
#

that's interesting, but I'm not exactly sure how I can use that to give the single shader a uniform which corresponds to each part separately and have it draw each part when it has the right value.

#

I think the idea of giving the shader a few Sample2D which holds the correct color data, along with grid position data, seems like the most straightforward

left wing
#

what uniform do you need for each node?

sly heath
#

each node has a separate color pallette (3 RGB values) which need to be applied to a sprite

#

the nodes are stored with position data in a 24 x 24 grid which is controlled by a parent node

left wing
#

Ah that would require independent rendering so you would probably need to use seperate shader materials

#

As far as I can tell, this is pretty normal to use this many materials

sly heath
#

ok! I will try both methods. thanks for your help!