Hi I am working on a card game and I am new to shaders.
I have a card which has Mana Cost, Name, Type, Description, etc. Some are text but parts of the art will change based on the type of card. Right now I just have each card component in different sprites with their position slightly higher than the order. This works for now, but to get effects like dissolving entire card I would need all the components onto 1 Mesh.
What I am wondering is if there is a way to just use shader code combined with a card script so that it writes each component’s textures onto the coordinates layered on top of each other instead of just using different sprites positioned on top of each other.
Is it possible to do all this in 1 pass? Can I do multiple vertex and fragment pragma in 1 pass or do I need a separate pass for each different texture I am overlaying onto the mesh?
That would be a way to do it, but it would be non-procedural and it would result in excess space. If you are referring to rendertexture, that is also a way I can go about this too. I am just wondering if there’s other ways.
After playing around with the shader code I found I can put multiple textures on top of each other in 1 pass. However, another problem I came across it, it stretches all textures to the size of the UV map. Is there a way to keep the size of textures relative to a reference texture (one texture which is the size of entire card, then all other texture sizes are relative to it)?
Right now I still think just superimposing each separate component of the card on different sprite layers is the best way to go about this.
When it comes to fill rate, which is mainly important on mobile platforms, composing the layers in the shader is the best way. The uv you use to sample the texture, is exactly that. But you can of course change that for each texture sample. It’s best to do this in the vertex shader to avoid dependent texture lookups.
Here’s another problem. My sprites are in an atlas. I played around with using shader to place textures ontop of each other and I see that I can adjust the scale and position of the textures but since my sprites are in an atlas I can only select the entire atlas as the texture instead of the sprite within the atlas. If I place the atlas ontop of a layer then it shows the other parts of the atlas and covers up what is beneath with the unwanted sprites of the atlas. In the image below I only want to show the left “pole” and not the other yellow stuff.
This is kind of why they’re not combined into a single shader to begin with, but it can be solved.
The short version is you’ll need another set of values for each texture to define the min-max UV area for each sprite and skip the lerp when outside the range.