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 /
avatar image
0
Question by ihsan07 · Jun 24, 2017 at 08:39 PM · shadershader programmingconditional

Conditional shader??

Now I know this one is a toughie, but any lead or idea will be helpful. Situation; -We have two meshes, one terrain and a large polygon. Polygon has no mesh renderer. Question; Is it possible for terrain mesh to use different material (or color) on just the place where both collides? I tried checking every vertices for collision on editor and creating a submesh, but because meshes are not that dense in vertices like textures, results are looking ugly. I believe the shaders are logical answer but so far i am stuck. Any method (shader, in editor, in runtime) is fine. EDIT: Here is a visualization. alt text

untitled-1.png (10.3 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

2 Replies

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

Answer by tanoshimi · Jun 24, 2017 at 10:21 PM

Sounds like this could be done pretty easily using the stencil buffer. Add a renderer to the polygon that writes a value to the buffer. Then test the buffer value in the terrain shader and write different coloured outputs accordingly.

https://alastaira.wordpress.com/2014/12/27/using-the-stencil-buffer-in-unity-free/

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 ihsan07 · Jun 25, 2017 at 08:02 AM 0
Share

I will definetly try this and return with results. many thanks

avatar image ihsan07 · Jun 26, 2017 at 05:05 AM 0
Share

If it was set to ZWrite Off, this is working much better. Thank you for your answer. And I really should try things more before making an update. It is my bad :P

avatar image
0

Answer by ihsan07 · Jun 25, 2017 at 07:17 PM

Just a quick question. I went through some examples and it seems that using this method will change color of terrain where it is behind of polygon from perspective of cam. This is not wanted. I just want colliding parts to change color which will not change wherever the camera. Is this doable using stencil buffers? EDIT: I found a solution; http://answers.unity3d.com/questions/23544/projecting-a-square-or-another-shape-onto-terrain.html EDIT2: If I set ZWrite off using stencil buffer, colored part doesn't change based on camera's location and angle.

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.

Follow this Question

Answers Answers and Comments

98 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 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

Unlit Transparent With Color Support 1 Answer

create a texture with shader code? ( without using a texture ) 1 Answer

How to add Emission to my custom shader? 2 Answers

The Best Way To Make Stylised Grass in Unity? 0 Answers

How to get the value of a pixel of a noise node if it's greater than some threshold? 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