• 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 vardulov · Aug 02, 2015 at 05:55 AM · meshlayersmeshes

Prioritizing Visibility of Meshes

I am building an environment that will have lots of different meshes to represent terrain. What I would like to be able to do is make it so that given an intersection of these meshes I could prioritize which ones are seen in the camera. So for example in the following images I have a large white flat plan, on top which there is a red mesh that is rendered from and .obj file. As you can see the red goes down underneath flat plane. As a result parts of the mesh are lost as they are covered up. I would like it to be rendered in a way that the red mesh is visible instead the white plane in the places. I've read a little bit on how to do this process, for example with rendering a weapon, but I also have circumstances where a third or even more meshes could layered on top. From the images. I would like to be able to see the green where there is green the green plane, red where there is red mesh but no green, and white visible only in the places where there is no other color mesh.

Images:

Side view:

alt text

Top view:

alt text

Thanks for any and all help,

Victor

image1.png (72.7 kB)
image2.png (85.7 kB)
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
0
Best Answer

Answer by vardulov · Aug 13, 2015 at 06:52 PM

So after a little bit of reading on the subject of how to control the order of rendering I determined that using Custom Shaders was the way to go. Because my particular materials for my project are texture mapped with colored images, I don't have to worry about lighting therefore I was able to use the most basic Vertex and fragment shader described here: http://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html.

Then I used the Tags section to specify the Render Queue by setting the "Queue" tag to a value of "Geometry+n" where n grew with the precedence . NExt you must set the ZTest Always I then went to the material I was applying to the mesh and set the Shader to be the Custom Shader associated with the priority associated with.

The basic idea is setting that all the meshes Always show up (that's the ZTest part) but then you also manipulate the order in which things are rendered to make it customizable. I used this method and it worked ideally for my reasons.

NOTE! This will cause weird results if you have many "lower priority" hills that cover up your "higher priority" meshes.

An example of the Shader I used is:

 Shader "Custom/New Shader"{
     Properties {
         _MainTex ("Base (RGB)" , 2D) = "white" {}
     }
     SubShader{
         Tags{"Queue" = "Geometry+1"}
         Pass{
             ZTest Always
             CGPROGRAM
             
             #pragma vertex vert_img
             #pragma fragment frag
             
             #include "UnityCG.cginc"
             
             uniform sampler2D _MainTex;
             
             float4 frag(v2f_img i): COLOR {
                 return tex2D(_MainTex, i.uv);
             }
             
             ENDCG
         }
     
     }
 }
Comment
Add comment · 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

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.

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

2 People are following this question.

avatar image avatar image

Related Questions

Can you store arbitrary data in a Mesh? 1 Answer

Different prefabs using same mesh. Any performance gain? 1 Answer

When meshes are loaded ? 1 Answer

How do I use the same material on 2 meshes without distortion? 2 Answers

How do you make a mesh visible to certain cameras? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges