manguste Posted April 5, 2013 Share Posted April 5, 2013 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. Step 1. Create Glass MeshAfter 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.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. 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.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. 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. ShadowsIf the glass is transparent: Uncheck Cast shadows for both materials. For the reflective surface material, check Receive shadow. Step 6. Colored ShadowsTo enable colored shadows: For the refractive surface material, check Common -> Cast translucent. Enable rendering of translucence: Esc to open the Main menu -> Render tab -> Options -> Translucence. Enable casting translucent shadows from a world light source: Nodes -> LightWorld -> Shadow tab -> Translucence. Select the translucent shadow map size in the Translucence size drop-down list. If necessary, adjust translucence Bias. Step 7. Set Up Sorting of Transparent SurfacesIf 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 Render order +1: Render order -1: Link to comment
manguste Posted April 5, 2013 Author Share Posted April 5, 2013 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. Link to comment
steve3d Posted April 8, 2013 Share Posted April 8, 2013 great tutorial, I'm just courious how to create a correct glass walls. Thanks for these tutorial. Link to comment
phillbot Posted September 12, 2013 Share Posted September 12, 2013 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
sebastianbah Posted September 13, 2013 Share Posted September 13, 2013 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
binstream Posted April 25, 2014 Share Posted April 25, 2014 Moved to the documentation: https://developer.unigine.com/en/docs/1.0/tutorials/glass/ Link to comment
drew.groeger Posted April 20, 2016 Share Posted April 20, 2016 Where does one find "mesh_reflection_cube_base" and "mesh_reflection_fresnel_base"? They are not listed anywhere in my Materials editor. Link to comment
silent Posted April 20, 2016 Share Posted April 20, 2016 Hi Drew, This tutorial is only for old Unigine SDK versions. Glass material you can find in Samples -> Demos -> Samples 2.2.x -> Mateirals -> pbr_materialballs. How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Recommended Posts