Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by Leoo · Aug 27, 2015 at 08:40 PM · shaderrenderingshader programmingshader writing

Simple "Render on Top of Everything" Shader?

Hey guys!,

i've been trying with no success to make a simple Render on Top of everything with shadows Shader, i cant figure out how to render on top of the terrain grass, and receive normal geometry shadows... wondering if you guys could turn me into the right direction.

  • *Render on top of everything ( will be used for the Player Hands and Weapon's Mesh materials)

  • *Receive Shadows from geometry around the world

  • *100% Diffuse, am not looking for anything else, plain texture/color diffuse, no transparency nor maps.

Where i am at:

  • "Queue" = "AlphaTest+10"

  • ZTest Off

Doing this almost achieves what i need, but it leads me to a weird transparency like problem, where the material dosnt block/cull same material polygons that are behind, its like, am rendering every triangle even on top of others of the same material, so i think it has to do with the ztest? probably? how could i make the shader cull or ztests only on itself?

What i want to achieve:

  • Use only the projection matrix with modified znear/zfar (custom projection, no inaccuracy issues)

  • Pass 1 – clear the depth buffer (renders the mesh, but only clears the depth)

  • Pass 2 – render (renders the mesh as normal, depth isn’t an issue)

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

· Add your reply
  • Sort: 
avatar image
1

Answer by cjdev · Aug 27, 2015 at 09:06 PM

If I understand your problem correctly you need to overlay a texture on top of another? In order to do that you could try combining the color data in one pass but it would be much better and give you better results to simply do two separate passes for each texture. And you said you didn't want transparency but you're going to need it if you want anything to show through on the overlaid texture, otherwise it's just going to show the last texture that was rendered. I just happened to have made an overlay shader recently:

 Shader "Custom/TextureOverlay" {
     Properties {
         _MainTex ("Main Texture (RGBA)", 2D) = "white" {}
         _OverlayTex ("Secondary Texture (RGBA)", 2D) = "white" {}
         _Transparency ("Transparency", Range(0,1)) = 0.85
     }
     SubShader {
         CGPROGRAM
         #pragma surface surf Standard fullforwardshadows 
         #pragma target 3.0
 
         struct Input {
             float2 uv_MainTex;
         };
 
         sampler2D _MainTex;
 
         void surf (Input IN, inout SurfaceOutputStandard o) {
             fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
             o.Albedo = c.rgb;
             o.Alpha = c.a;
         }
         ENDCG
         Blend SrcAlpha OneMinusSrcAlpha
         ZWrite Off
         CGPROGRAM
         #pragma surface surf Standard fullforwardshadows alpha
         #pragma target 3.0
 
         sampler2D _OverlayTex;
         float _Transparency;
 
         struct Input {
             float2 uv_OverlayTex;
         };
 
         void surf (Input IN, inout SurfaceOutputStandard o) {
             fixed4 c = tex2D (_OverlayTex, IN.uv_OverlayTex);
             o.Albedo = c.rgb;
             o.Alpha = _Transparency * c.a;
         }
         ENDCG
     } 
     FallBack "Diffuse"
 }

I'm not sure if that's what you were after but at least it should get you started in the right direction.

Comment
Add comment · Show 1 · 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 Leoo · Aug 27, 2015 at 09:25 PM 0
Share

Ok, this is a good point, i need multiple passes, to be able to do this Pass 1 – clear the depth buffer (renders the mesh, but only clears the depth) Pass 2 – render (renders the mesh as normal, depth isn’t an issue), i dont have a clue about a good syntax for this...

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

27 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

Related Questions

Help with URP shader for a procedural terrain mesh 0 Answers

Operate the shader, rotate the material 90 degrees 0 Answers

Blending between two materials with a mask? 1 Answer

Custom shader samples pixels per-texture rather than from the screen 1 Answer

Custom Urp shader weird problem 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