• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • 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

avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
0

Answer by ricknice · Apr 10, 2017 at 07:39 AM

SOLVED

This problem was not the shader but another script.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gmkwak · Apr 30, 2018 at 04:59 AM 0
Share

What was the problem in another script? I have the same problem now.

avatar image gmkwak gmkwak · Apr 30, 2018 at 05:34 AM 0
Share

I think its about the issue. https://issuetracker.unity3d.com/issues/calling-graphics-dot-blit-destination-null-crashes-the-editor

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

3 Color linear gradient shader 1 Answer

Standard Surface Shader with fade too dark 0 Answers

Rewrite shader so that the Sprite-Diffuse shader doesn't take incidence angle into consideration when applying lighting? 1 Answer

Help with a see-through shader 0 Answers

Block/Obscure light without shadows 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges