- Home /
How to find vertice points for "lid generation"
Hello.
I need to "cut" mesh in real-time. I have made a shader that discards all drawing above given world y-coordinate. The y-coordinate is passed to the shader as an attribute. This works fine, but of course this leaves a hole to the top of the mesh. I was thinking of generating "a lid" to the mesh hole from a script. My question is how could I find the points for the vertices? I have attached a screenshot of 2 cubes standing on one corner and marked the points for the vertices with red color. As you can see, the number of vertices depends on where the "cut plane" is located.
The lid generation should works also if I rotate the mesh. And it would be awesome if the solution would work also more complex meshes than a cube (but I'm not talking about organic/spherical objects, as that would require tons of vertices for the lid)
Alternative solutions on how to achieve this kind of behavior are welcome too. Unity doesn't have any boolean operations for mesh, but I'm pretty sure those would be very performance hungry if done on real-time.
The purpose of this is to mimic simplified liquid in a closed tank and I must be able to adjust the liquid level.
ChrisHP at #Unity3D gave me a very interesting and completely different solution to the problem - I should flatten all vertices in a vertex shader ins$$anonymous$$d of discarding pixels in the pixel shaders. This should be also very cheap performance wise. Im on it now, will post the solution here if it works (not really sure how to write such shader, and also a bit concerned how it will look).
That is the method I was trying, moving the verticies is quite simple I think however I was struggling to get diffuse lighting and shadows to work. I would be interested to see what you come up with! :)
As afaik I cannot answer my own question, heres what I did: I gave up on the idea to find vertices and generating mesh. I also tried moving the vertices, but could not get the results I wanter (pretty obviously moving the top vertice in the above example would not give a slicing effect, but rather would look like the mesh is squashed). The solution was (thanks to ChrisHP again!) to add another pass to the shader that renders the backfacing polygons (dark blue areas of the above pictures) with solid color (+ ignoring lightning). This creates an illusion of a lid.
Your answer
Follow this Question
Related Questions
Flat shading procedural generated mesh? 1 Answer
Don't we love roads? 0 Answers
Odd shadow behaviour from generated mesh 1 Answer
Generating Normals 1 Answer
How can I generate a up facing quad mesh with variable resolution? 0 Answers