- Home /
This question was
closed Apr 10, 2017 at 07:17 AM by
ricknice for the following reason:
The question is answered, right answer was accepted
Question by
ricknice · Apr 07, 2017 at 03:02 PM ·
shadercrashlerpshader programming
Unity crashes when trying to run depth shader with color lerp.
I'm building a little custom shader that uses the z-depth value as T for a color lerp. So the result should be that instead of a black and white depth view. I can have the colors be red and green (for example).
Properties {
_minColor ("Min Black", Float) = 0.0
_maxColor ("Max Black", Float) = 1.0
_Color1 ("Some Color", Color) = (0,0,0,1)
_Color2 ("Some Color", Color) = (1,1,1,1)
}
SubShader {
Tags { "RenderType"="Opaque" }
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D_float _CameraDepthTexture;
fixed _minColor;
fixed _maxColor;
float4 _Color1;
float4 _Color2;
struct v2f {
float4 pos : SV_POSITION;
float4 scrPos:TEXCOORD1;
};
//Vertex Shader
v2f vert (appdata_base v){
v2f o;
o.pos = UnityObjectToClipPos (v.vertex);
o.scrPos=ComputeScreenPos(o.pos);
return o;
}
//Fragment Shader
half4 frag (v2f i) : COLOR{
float depthValue = Linear01Depth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos)).r);
//depthValue = clamp(depthValue,_minColor,_maxColor);
half4 depth;
//depth.r = depthValue;
//depth.g = depthValue;
//depth.b = depthValue;
//depth.a = 1;
float4 LerpColor = lerp(_Color1, _Color2, depthValue);
depth.r = LerpColor.r;
depth.g = LerpColor.g;
depth.b = LerpColor.b;
depth.a = 1;
return depth;
}
ENDCG
}
}
FallBack "Diffuse"
}
The main part is taken from this tutorial When I open the editor the game view shows the result I'm after, but when I run it. Unity crashes immediately. When am I missing?
Thanks!
Comment
Answer by ricknice · Apr 10, 2017 at 07:39 AM
SOLVED
This problem was not the shader but another script.
What was the problem in another script? I have the same problem now.
I think its about the issue. https://issuetracker.unity3d.com/issues/calling-graphics-dot-blit-destination-null-crashes-the-editor