I'm porting a game from iOS / Obj-C / OpenGL ES 2.0 to Unity.
I have a procedural mesh script that generates a batch of quads that need to blend together to create a game board. Some of the quads add a highlight effect, others on top of those darken the scene. This is handled with the blend mode and the color of the object.
In the old version I did things inefficiently and just drew each quad individually, as needed setting the blend mode (glBlendFunc) and a color uniform. I batched similar things as I could.
In Unity3D rather than having 500 sprite gameObjects which IMO would be difficult to manage. I have one gameObject with a mesh = one draw call. I use per vertex color attribute instead of a uniform to set colors for each quad/sprite. But I want to also set the blend mode per quad by using vertex data. I'm sending the blend mode as uv2 data.
I found this question. See the second answer: http://answers.unity3d.com/questions/399074/change-blend-mode-from-outside-shader.html
Which says you can do this:
Pass {
Blend [MySrcMode] [MyDstMode]
}
But in the example MySrcMode
and MyDstMode
are shader properties (uniforms) and again would set the blend mode for the entire draw call. I want to change it per quad which would have to be done per fragment.
I understand GLSL shaders. They make sense to me. But Unity shaders are still a bit mysterious. The unity docs aren't getting through to me and I can't find any good tutorials on really how they work and what gets called in what order. I tried:
Blend [texcoord1.x] [texcoord1.y]
But that didn't work. (Meaning that it's not getting a value for texcoord1 there.) My Blend
is above the Pass{}
. Moving it inside the Pass
either is the same or produces an error depending where it goes.
My other option would be to do something like a gl_LastFragData
to fetch the current fragment and do my own per fragment blending.
Or do I have to pull out the quads that use a different blending into another game object. Which would mean having geometry sorted into game objects based on their blending mode and not their behavior or the script that creates and manages them.