• Runtimes
  • Allegorithmic substance and spine2d

Ok, so, first of all, what is allegorithmic substance?
Google it, it's the tool you should check if you're in the texturing business, it applies mostly to 3D, but I'm in a 2D project that actually has some use for it, we're using it for customizations and basically lowering app size (which is mostly about having less textures or optimizing them).

Basically what it does is generate textures at runtime based on a node based graph that uses filters and.... well... it makes a bunch of stuff that you usually do in photoshop but in a way that can at any point of the process be changed by a coder(even in runtime).
An use case (my situation) could be having only one atlas but several cutomizations added to it through substance designer... It's really useful, if we weren't using it it would take several versions of each sprite and that leads to bigger textures and bigger app size.

So the problem here is that since substance generates textures/materials on the fly, the atlas/skeleton system of the spine runtime seems to have a problem with that, only thing I know is that the material used in a spine atlas kind of needs the main texture to be "static", which leads to getting the well known pink "I got a shader problem" texture when trying to use spine and substance out of the box.

The solution I found so far was to write a simple shader with two textures and basically fool spine with a normal texture as the _MainTexture and actually render the second texture which is the one generated by substance.

Too long of a post, I'm sharing the shader here, t has worked for me on runtime in the editor, will be testing on device soon and sharing results, if you find other alternatives let me know cause this is hacky as hell.

Shader "Custom/SubstanceSpine" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_SubsGenTex ("Substance Generated Texture (RGBA)", 2D) = "white" {}

}
SubShader {
Tags { "Queue"="Transparent" }
LOD 200

Cull Off
ZWrite On
Blend One OneMinusSrcAlpha
Lighting Off
      CGPROGRAM
      #pragma surface surf Lambert alpha
       
sampler2D _SubsGenTex; struct Input { float2 uv_SubsGenTex; }; void surf (Input IN, inout SurfaceOutput o) { half4 c = tex2D (_SubsGenTex, IN.uv_SubsGenTex); o.Albedo = c.rgb; o.Emission = c.rgb; o.Alpha = c.a; } ENDCG } FallBack "Transparent" }
Related Discussions
...

Thank's for sharing! Unfortunately I know absolutely nothing about the subject, but I'm sure others can use the information and maybe will also know a less hacky way of doing something similar 😃

I placed your code in some "code" tags to make it a little more readable 🙂