Creating a glass material has always been a troubling aspect for many developers whom are new to creating materials.
In this tutorial we will cover creating a glass material that will serve multiple uses. We will create a base glass material with three main features/glass types:
- Glass Tint
- Reinforced Glass
- Frosted Glass
Begin with setting your base material blend mode to Translucent and your Lighting Mode set to Surface TranslucencyVolume.
There are four global parameters we will use. Start by creating three Scalar parameters named Opacity, Roughness, and Specular. Create a constant and set the value to 1.
Connect this constant into Metalness of the base material.
If you like to stay organized, select the four new nodes and create a Comment box by pressing ‘C.’
Here is where we introduce the first of many Static Switch Parameters. These nodes allow the user to toggle between True and False, essentially enabling or disabling features within the material.
Create a Static Switch Parameter and name the node Use Normal Texture.
Create a Constant 3 Vector node and set the values to 0.5, 0.5, 1. This will be the flat normal value for the False state. Plug the output of the Constant 3 Vector into the False input of the Static Switch Parameter.
Create a Texture Sample node and convert it into a parameter. Be sure to place a default normal map into this node for it to be valid. For this example I created a developer texture that simulates a normal map using a flat normal value.
Connect the output of the Texture Sample into the True Input of the Static Switch Parameter.
Connect the output of the Static Switch Parameter into the Normal input of the material.
For Refraction we will use a very common setup for glass materials.
First, create two Scalar Parameters named Fresnel Falloff and IOR (Index of Refraction).
Create a Constant node with the value of 1.
Create a Fresnel node and a Lerp, or Linear Interpolate node.
For default settings of the Scalar Parameters, set Fresnell Falloff to 10.0 and IOR to 0.4.
Connect the output of Fresnel Falloff to the ExponentIn of the Fresnel node. Connect the output of Fresnel into the Alpha input of the Lerp.
Connect the Constant node output into the A input of the Lerp.
Connect the IOR Scalar Parameter into the B input of the Lerp.
The ouput of the Lerp will be used later on in the material as we create additional features that tie it all together.
Setting up Glass tint is a very simple step.
Create a new Static Switch Parameter named Tint Glass.
Create a Constant 3 Vector and assign it a value for your base glass material when Tint Glass is not enabled.
Create a Constant 3 Vector Parameter named Color Glass and set it to just less than pure white at 0.9, 0.9, 0.9, 1.
Connect Color Glass into the True input of the Tint Glass Switch Parameter.
Connect the Constant 3 Vector, the default glass color, into the False input of the Tint Glass Switch Parameter.
As we continue on we will connect the output of Tint Glass into our material network.
For creating Reinforced Glass we are going to implement some procedural generation into the workflow.
Begin by creating the following nodes:
- Three Constant nodes with values set to 0.08, 0.625, and 8.0.
- One Static Boolnode set to True.
- Two GeneratedOffsetBands
- One Constant 3 Vector Parameter named Reinforeced Metal Color with a default value of 0.1, 0.1, 0.1, 1.0.
- Three Add nodes.
- Three Multiply nodes.
- One One-Minus Node (1-x).
- Two Static Switch Parameters, both named Reinforced.
Lets start with the creation of our Reinforced metal lines by using GeneratedOffsetBands. This node allows the creation of solid white bands procedurally. We will use this to create both horizontal and vertical bands.
Connect the 0.08 Constant into the Width input of both GeneratedOffsetBands.
Connect the 0.625 Constant into the Offset input of both GeneratedOffsetBands.
Connect the 8.0 Constant into the Bands input of both GeneratedOffsetBands.
Connect the Static Bool, set to True, into only one of the GeneratedOffsetBands. This will rotate the direction 90 degrees allowing us to have created identical bands in both directions.
Connect the Result output of Both GeneratedOffsetBands into the A and B input of the first Add node.
Connect the output of the Reinforced Metal Color Constant 3 Vector into the A input of the first Multiply node. Connect the output of the first Add node created into the B input of the same Multiply node.
We now need to invert our Generated bands to create a mask for the actual window color to appear correctly.
To do this we will connect the output of the Add node into the input of the One-Minus (1-x) node.
From here we will connect the output of the One-Minus into the next Multiply node’s A input. Revisiting the Tint Glass network we will take the output of the Tint Glass Switch Parameter and connect into the B input of the Second Multiply node.
Now we need to add together the color of the GeneratedOffsetBands with the Color of the glass itself.
From the first multiply node connect the output into the input of the second Add node A input. Connect the second Multiply output into the B input of the Add node.
This should sum up the color aspect of the Reinforced feature. We need to finish this off by connecting the first Reinforced Static Switch Parameter with the proper values.
From the second Add node, connect the output into the True input of the Reinforced Static Switch Parameter. Connect the output from our Tint Glass network into the False Input of Reinforced Static Switch.
Finally connect the output of the first Reinforced Static Switch Parameter into Base Color of the Material.
We now need to filter the Opacity for the Reinforced feature.
From the very first Add node where we combined both GeneratedOffsetBands nodes, connect the output and connect to the A input of the third and final Add node.
We now need to use our inverted mask from the One-Minus node to mask out the Opacity Scalar Parameter. We do this by connecting the output of the One-Minus into the A input of the last Multiply node and connect the output from our Scalar Parameter, Opacity, into the B input of the multiply node.
We need to combine the two opacity values by taking the output of the third Multiply node and connecting it into the B input of the third Add node.
Finally, using the last Reinforced Switch Parameter node, Connect the output of the third Add node into True. We will connect the False input of the parameter at the end of the next feature.
To finish, connect the output of the second Reinforced Switch Parameter into the Opacity input of the material.
The final feature is to create Frosted Glass, or Privacy Glass.
Start by creating the following nodes:
- One Scalar Parameter Node named Frosted Glass Blur.
- One Noise Node.
- Two Multiply Nodes.
- Two Static Switch Parameters named Frosted.
For this case we will start with the Noise node first. By clicking on the node we can access the values within. We need to set the following values.
- Scale: 5.0
- Quality: 1.0
- Function: Simplex (Default)
- Turbulance: unchecked, off
- Levels: 3.0
- Output Min: 0.5
- Output Max: 0.6
- Level Scale: 1.0
Connect the Frosted Glass Blur into the Filter Width input of the Noise node. This will help us simulate the blurred effect of frosted glass.
Connect the output of the Noise node into the first Multiply A input. From the Refraction network, connect the output of the Lerp into the B input of the First Multiply.
From here this defines the Refraction values of the Frosted Glass. Connect the output of the first Multiply node into the True input of the first Frosted Static Switch Parameter. Connect the output of the Lerp from the Refraction network into the False input of the Frosted Static Swtich Parameter. Connect the output of the Static Switch Parameter into the Refraction input of the Material.
Now we need to define the Frosted Glass opacity. Similar to how we treated this step in the Reinforced glass feature we will do a similar process.
Connect the Fresnel output from the Refraction network into the A input of the last Multiply. Connect the Opacity output from our global nodes into the B input of the Multiply. Using the second Frosted Static Switch Parameter, Connect the output of the last Multiply node into the True input of the Frosted Static Switch Parameter. Connect the Opacity output into the False input of the Frosted Static node.
To complete the material, connect the output of the final Frosted Static Switch Parameter into the False input of the second Reinforced Static Switch Parameter.