This page has been translated automatically.
UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Content Creation
Materials
Unigine Material Library
Tutorials
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

Creating a Reflective and Refractive Glass

To create a highly realistic looking glass which can reflect and refract the light, we recommend you to use two glass surfaces instead of one:

  1. The first surface is used to reflect the light.
  2. The second surface is used to refract the light.

Such approach is better than using only one glass surface, as the glass surface itself would not be distorted by the refraction. It is also allow you to create proper colored glass by avoiding lightening and bleaching of diffuse colors, which is applied in case of using one one glass surface (since dual-source color blending is not available in DirectX 9).

Notice
In Unigine depth-sorting is done per surface (depending on its bound volume). Split transparent objects into small surfaces when exporting for them to be sorted.

Step 1. Creating a Glass Mesh

While creating a glass mesh in the third-party application, you may need to do the following:

  1. Split the glass surface into smaller ones for better depth-sorting.
  2. Clone the glass surfaces. Name one of them *_reflection and another *_refraction. Vertices of these surfaces should fully match (it is necessary for surfaces to be depth-sorted in Unigine without visual artifacts). Besides, these two surfaces should be exported as one mesh to avoid any flickering issues.

After a proper mesh is created, export it from a 3D editor. In Autodesk 3ds Max cloned objects have issues with vertex precision (which may cause flickering), that is why in the Exporter it is necessary to set Precision to 3-4 (limit floats).

Step 2. Setting Up a Refractive Surface

To set up a refractive surface, you should do the following:

  1. In Materials editor inherit a new material from mesh_reflection_fresnel_base material.
  2. Assign textures to it in the Textures tab.

    As you see, this diffuse texture do not contain an Alpha channel. Transparency of the glass will be defined by RGB components: the brighter the pixel is, the more transparent is the glass.

  3. Set alpha blending parameters in the Common tab: Src to zero, Dest to src color. That would make the scene behind the glass colored. That means, the screen buffer color (color of the objects behind the glass) is multiplied by the glass color. No glass diffuse color is added (it is zero). Such blending will darken the objects behind the glass as they should be.

  4. Disable Parallax mask flag for objects with parallax mapping behind the glass to be rendered correctly.
  5. In the States tab set the Ambient pass to Transparent (in this mode, the glass diffuse color is not multiplied by the ambient lighting).
  6. Set Refraction pass to Default, so that refraction is rendered.
  7. Set all light passes (Light world, Light omni, etc) to Skip, as this surface is used only for refracting.
  8. If necessary, set any Detail option (overlay or multiply modes) to add unique bumps to the glass surface.
  9. In the Parameters tab set Fresnel bias parameter to 0 (not to compensate for the Fresnel effect). This way, when the camera is directed on the glass from up front, it will be transparent.
  10. Move the camera to look at the glass from a side and set up Fresnel power for the glass to look dark/non-transparent.
  11. Adjust Refraction parameters.

Step 3. Setting Up a Reflective Surface

To set up a reflective surface, you should do the following:

  1. In Materials editor inherit a new material from mesh_reflection_cube_base material.
  2. Assign textures to it in the Textures tab.

    For this material, we will set blending to lighten the glass surface. That means, dark pixels will not affect the final image, while white pixels will make the glass surface look whiter, as if covered or sprayed with something. For example, it make the glass look dusty or smudged.

  3. In the Common tab, set alpha blending: Src to one, Dest to one so, glass diffuse color and the colors of the scene behind the glass are added together.

  4. Disable Parallax mask flag for objects with parallax mapping behind the glass to be rendered correctly.
  5. Disable a Glow mask flags if objects behind the glass need to be rendered with glow. If the glass itself should be glowing (for example, at night), leave this flag enabled.
  6. Enable a Post refraction flag for glass surface itself not to be distorted by refraction.
  7. In the States tab leave the ambient and all light passes enabled (they will be used to create reflections).
  8. For shadows cast on the glass surface to be more visible, increase the Diffuse scale in the Parameters tab. Make sure that you do not use a dark diffuse color, as in this case shadows cast on the glass will not be visible at all.
  9. Adjust reflections in the Reflection field.

Step 4. Adjust Light Scattering

To set up a correct light scattering, do the following:

  1. If the camera will view the sky through the glass, for both materials enable a Post Scattering flag in the Common tab.
  2. If the camera will view the glass from the far distance, disable a Post scattering flag. If you will create a distant glass LODs, inherit materials from the created ones and disable this flag for them too.

Step 5. Adjust Shadows

If the glass is transparent, do the following:

  1. Disable a Cast shadows flag for both materials.
  2. For the reflective material, enable a Receive shadow flag.

Step 6. Set Up Colored Shadows

To set up colored shadows do the following:

  1. For the refractive surface material, enable a Cast translucence flag in the Common tab.
  2. Enable rendering of translucence: press Esc to open the Main menu -> Render tab -> Options -> Translucence.
  3. Enable casting translucent shadows from a world light source: Nodes -> LightWorld -> Shadow tab -> Translucence.
  4. Select the translucent shadow map size in the Translucence size drop-down list.
  5. If necessary, adjust translucence Bias parameter in the Parameters tab.

Step 7. Set Up Sorting of Transparent Surfaces

If splitting glass into small surfaces did not help, you can manually set the sorting order: Materials -> Common tab -> Render order. The higher the value, the later the surface will be rendered if compared to other transparent objects.

Last update: 2017-07-03
Build: ()