In this lesson, you will learn how to configure alpha blending and screen-space color sampling in Shader Graph to simulate the way light passes through and bends within glass surfaces.
The Physics of Glass
To create realistic glass, we must move beyond standard opaque rendering. Glass is defined by two primary characteristics: transparency (allowing light to pass through) and refraction (bending light as it enters a denser medium).
In Shader Graph, you must first set your Material's Surface Type to Transparent. Unlike opaque objects that overwrite the depth buffer, transparent objects use the Alpha channel to determine how much of the underlying scene color is visible.
Implementing Refraction via Screen Color
Refraction occurs when the light path is distorted by the object's surface normals. To achieve this, we use the Scene Color node. This node samples the rendered scene from the perspective of the camera, effectively "grabbing" what is behind the object.
- Distortion: Connect a
Normal Vectornode to aTransformnode (converting from World to Tangent space). Use this to offset theScreen PositionUVs. By multiplying this offset by a small factor (theRefraction Strength), you cause theScene Colorto look shifted. - Sampling: Feed these distorted UVs into the UV input of the
Scene Colornode. - Output: Plug the resulting color into the
Base Colorslot of your Master Node.
Controlling Transparency
Transparency is managed through the Alpha slot. For glass, a constant value is rarely realistic. Use a Fresnel Effect node to increase opacity at grazing angles (the edges of the glass) while keeping the center more transparent. This simulates the behavior where glass looks more reflective and less clear when viewed from the side.
// Concept: Logic flow for a Refractive Node
float2 refractionUV = ScreenUV + (Normal * RefractionStrength);
float4 sceneColor = SampleSceneColor(refractionUV);
float fresnel = FresnelEffect(Normal, ViewDir, Power);
// Apply alpha based on fresnel for realistic edge-weighting
By balancing the Refraction Strength with an appropriate Alpha value, you create a convincing illusion of depth that reacts dynamically to the objects placed behind your glass meshes.
Key Takeaway: Realistic glass is achieved by combining Fresnel-based alpha masking with a distortion offset applied to the Scene Color sampling node to simulate light refraction.