Hi, I have a simple shader from the internet which works good in the editor (Unity 2017), but not really in a build. It is a simple dissolve shader:
Shader "Custom/Dissolve" {
Properties{
_Color("Color", Color) = (1,1,1)
_SliceGuide("Slice Guide (RGB)", 2D) = "white" {}
_SliceAmount("Slice Amount", Range(0.0, 1.0)) = 0.5
}
SubShader{
Tags{ "RenderType" = "Opaque" }
Cull Off
CGPROGRAM
#pragma surface surf Lambert addshadow
struct Input {
float2 uv_MainTex;
float2 uv_SliceGuide;
float _SliceAmount;
};
float4 _Color;
sampler2D _SliceGuide;
float _SliceAmount;
void surf(Input IN, inout SurfaceOutput o) {
clip(tex2D(_SliceGuide, IN.uv_SliceGuide).rgb - _SliceAmount);
o.Albedo = _Color;
}
ENDCG
}
Fallback "Diffuse"
}
I run it from my code like this (I dont think this is the problem, it runs fine in the editor and the debug log is perfect in the build):
IEnumerator BlinkCo()
{
Blinking = true;
rising = true;
ChangeShader(BlinkingShader); // the dissolve shader
yield return new WaitForSeconds(sc.Stats.BlinkDuration / 2);
ChangePos();
rising = false;
yield return new WaitForSeconds(sc.Stats.BlinkDuration / 2);
ChangeShader(NormalShader); // the standard shader
Blinking = false;
currentDissolve = 0;
}
private void Update()
{
if (Blinking)
{
ChangeDissolve(rising ? Time.deltaTime * 15 : -Time.deltaTime * 15);
}
}
string prop = "_SliceAmount";
private void ChangeDissolve(float delta)
{
currentDissolve += delta;
currentDissolve = currentDissolve < 0 ? 0 : currentDissolve;
currentDissolve = currentDissolve > 1 ? 1 : currentDissolve;
for (int i = 0; i < meshes.Length; i++)
{
for (int j = 0; j < meshes[i].materials.Length; j++)
{
meshes[i].materials[j].SetFloat(prop, currentDissolve);
Debug.Log(meshes[i].materials[j].GetFloat(prop));
}
}
}
void ChangeShader(Shader shad)
{
for (int i = 0; i < meshes.Length; i++)
{
for (int j = 0; j < meshes[i].materials.Length; j++)
{
meshes[i].materials[j].shader = shad;
}
}
}
}
In the editor, the shader changes when you blink, it dissolves, you change position and it fades in again. But in a windows build I can only see the shaders switch, but there is no dissolve. I added the shader to resources and also into the “always include shader” in the graphic options. What is wrong with the shader, that it only runs correctly in the editor? Thanks for your help, much appreciated! (The debug log shows the correct values in the build, but it doesnt dissolve)