Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by MaT227 · Aug 25, 2014 at 02:43 PM · shadermaterialdepthsurface

Shader - Writing to Depth issues

I am trying to write to the depth buffer using a shader but I am facing some issues. If you look at the two screenshots, you can see that the mask is a circular gradient (black part) but it does a awful cut-out and I don't understand why.

It's quite strange because the gradient seems to be good if I render the Depth buffer from the camera. But inside the shader it does a bad simple cut-out instead of a nice gradient.

How can I fix this ?

 Tags { "Queue"="Geometry+10" }
 ZWrite On
 Blend SrcAlpha OneMinusSrcAlpha
 Pass
 {
     CGPROGRAM
     #pragma exclude_renderers gles flash
     #pragma vertex vert
     #pragma fragment frag
     #include "UnityCG.cginc"
     sampler2D    _Mask;
     float4        _Mask_ST;
     
     struct VertOut {
         float4 pos :    POSITION;
         float2 uv :    TEXCOORD0;
     };
     struct FragOut {
         float4 color :    COLOR;
         float depth :    DEPTH;
     };
     VertOut vert(appdata_base IN) {
         VertOut o;
         o.pos    = mul(UNITY_MATRIX_MVP, IN.vertex);
         o.uv    = TRANSFORM_TEX(IN.texcoord, _Mask);
         return o;
     }
     FragOut frag(VertOut IN) {
         FragOut o;
         float4 mask    = tex2D(_Mask, IN.uv);
         o.depth        = mask.rgb;
         o.color.rgb    = mask.rgb;
         o.color.a    = 1.0;
         return o;
     }
     ENDCG
 }

Screenshot

untitled-1.jpg (85.0 kB)
Comment
Add comment · Show 1
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 mradfo21 · Jul 29, 2015 at 06:26 AM 0
Share

how did you do this?

i can't seem to create a struct and use that as the output from the frag function.

i always have to export COLOR

   half4 frag (v2f i) : COLOR
     {
         i.uvproj /= i.uvproj.w;
         i.uvproj = (i.uvproj + 1) * 0.5;
                        
         float3 tex = tex2D(_$$anonymous$$ainTex,i.uvproj).xyz;
         return float4(tex.xyz,1.0);
     }

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Depth-only pass in Surface Shader 1 Answer

How to Modify Standard Surface Shader's SpecCube? 1 Answer

Thickness Surface Shader 0 Answers

Material doesn't have a color property '_Color' 4 Answers

Screen Depth giving me artifacts in Intersection Shader. 1 Answer


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