Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Awesomepickle · Aug 03, 2018 at 02:05 AM · shaderstencil

Stencil shader object "colliding" with outside of mesh

Hi, sorry for the weird title, I don't really know how to explain this since I'm new to programming and working with shaders. So what I'm trying to do is make it so the liquid mesh only looks like it is inside of the bottle. If I scale the liquid mesh to far it looks like the mesh is outside of the bottle. I was wondering if there is a fix for this to make it look like the mesh is still in the bottle without having to scale the liquid down. Sorry if there is a really obvious fix but i've been stuck on this for like 3 days and have tried anything I could think of.alt text

bottle.png (79.4 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 Piyush_Pandey · Aug 03, 2018 at 09:28 AM

I think you want the water to look like it is inside your bottle with some width for glass thickness. You can achieve this by below steps:-

1) Make mesh just like the bottle. Add a material to it. To this material, you need to add new custom shader code { IMPORTANT when you add this Material with this shader, it will stop rendering on the scene. Do not think something went wrong. We want a masker which is just like a water bottle but a bit thinner so that we can see the glass thickness}

 SubShader
 {
         Tags 
         {  
             "RenderType"="Transparent" 
             "Queue"="Transparent"
         }
             Cull Off
         Lighting Off
         ZWrite Off
         Blend Zero OneMinusSrcAlpha

           Pass
          {
             Stencil
             {
                 Ref 6
                 Comp always
                 Pass replace
 
             }
             // blending zero to one will not render the object to the screen hence you can use this as a masker which is not rendered on the screen also
             Blend Zero One
     
         ***rest of the shader code***
          }
 }



2) Now to your liquid , you have to add a new material. Add a new custom shader to this material with this code

  SubShader
 {
         Tags 
         { 
             "RenderType"="Transparent" 
             "Queue"="Transparent+1"
         }
             Cull Off
         Lighting Off
         ZWrite Off
         Blend One OneMinusSrcAlpha
 
         Pass
          {
             Stencil
             {
                 Ref 6
                 Comp equal 
                 ZFail decrWrap                            
             }
                     ***rest of the shader code**
         }
          
 }




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 Awesomepickle · Aug 13, 2018 at 03:38 AM 0
Share

That did it! Thanks so much!

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

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

Standard Shader Still Visible through Stencil Shader 0 Answers

RenderTexture clears after Blit 0 Answers

Render a sprite only when it's on the parent but not other sprites. 0 Answers

Shadows in my rendered "Portal" Don't Render 0 Answers

Strange issue with stencil buffer and draw order 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