Quantcast
Channel: Questions in topic: "crash"
Viewing all articles
Browse latest Browse all 2383

Unity crashes when trying to run depth shader with color lerp.

$
0
0
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][1] 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! [1]: http://willychyr.com/2013/11/unity-shaders-depth-and-normal-textures/

Viewing all articles
Browse latest Browse all 2383

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>