Shader Forge Unity, Problems with android [Solution]

unity3d
shaders
unity

#1

Hi I’m Diego Mieles and if you have problems with the Android exportation of you shaderForge shader, try this, maeby will help you.

i had a free day today and i just tried to solve this problem.
alert (pls sorry for my english i’m learning)
So, the first that i did was see my lasts shader files that i did when i was learning, and i saw that the shaderForge’s shader are too long, maeby some shader expert could slap me the face , but i just started to delete all that “extra” code, obviously testing with every single line code that i deleted.
The first part was this section (ShadowCaster):


Yeah maeby it’s an important part of the code, but, honestly, i don’t need the best Shadows for my material in an Android game, so… bye bye.

The second Part, was this another section (ForwardDelta):


Uh… I don’t know what´s that but… the shader still working Exactly as the begin without this, so… ejem , bye bye.

And Finally, the last par. Here, I only kept the first part of the code, and it looks like this



It works in PC but it still did not working in Android, so i erased this lines code:

and EUREKA the shader was working in my phone and even with all this changes in the code, it looks like it was looking before.
here is my test shader in shaderForge:

And here is the shader Working in my Android Phone.

As you can see, i tested with Vertex offset, emmision, opacity and diffuse, the most important for me.
I hope that this could help you ;:slight_smile: i had this problem for one year and i didn’t found any solution.

WARNING: if you open the shader with ShaderForge Again, it just Compile the code as in the begin


#2

I haven’t been in ShaderForge in a minute but there are things you can turn on/off under your lighting/blending/experimental tabs that can stop some of that stuff from compiling every time. You can shut off support for fog/ lightmaps, and other things you might not want. Make your lighting single-pass instead of multi-pass. Turn off force target shader model 2.0 etc.


#3

Hi Ryan, that’s true i forgot Turn off the force Target shader 2.0, but believe me, before that, i tried too many ways to make it compatible with Android, but it wasn’t working (without touch the code).
that’s because ShaderForge Compile Code lines that isn’t compatible with Android, even without the experimental tabs and stuff.
(but well :s i’m a noob in this, i will try unable all this tabs that i will not use in the shader)


#4

All my Shader Forge shaders created in Unity 2017.x in the past have compiled to multiple platforms without any issues.

I agree there’s some trash generated in the Shader Forge files that you can safely delete without any visual changes but generally it haven’t created any measurable performance gains for me so I usually leave them in.

If you deselect all Target Platforms in the ShaderForge asset before compiling it, it will compile the shader to all platforms. Effectively removing the line that you removed:
image
Warning though: the Shader Forge editor will tick a few boxes by default once you open the shader again

After some googling, I would have tried to use #pragma only_renderers gles3 to see if that fixes your Android problem but that’s only a speculation from me.

Quick tip: Excluding platforms does not increase performance of the shader, it only reduce shader compilation time


#5

hey thanks! as i said all that i did, i was doing without knownness, I’ll use your trick