- Home /
Transparencies with overlapping bounding boxes (Glass Interior/Exterior)
Hello, I am using Unity to simulate some glass objects that sometimes have (transparent) liquids inside them as well.
Basically I have objects that are made of up three progressively smaller bounding boxes
Glass exterior (should be rendered last)
Liquid (rendered in the "middle")
Glass interior (should be rendered first)
Here is a simplified (just two layers, no liquid) example I made when trying to solve the problem:
http://69.73.181.152/~distorti/work/transp_problem/
The interior glass is made blue and exterior is yellow to make it more obvious when it renders incorrectly. Press TAB to change the view to other objects. Move around the view to see how it affects the sorting. Also notice the two cubes appear mostly correct from 2 sides (yellow outside) but from the opposite two sides they appear wrong (blue showing over yellow). The cylinder at the end just flips depending if your view is above or below it.
My problem is the sorting seems to change depending on what angle I view the objects. When my camera is below the center of the bounding box it "flips" and renders in the opposite order. I've tried many things to resolve it.
So I know the order they should be rendered in, because they are always viewed from the outside. I was hoping I could influence unity to prioritize by hierarchy, naming or bounding box size but so far no luck. I've tried:
Setting bounding boxes manually (I really had hope this would work): I tried to set the renderer's bounds to be progressively smaller in the order I want them to render in. Since they all overlap and have nearly the same center I figured this would make unity's sorting work, but it did not seem to have any effect. Perhaps I am setting it wrong? There seems to be multiple bounding boxes and ways to set them.
- Setting render queues from script: this works on a single object, but the problem is I need these to sort with other objects like particles, other transparent objects, and the environment. It seems I would have to create scripts to detect and set the render queues on every transparent object in my scene based on the order from the viewer - seems like I would be asking for trouble and a lot of extra scripts evaluating every frame.
I've worked on Nintendo DS games and we had the option to set a render priority within a single model, but it wouldn't effect the sorting against other models - this would be the perfect solution for me, does Unity have this ability? The render queue seems to effect its priority overriding the entire scene.
Changing pivot locations, making all pivots the same - it seems the pivot doesn't matter, probably using the center of the bounding box.
I've done a lot searching for transparency sorting but seems most people's problem involves layers of objects, where mine is overlapping volumes. Anyone have any suggestions for me?
could you post the shader of those objects in your example scene?
Your answer
Follow this Question
Related Questions
Looking for a transparent shader 0 Answers
CustomAxis sort not working between objects placed at different layers rendered by multiple cameras 0 Answers
Issue using a single-mesh with multiple-seperate-components and alphaBlended transparency. 1 Answer
Transparent objects sorting 6 Answers
Sorting Issue with Alpha Blended and UI 0 Answers