How do you ensure that the index of refraction is correct, regardless of how many nested or overlapping mediums a light ray enters? Some common situations are:
- Beverages in glassware, with floating ice.
- Bubbles in transparent solids or liquids.
- Overlapping materials with different indices of refraction.
These situations require careful setup to avoid incorrect refraction.
For example, if you have an ice cube floating in liquid in a glass, do you:
- Just model the top surface of the liquid?
- Try to cut out the ice cube from the liquid?
- Model the liquid as a closed surface and try to precisely match the interfaces between glass and ice?
- What about numerical precision problems at the interfaces where some intersections might be ignored due to ray bias?
- How do you tell Moonray how to track the different IORs properly as rays traverse the interfaces?
MoonRay employs a system of material tracking to ensure that overlapping materials with different indices of refraction refract light correctly. In order to correctly render these overlapping surfaces you must:
- Model overlapping objects as closed surfaces that intentionally overlap each other
- Assign a different material
priorityto each material so the renderer can resolve the overlaps when tracing the rays. This priority is simply a
priorityattribute on each material that defaults to 0 (no material priority).
With this scheme, the modeling of interfaces no longer needs to be exact (intentional overlap!). No cutting out of shapes is needed. Only the highest priority material exists at any point in space when tracing rays. Moonray will ignore “invalid” ray-surface intersections based on priority.
The key to making this work is a material list that tracks materials as rays enter/exit geometry. The highest priority material in the list is the current material (and current index of refraction.) Moonray can use this information to skip false intersections / ignore lower priority geometry.
|Correct Setup||Incorrect Setup|
In the example walkthrough below, you will see that each object is assigned a priority, where a lower number corresponds to a higher priority. Both glass and ice displace the liquid, and therefore have a higher priority. The liquid does not exist in the overlap areas because it is lower priority, and MoonRay ignores intersections with lower priority surfaces.
If you don’t specify a
priority attr on a Material, it will default to “0” (no priority) and all of the “false” intersections in the example above will become “true” intersections and be shaded.
If you don’t have any overlapping dielectric materials, you don’t need to specify priorities.