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 joeybubble1 · Mar 09, 2013 at 10:17 AM · shaderterrainrenderqueue

Render object through terrain

Hey everyone, as I am no good at shader coding, I am compelled to turn to unity answers :D anyway, what I want is just a basic defuse shader that render behind everything except the terrain, which I want the shader to render in front of.

So if anyone could help me, ill be very greatful.

Thanks Tz

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by whebert · Mar 09, 2013 at 06:04 PM

Try this. I modified the default diffuse texture and added several tags to accomplish what you need I think. The queue order setting should cause rendering after the terrain and before any geometry, and along with the ZWrite Off tag should insure your normal geometry renders over anything with this shader. I added an Offset to help this shader render over the terrain, even when very close to the terrain surface.

 Shader "DiffuseOverTerrain" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _MainTex ("Base (RGB)", 2D) = "white" {}
 }
 
 Category {
     Offset -2, -2
     ZWrite Off
     
 SubShader {
     Tags { "RenderType"="Opaque" "Queue" = "Geometry-1" }
     LOD 200
 
 CGPROGRAM
 #pragma surface surf Lambert
 
 sampler2D _MainTex;
 fixed4 _Color;
 
 struct Input {
     float2 uv_MainTex;
 };
 
 void surf (Input IN, inout SurfaceOutput o) {
     fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
     o.Albedo = c.rgb;
     o.Alpha = c.a;
 }
 ENDCG
 }
 }
 
 Fallback "Diffuse"
 }
 
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 whebert · Mar 09, 2013 at 07:06 PM 0
Share

Forgot to mention, if you wanted your in-between objects to render over the terrain regardless if they are positioned under it or not, you could add a "ZTest Always" just after ZWrite Off and that'd do the trick.

avatar image joeybubble1 · Mar 09, 2013 at 09:52 PM 0
Share

thanks so much! :)

avatar image
1

Answer by Loius · Mar 09, 2013 at 06:14 PM

Just use two cameras. One camera renders only the terrain's layer, and the other camera renders the seen-through things. Give the cameras different depths and a 'don't clear' background, and one will render on top of the other.

Comment
Add comment · Show 4 · 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 joeybubble1 · Mar 09, 2013 at 09:53 PM 0
Share

problem with that is, it will affect performance won't it?

avatar image Loius · Mar 10, 2013 at 12:15 AM 0
Share

Everything affects performance. It's simple enough to try it and see for yourself if it's going to be a big hit, but I've used it plenty myself and never had an issue. If your camera draw layers are mutually exclusive (you're not drawing anything twice), the only overhead would be repositioning the viewing area between cameras.

avatar image joeybubble1 · Mar 10, 2013 at 12:19 AM 0
Share

oh, ill try out then :)

avatar image beniciodomi · Nov 25, 2020 at 11:41 PM 0
Share

Thanks!! The best and easier answer!! One thing to take on care is that in newer versions of unity you have to use the Clear Flag "Depht only" instead of "don't clear"

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

13 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

Related Questions

Custom Render Queue 0 Answers

render object on top of everything with dynamic shadows (for mobile) 1 Answer

Stumped! I have an engine that chooses what cube is where, but I need a way to render them. 1 Answer

How to generate a smooth spherical world? 1 Answer

Using custom vertex shader for terrain? 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