Jump to content

How to Create Glass


photo

Recommended Posts

To create glass that is both transparent and refractive, one glass surface is not enough. Our artists recommend to use two surfaces:

  • The first surface is used to render reflected light. That is, diffuse and specular (reflective) highlights.
  • The second surface is used to render refraction. That is, how transparent or dark the glass is.

Such approach is better than using only one glass surface, as this way the glass surface itself is not distorted by the refraction. It is also used to create proper colored glass without lightening/bleaching diffuse colors, which is the case if one glass surface is used (since dual source blending is not available in DirectX 9).

Another tip is related to proper sorting of transparent objects. In Unigine sorting is done per surface (depending on its bound volume). For transparent objects to be be sorted, split transparent objects into small surfaces when exporting an object. The smaller surfaces are, the better they are culled and sorted.
 
post-13-0-01245200-1365169538_thumb.jpgpost-13-0-15525700-1365169543_thumb.jpgpost-13-0-11183100-1365169547_thumb.jpg

Step 1. Create Glass Mesh
After you've created a mesh for a glass surface:

  • If necessary, split the glass objects into smaller ones.
  • Clone the glass surface. Name one object *_reflection and another *_refraction. Vertices of these objects should fully match; it is necessary for surfaces to be depth-sorted in Unigine without visual artifacts. Plus these two surfaces should be exported as ONE mesh to avoid any flickering issues.
  • Export a mesh from a 3D editor. In 3ds Max, cloned objects have issues with vertex precision (which may lead to flickering), that is why in the Exporter it is necessary to set Precision to 3-4 (limit floats).

Step 2. Set Up Refractive Surface

  • Open the Materials panel and inherit a new material from mesh_reflection_fresnel_base.
  • Assign textures on the Textures tab.
    post-13-0-14122700-1365169831_thumb.jpg
    As you see there is no Alpha here. Transparency of the glass will be only defines in RGB components: the brighter the pixel is, the more transparent the glass. The darker it is, the less transparent the glass is.
  • Set alpha blending: Src to zero, Dest to src color. That would make the scene behind the glass colored. That means, the screen buffer color (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.
    post-13-0-09718500-1365170137_thumb.jpg
  • Go to States tab and set the Ambient pass to transparent (in this mode, the glass diffuse color is not multiplied by the ambient lighting).
  • Set Refraction to Default, so that refraction is rendered.
  • Set all light passes (Light world, Light omni, etc) to Skip, as this surface is purely for rendering refraction.
  • If necessary, set any Detail option (an overlay or multiply mode) to add unique bumps to the glass surface.
  • On the Common tab, uncheck Parallax mask for objects with parallax mapping behind the glass to be rendered correctly.
  • Uncheck Glow mask.
  • Go to the Parameters tab and set Fresnel bias to 0 (not to compensate for the Fresnel effect). This way, when the camera looks on the glass up front, it will be transparent.
  • Move the camera to look at the glass from a side and set up Fresnel power so that the glass looks dark/non-transparent.
  • Set up Parameters -> Refraction.

Step 3. Set Up Reflective Surface

  • On the Materials panel inherit a new material from mesh_reflection_cube_base
  • Assign textures on the Textures tab.
    post-13-0-66437800-1365169836_thumb.jpg
    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.
  • Set alpha blending: Src to one, Dest to one. This means, glass diffuse color and the colors of the scene behind the glass are added together.
    post-13-0-75129200-1365170145_thumb.jpg
  • Check a Post refraction flag for glass surface itself not to be distorted by refraction.
  • Leave the ambient and all light passes checked (they will be used to create reflections)
  • On the Common tab, uncheck Parallax mask.
  • Uncheck Glow mask if objects behind the glass need to be rendered with glow. If the glass itself should be glowing (for example, at night), leave this option checked.
  • For shadows cast on the glass surface to be more visible, increase Diffuse scale. 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.
  • Set up reflections (dynamic or static ones). Parameters->Reflection->Normal slider controls how the glass' normal map distorts the reflection.

Step 4. Glass and Sky (Light Scattering)

  • If the camera will view the sky through the glass, for both materials check Common -> Post Scattering flag.
  • If the camera will view the glass from the far distance, such glass needs to be affected by light scattering. That is, Post scattering needs to be unchecked. Create a distant glass LOD, inherit materials from the created ones and uncheck this flag for both.

Step 5. Shadows
If the glass is transparent:

  1. Uncheck Cast shadows for both materials.
  2. For the reflective surface material, check Receive shadow.

Step 6. Colored Shadows
To enable colored shadows:

  1. For the refractive surface material, check Common -> Cast translucent.
  2. Enable rendering of translucence: 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.

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.

 

Render order: default

post-13-0-23502000-1365170826_thumb.jpg

Render order +1:

post-13-0-27976300-1365170834_thumb.jpg

Render order -1:

post-13-0-11845400-1365170842_thumb.jpg

Link to comment

Another tutorial from Nat (aka nat.harrold). Many thanks for it!

 

 

This will create a nice simple reflective dirty transparent glass with no refraction or shadow casting ability.

 

1. create textures for diffuse and specular both with interpolated alpha channels. (eg dxt3 or dxt5)

     -  for speed, follow the attached image (explanation_glass_dirty.jpg)

     -  diffuse is inverted and desaturated for specular texture

     -  copy your specular texture into the alpha channel of the diffuse texture

     -  copy your specular texture into the alpha channel of the specular texture (the alpha channel of the spec map interpolates / controls reflection amounts)

     -  save .dds with interpolated alpha

 

2. Inherit material from a reflective one.

     - set blending modes:    

                   Src: src alpha    

                   Dest: one minus src alpha

     - do not use alpha test

     - set textures, save and apply.

     - tweak values. (high glossiness value +180)

     - check 2-sided if you need

 

explanation_glass_dirty.jpg explains more about which parts of the textures and channels create different results.

post-13-0-86171500-1365171496_thumb.jpg

post-13-0-57209700-1365171501_thumb.jpg

Link to comment
  • 5 months later...

could someone from unigine please tell me if it would be possible to make reflection totally separate from opacity for the material? in order to get a surface that is entirely see through but reflective? like really really clean glass? that'd be really helpful.

 

thanks :)

Link to comment

Hello,

If I understand you correctly, please, try to check glass_00 sample at samples/materials.
Materials_phong_mesh_reflection material has a property States -> Reflection -> Dynamical to use dynamical reflection instead of static cubemap.

Link to comment
  • 7 months later...
  • 1 year later...
  • silent unpinned this topic
×
×
  • Create New...