I know apparently some things changed with shaders in 5, like compiling to hlsl or glsl or something automatically? I wonder if that switch-over has produced some new bugs.
Blending can be different for each pass of the shader. It is therefore supposed to go inside the Pass block. The same actually goes for some other settings. In the past it also worked if set in the Subshader block, but they might have cleaned this up. That could be why it’s ignored in the shader above.
Damn, sir Jonny Roy, I want that brain of yours. Works fine. Where do you think the code is unoptimised? I may try to find someone else to help me with optimising this, since I don’t wanna waste your time. Just this is a huge help, thank you so much!
Anyway this is my first post I wanted to say that I had a shader problem (I’m not a good shader writer) but I just wanted to share some knowledge if someone had the same problem with the shaders
I changed all these things and my shader started to work again.
OLD: #pragma surface surf Lambert
NEW: #pragma surface surf Standard fullforwardshadows
OLD: void surf(Input IN, inout SurfaceOutput o) {
NEW: void surf (Input IN, inout SurfaceOutputStandard o) {
I am running into the same issues trying to rewrite a shader I’ve written for Unity 4, blending seems broken.
We wanted a splatmap shader that allowed for more than 4 textures, so after attempting arcane magic with packing floats into RGBA in order to do 8 or more textures I ended up simply layering materials. A simple One OneMinusSrcAlpha blend used to do the trick but in Unity 5 I’m completely at a loss. The blend mode simply doesn’t seem to work, and any other blendmode makes my terrain see-through.
I’m trying to adapt the Terrain shader from the Viking demo here; but I can neither get the blending to work as described above and my shadows receiving seem to be broken.
If anyone can help that would be greatly appreciated.
Hey Jonny Roy, thanks so much for helping everyone out! That’s so amazing of you given shader programming’s high barrier of entry. A friend of mine recently gave me some shader code and like everyone else, every object with the shader turns black on builds. Could you take a look at mine? It gets errors like
“Program ‘frag_surf’, error X4506: ps_4_0_level_9_1 input limit (8) exceeded, shader uses 9 inputs.
Compiling Fragment program with DIRECTIONAL SHADOWS_SCREEN SHADOWS_NATIVE LIGHTMAP_OFF DIRLIGHTMAP_OFF DYNAMICLIGHTMAP_OFF FOG_LINEAR”
and
“Too many math instructions for SM2.0 (66 needed, max is 64). Try #pragma target 3.0
Compiling Fragment program with DIRECTIONAL SHADOWS_OFF LIGHTMAP_OFF DIRLIGHTMAP_OFF DYNAMICLIGHTMAP_OFF FOG_LINEAR”
With shader code the parts in the frag function basically get called for every pixel and so need to be as efficient as possible, “if” statements are one of the slowest functions you can call, so should be avoided, basically replace the above with this:
Basically with if, the shader runs both bits of code every time, then decides which value to go with after it evaluates the if, it’s just because they batch process multiple pixels at one, I’ve changed this to use the step command which basically compares the first value to the second and return 0 if the second is greater than or equal to the second otherwise 1 (which is why I did 1 - the step), it should give the same result and be quite a bit faster.
I’d need more of a repro showing the issue with this as it’s a little more complex and specific, if you can upload a simple sample project I’ll see what I can do.
No problem Kiron, out of interest are you targeting windows store with this? Or just iOS, android? It’s a slightly trickier one to fix this one, but depending on what your targeting depends on how easy the fix is!
Well, we are targeting the Steam platform at the moment, but in the future we’re looking to do iOS and Android. It would be great if you can just help us out with a PC solution and we’ll worry about mobile later.
Thanks so much for helping!
And just curious, do you recommend any tutorials/learning resources for starting to program shaders for Unity? It seems to be a very uncommonly educated topic in programming, like specific knowledge for triple A studios