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 Harry64 · Nov 06, 2013 at 08:31 PM · clippingliquid

illusion of liquid in bottle with cull and clip shader?

I am searching now a little while for a solution to create a liquid in a bottle that behaves like real liquid but dont uses realtime fluid simulation. Because that would not work good and is really cpu and gpu heavy!

Today I had a really great idea. I found once on the internet a project from someone that showed a box that is moving left to right and everything that is inside this box is displayed and everything that is outside this box is clipped.

I found the project on my pc again but there are 2 big problems. 1. the shader is outdated and unity has excluded it from OpenGL Es 2.0 and DX11 and my Project uses DX11. 2. this method uses a texture to clip stuff and that texture is projected via script over the world from the clipping objects local position and rotation. (I tryed it and it works for the liquid part but because it is projected over the world I will never be able to create a top face for the liquid.)

I found also another try from someone who made a shader that does nothing and this shader works like a mask. but it clips the whole object if it is between the camera and the bottle.

sooo. what I need is a way to clip everything from a specific object that is outside of a clippingobject. with that I could work. Is there a way to do this?

EDIT: I draw a little picture to better describe how I will setup this Idea. btw to clip the liquid Surface I would use a copy of the liquid model. link text

I made this really quick in blender to show how it would look if the bottle would be rotated. alt text the blue face is the liquid surface. the transparent blue plane is that whats been clipped away by the liquid model. the gray liquid is inside of this box so it is visible. the upper half of the liquid is outside of the box so it is clipped. I would write a script to the clipping box and the liquid surface so that it will not rotate with the bottle but will move with the bottle.

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
0

Answer by MarkD · Nov 06, 2013 at 11:25 PM

Ok well, mostly for my liquids I simply create a shape that fits inside the bottle and just animate it. Throw one of the refraction shaders standard in unity on it and the animation of makes the refraction move. Also why go over the complete trouble of a clipping shader when you can create a simple round plane that fits in the bottle? (in modeling software) the size can be animated / controlled by scripts, so if the bottle is full the circle plane is smaller when the bottle is more empty the circle plane scales up to fit the bottle. Like I said before this would work better with a complete model fitting inside the bottle as you can give it color / effects with shaders.

I hope this was of any sort of help.

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 Harry64 · Nov 07, 2013 at 09:28 PM 0
Share

Yes that would be ok for static objects that never move.

I did forget to write that I want the bottle to be a rigid body and the liquid should move like real fluid if the player or a object moves the bottle or tilt it or throw it around.

I update my question a bit with more pictures.

avatar image MarkD · Nov 09, 2013 at 11:35 AM 0
Share

Ok, that picture realy helped putting it in perspective.

Well for that effect you could use the stencil buffer, There are several people creating portal effects with it, but you should be able to inverse that effect. So ins$$anonymous$$d of cutting out a hole in a wall you could cut out all the stuff around it and keep the center in the shape of the object, you could use the vertex position of your model to deter$$anonymous$$e how far each part needs to be cut off.

I can't give you a code because i'm not that great with shader coding, at least not with stencil buffers, but that should be a good way to start investigating.

avatar image Harry64 · Nov 10, 2013 at 07:04 PM 0
Share

hmmmm.... I tryed it with a shader that uses only the z-buffer to cut away the top part of the bottle... but this was not good because when I looked at the bottle from above it cutted all liquid away... interesting idea but I really have no idea where to start... I will search a bit more for stencil buffers.

I really think my idea could be a very cool way to render a liquid effect for every game. If I find a working solution I hope I can get it into the asset store.

if you find anything useful for me please let me know. ^^

avatar image MarkD · Nov 10, 2013 at 09:05 PM 0
Share

If I bump into anything useful i will surely let you know :) And indeed it is a cool idea, which also could be very performance friendly since no real time vertex displacement occurs. Combine that with a refract and detract shader and you have a pretty good water emulation going on, which would be definitely worth something on the asset store :)

avatar image
0

Answer by Harry64 · Nov 08, 2013 at 09:29 PM

I think I can forget to try this with shaders. But I think I have a solution for this but to do the liquid in the bottle thing I would need to write a script that makes a boolean intersection operation in realtime.

I found on the internet only 2 people that created a realtime boolean script but the first ones link to the asset store is dead. and the second one made a big pack with lots of stuff that I never need and it costs 140$ or something.

sofar I did not found any hint on the internet how to code this...

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

16 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

Related Questions

Drawing outside/over GUI.Window 2 Answers

Physics.Raycast + CharacterController + Clipping plane problems 0 Answers

How use a clipping shader to make a cross section? 1 Answer

3rd Person Camera clips through walls 0 Answers

How to use 2 tk2dCameras, the 2nd one with "viewport clipping"? 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