• 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 Jun 18, 2017 at 07:25 PM by Whirligig231 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Whirligig231 · Jun 15, 2017 at 12:24 AM · shadersshader programmingshader writingsurface shader

Shading is visible through object using surface shader

I currently have the following surface shader:

 Shader "Custom/Blend 4 Textures, Vertex Color" {
     Properties
     {
         _Layer1("Texture 1", 2D) = "black" {}
         _Layer2("Texture 2", 2D) = "black" {}
         _Layer3("Texture 3", 2D) = "black" {}
         _Layer4("Texture 4", 2D) = "black" {}
     }
         SubShader
     {
 
         Tags{ "Queue" = "Geometry" }
 
         Lighting Off
 
         CGPROGRAM
 #pragma surface surf Lambert
 
         sampler2D    _Layer1;
     sampler2D    _Layer2;
     sampler2D    _Layer3;
     sampler2D    _Layer4;
 
     struct Input
     {
         fixed4 color : COLOR;
         fixed2 uv_Layer1 : TEXCOORD0;
     };
 
     void surf(Input i, inout SurfaceOutput o)
     {
         half4 l1 = tex2D(_Layer1, i.uv_Layer1);
         half4 l2 = tex2D(_Layer2, i.uv_Layer1);
         half4 l3 = tex2D(_Layer3, i.uv_Layer1);
         half4 l4 = tex2D(_Layer4, i.uv_Layer1);
 
         float4 color = float4(1, 1, 1, 1);
         color.rgb = l1.rgb;
         color.rgb = l2.rgb * (1 - i.color.r) + color.rgb * i.color.r;
         color.rgb = l3.rgb * (1 - i.color.g) + color.rgb * i.color.g;
         color.rgb = l4.rgb * (1 - i.color.b) + color.rgb * i.color.b;
         o.Albedo = color.rgb;
         o.Alpha = color.a;
     }
         ENDCG
     }
 
 }
 

I'm using this for a model of terrain, so that I can blend four different terrain textures. However, the shading on other objects seems to be visible through the object with the surface shader:

Tree visible through terrain

The tree here is using the Tree Creator shaders, but with Standard it does the same thing. Therefore, I suspect the issue is with the custom surface shader. Does anyone have an idea what is wrong?

Comment
Add comment · Show 2
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 TheBlackBurrito · Jun 15, 2017 at 02:46 AM 0
Share

Does changing the order of the $$anonymous$$aterial in the render Queue fix this?

Show more comments

0 Replies

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

70 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 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 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 avatar image

Related Questions

How to add Zbuffer to Custom Surface Shader 1 Answer

How can i add a alpha value to this shader? 1 Answer

Five colors gradient on sprite 1 Answer

Black outline and transparency shader 1 Answer

"Stencil Operation" property setup? 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