+27
Completed

How to create a Sprites-Default shader?

Janaka Prasad 4 years ago • updated by Shadi Muklashy 2 years ago 30
I am making 2D game and I would like to modify some of shaders of the sprites. I noticed that I can’t open Sprites-Default shader used by sprite renderer using shader forge without losing all the data.

Is there a compatible shader I can use for this, with can be modified with shader forge?

Answer

+2
Answer
Completed
This has now been added in Shader Forge 1.14 :)
+5
Under review
Right, this is something I've considered doing, but haven't because nobody has requested it before. I do have a reason now though :)
+3
+1 for the Sprite Shaders capability! ^^
+1
How is it going? Any progress with this feature?
Not yet, my schedule is unfortunately completely full until after GDC
I'm waiting for this before I purchase your tool. You have good reviews from the Krillbite guys.
+1
I've been trying to make a sprite shader that observes the sortingLayer property, but am having trouble.
+3
I'll look into this in the coming week - seems like it's one of the more commonly requested features now :)
Excellent, thanks for all your hard work Joachim!
Thank you sir! All flash deserters depend on you now :D
+1
Oh dear. I'll need to make a vector graphics plugin soon then
+2
Answer
Completed
This has now been added in Shader Forge 1.14 :)
For the record - the sprites shader has nothing special, apart from the pixel snap toggle.
You can create a sprite shader in 1.13 too :)
Hello, I was very much hoping you could add sprite support for the Unity4 version of shaderforge. We are locked into using Unity4, and love shader forge, but can't use the latest version because its not supported for our version of Unity. Any possibility of a quick fix for this? Thank you so much advance!
Here's the closest you can get using SF 1.13 or earlier, in both Unity 4 and 5:
  • Set lighting to unlit
  • Set face culling to double-sided
  • Set the blending mode to Pre-multiplied alpha blending (Source * One + Destination * OneMinusSrcAlpha)
  • Disable fog
  • Replicate this node tree below, using the exact same property names



Hope it helps :)
Would there be a way to replicate the built in UI Sprite? This would support the UI sorting / z ordering, as well as UI masking, etc.
I think, though I'm not sure, they are using the same shader. Try the stuff I wrote above :)
I tried using the generated shader forge sprite shader (I called it Uber Shader here), and adding it to a game object with an Image and Mask component, and I get the following errors:



It looks like Unity has posted a roadmap, and I noticed this as the last feature planned to make it into 5.2:

  • 2D rectangle mask clipping that does not use stencil buffer.
So it looks like maybe the way masking works in the UI will change to not require the stencil buffer, and then maybe a shader forge sprite shader will work with masking in the UI? Hopefully!
If I add these changes to a shader produced by Shader Forge, the shader will work with UI masking. Unfortunately these get cleared out whenever editing the shader:

Properties    {
        ...

        _StencilComp ("Stencil Comparison", Float) = 8
        _Stencil ("Stencil ID", Float) = 0
        _StencilOp ("Stencil Operation", Float) = 0
        _StencilWriteMask ("Stencil Write Mask", Float) = 255
        _StencilReadMask ("Stencil Read Mask", Float) = 255

        ...
}

SubShader    {
        ...
        
        Stencil
        {
            Ref [_Stencil]
            Comp [_StencilComp]
            Pass [_StencilOp] 
            ReadMask [_StencilReadMask]
            WriteMask [_StencilWriteMask]
        }
        
        ...
}

+1
Oh, that's super useful, thanks! I'll implement this in the next update of SF :)
Hooray! I just grabbed that from the source of the stock UI Default shader, if you want to use that as reference.
Grabbed 1.18, and I see the stencil options, but I'm not sure how to get it to work with the Unity UI. The UI still complains about the shader missing stencil properties, etc.
Yeah, I didn't have the time to implement the UI specific properties for it. It had more implications than I thought at first, I need to customize the interface and modify the property system to make it work like this.
Sorry that it didn't come with 1.18, I'll definitely add it for 1.19