Eye Shader
The Eye Shader is your starting point for rendering eyes in the High Definition Render Pipeline (HDRP). Use it to exhibit important phenomena like cornea refraction, caustics, pupil dilation, limbal darkening, and subsurface scattering to bring your characters to life.
Under the hood, the Eye shader is a pre-configured Shader Graph. To use the Eye Shader Graph, you need to use the sample Eye Prefab in your project. To learn more about the Eye shader implementation, or to create your own Eye shader variant, see the Shader Graph documentation about the Eye Master Stack.
Eye anatomy
When rendering eyes, it’s helpful to become familiar with their biological structure to produce a realistic outcome.
- The Iris is the flat, colored, ring that surrounds the Pupil. It sits underneath the Cornea.
- The Cornea is the transparent lens on top of the Iris. It reflects and focuses light into the Pupil.
- The Pupil is the opening in the Iris that allows light to pass into the eye and reach the retina.
- The Limbus, or the Limbal Ring, is the darkened bordering region between the Cornea and the Sclera.
- The Sclera is the opaque, protective outer layer of the eye.
Creating an Eye Material
New Materials in HDRP use the Lit Shader by default. To create an Eye Material:
- In the Unity Editor, navigate to your Project's Asset window.
- Right-click the Asset Window and select Create > Material. This adds a new Material to your Unity Project’s Asset folder.
- Click the Shader drop-down at the top of the Material Inspector, and select HDRP > Eye.
This Eye Material uses the sample Eye Shader Graph. You can only use this Material with the built-in Eye mesh in the Eye Prefab. To create a new Eye Shader graph from scratch, see Eye Matster Stack.
Eye Prefab
To use the sample Eye Shader Graph, you need to use the Eye Prefab from HDRP’s sample Eye scene in your own project. This is because the Eye Shader Graph is dependent on vertex positions in the sample eye mesh which exists in the Eye Prefab. Because of this, HDRP’s Eye Shader Graph isn’t compatible with custom meshes.
To use the sample Eye Shader Graph:
- Install the Material Samples project.
- Open the Eye sample scene.
- Import the Eye Prefab into your project.
You can also create your own custom Textures for the Eye Shader Graph. For more information see Eye Textures.
Install the Material Samples project
HDRP includes four sample eyes of different sizes in the Eye sample scene. This scene exists in HDRP’s Material Samples. To install the Material Samples:
- Open the Package Manager window (Window > Package Manager).
- Open the Packages menu and select the In Project context.
- Select the High Definition RP package.
- Expand the Samples dropdown.
- Next to Material Samples, select Import.
Open the Eye sample scene
To open the Eye sample scene:
- In the Project window, go to the Assets > Samples > High Definition RP. Open the folder that matches your current Unity version number, then open Material Samples.
- Right-click the Eye scene and select Open.
Import the Eye Prefab into your project
To import one of the HDRP sample Eye Prefabs into your scene:
- Open your own scene from the Hierarchy window (if you don’t have a scene, go to Assets > Scene and give it a name in the Project window).
- In the Project window, go to Assets > Samples > High Definition RP. Open the folder that matches your current Unity version number, then open Material Samples > Prefabs.
- Click and drag one of the four Eye Variant Prefabs into the Hierarchy window.
Tip: When the eye appears in your scene, it might have a green tint. To remove this green tint, fix the Eye Material’s diffusion profiles:
- Select the Eye Prefab in the Hierarchy window.
- In the Inspector window, find the Material that begins with M_EyeSG and open the dropdown underneath it.
- Expand Exposed Properties > Sclera
- In the information box below Sclera Diffusion Profile, click Fix.
- Repeat these steps for the Iris Diffusion Profile in the Inspector under Exposed Properties. Inspector window with the Sclera Diffusion Profile fix option highlighted.
Eye Textures
You must provide seperate Texture maps for the Iris and Sclera. This is because of the way that properties for subsurface scattering, limbal ring, smoothness, and other surface information blends between the Iris and Sclera. This means you need to create a Sclera map with no Iris information, and an Iris map with no Sclera information:
Properties
Surface Options
Surface Options control the overall look of your Material's surface and how Unity renders the Material on screen.
Property | Description | ||
---|---|---|---|
Surface Type | Specifies whether the material supports transparency or not. Materials with a Transparent Surface Type are more resource intensive to render than Materials with an Opaque Surface Type. Depending on the option you select, HDRP exposes more properties. The options are: • Opaque: • Transparent: Simulates a translucent Material that light can penetrate, such as clear plastic or glass. For more information about the feature and for the list of properties each Surface Type exposes, see the Surface Type documentation. |
||
Rendering Pass | Specifies the rendering pass that HDRP processes this material in. • Before Refraction: Draws the GameObject before the refraction pass. This means that HDRP includes this Material when it processes refraction. To expose this option, select Transparent from the Surface Type drop-down. • Default: Draws the GameObject in the default opaque or transparent rendering pass pass, depending on the Surface Type. • Low Resolution: Draws the GameObject in half resolution after the Default pass. • After post-process: For Unlit Materials only. Draws the GameObject after all post-processing effects. |
||
Blending Mode | Specifies the method HDRP uses to blend the color of each pixel of the material with the background pixels. The options are: • Alpha: Uses the Material’s alpha value to change how transparent an object is. 0 is fully transparent. 1 appears fully opaque, but the Material is still rendered during the Transparent render pass. This is useful for visuals that you want to be fully visible but to also fade over time, like clouds. • Additive: Adds the Material’s RGB values to the background color. The alpha channel of the Material modulates the intensity. A value of 0 adds nothing and a value of 1 adds 100% of the Material color to the background color. • Premultiply: Assumes that you have already multiplied the RGB values of the Material by the alpha channel. This gives better results than Alpha blending when filtering images or composing different layers. This property only appears if you set Surface Type to Transparent. |
||
Preserve Specular Lighting | Indicates whether to make alpha blending not reduce the intensity of specular highlights. This preserves the specular elements on the transparent surface, such as sunbeams shining off glass or water. This property only appears if you set Surface Type to Transparent. |
||
Sorting Priority | Allows you to change the rendering order of overlaid transparent surfaces. For more information and an example of usage, see the Material sorting documentation. This property only appears if you set Surface Type to Transparent. |
||
Receive Fog | Indicates whether fog affects the transparent surface. When disabled, HDRP doesn't take this material into account when it calculates the fog in the Scene. | ||
- Back Then Front Rendering |
Indicates whether HDRP renders this material in two separate draw calls. HDRP renders the back face in the first draw call and the front face in the second. |
||
Transparent Depth Prepass | Indicates whether HDRP adds polygons from the transparent surface to the depth buffer to improve their sorting. HDRP performs this operation before the lighting pass and this process improves GPU performance. | ||
- Transparent Depth Postpass |
Indicates whether HDRP adds polygons to the depth buffer that post-processing uses. HDRP performs this operation before the lighting pass. Enabling this feature is useful if you want to use post-processing effects that use depth information, like motion blur or depth of field. |
||
Transparent Writes Motion Vectors | Indicates whether HDRP writes motion vectors for transparent GameObjects that use this Material. This allows HDRP to process effects like motion blur for transparent objects. For more information on motion vectors, see the motion vectors documentation. This property only appears if you set Surface Type to Transparent. |
||
Depth Write | Indicates whether HDRP writes depth values for GameObjects that use this material. | ||
Depth Test | Specifies the comparison function HDRP uses for the depth test. | ||
Cull Mode | Specifies the face to cull for GameObjects that use this material. The options are: • Front: Culls the front face of the mesh. • Back: Culls the back face of the mesh. This property only appears if you disable Double Sided. |
||
Alpha Clipping |
Indicates whether this material acts like a Cutout Shader. |
||
- Threshold |
The alpha value limit HDRP uses to determine whether to render each pixel. If the alpha value of the pixel is equal to or higher than the limit then HDRP renders the pixel. If the value is lower than the limit then HDRP does not render the pixel. The default value is 0.5. |
||
- Use Shadow Threshold |
Indicates whether HDRP uses another threshold value for alpha clipping shadows. |
||
- - Shadow Threshold |
The alpha value limit that HDRP uses to determine whether it should render shadows for a pixel. |
||
- Alpha to Mask |
Indicates whether to turn on alpha-to-coverage. If your Project uses MSAA, alpha-to-coverage modifies the multi-sample coverage mask proportionally to the pixel shader result alpha value. This is typically used for anti-aliasing vegetation and other alpha-tested shaders. |
||
- Prepass Threshold |
The alpha value limit HDRP uses for the transparent depth prepass. This works in the same way as the main Threshold property described above. |
||
- Postpass Threshold |
The alpha value limit HDRP uses for the transparent depth postpass. This works in the same way as the main Threshold property described above. |
||
Double-Sided GI | Determines how HDRP handles a material with regards to Double Sided GI. When selecting Auto, Double-Sided GI is enabled if the material is Double-Sided; otherwise selecting On or Off respectively enables or disables double sided GI regardless of the material's Double-Sided option. When enabled, the lightmapper accounts for both sides of the geometry when calculating Global Illumination. Backfaces aren't rendered or added to lightmaps, but get treated as valid when seen from other objects. When using the Progressive Lightmapper backfaces bounce light using the same emission and albedo as frontfaces. (Currently this setting is only available when baking with the Progressive Lightmapper backend.). | ||
Normal Mode | Specifies the mode HDRP uses to calculate the normals for back facing geometry. • Flip: The normal of the back face is 180° of the front facing normal. This also applies to the Material which means that it looks the same on both sides of the geometry. • Mirror: The normal of the back face mirrors the front facing normal. This also applies to the Material which means that it inverts on the back face. This is useful when you want to keep the same shapes on both sides of the geometry, for example, for leaves. • None: The normal of the back face is the same as the front face. This property only appears if you enable Double-Sided. |
||
Double Sided | Indicates whether HDRP renders both faces of the polygons in your geometry. For more information about the feature and for the list of properties this feature exposes, see the Double-Sided documentation. | ||
Material Type | Specifies a type for the material. This allows you to customize the material with different settings depending on the type you select. The options are: • Subsurface Scattering: Applies the subsurface scattering workflow to the material. Subsurface scattering simulates the way light interacts with and penetrates translucent objects, such as skin or plant leaves. When light penetrates the surface of a subsurface scattering material, it scatters and blurs before exiting the surface at a different point. • Standard: Applies the basic metallic Shader workflow to the material. This is the default Material Type. • Anisotropy: Applies the anisotropic workflow to the material. The highlights of Anisotropic surfaces change in appearance as you view the material from different angles. Use this Material Type to create materials with anisotropic highlights. For example, brushed metal or velvet. • Iridescence: Applies the Iridescence workflow to the material. Iridescent surfaces appear to gradually change color as the angle of view or angle of illumination changes. Use this Material Type to create materials like soap bubbles, iridescent metal, or insect wings. • Specular Color: Applies the Specular Color workflow to the material. Use this Material Type to create Materials with a coloured specular highlight. This is similar to the built-in Specular Shader. • Translucent: Applies the Translucent workflow to the material. Use this Material Type, and a thickness map, to simulate a translucent material. In contrast to Subsurface Scattering materials, Translucent materials do not blur light that transmits through the material. For more information about the feature and for the list of properties each Material Type exposes, see the Material Type documentation. |
||
Transmission |
Indicates whether HDRP simulates the translucency of the material using a thickness map. Configure subsurface scattering and transmission settings using a Diffusion Profile. For more information, see documentation on Subsurface Scattering. |
||
Receive Decals | Indicates whether HDRP can draw decals on this material’s surface. | ||
Receive SSR | Indicates whether HDRP includes this material when it processes the screen space reflection pass. This property only appears if you set Surface Type to Opaque. |
||
Receive SSR Transparent | Indicates whether HDRP includes this material when it processes the screen space reflection pass. This property only appears if you set Surface Type to Transparent. |
||
Geometric Specular AA | Indicates whether HDRP performs geometric anti-aliasing on this material. This modifies the smoothness values on the surfaces of curved geometry to remove specular artifacts. For more information about the feature and for the list of properties this feature exposes, see the Geometric Specular Anti-aliasing documentation. |
||
- Screen Space Variance | The strength of the geometric specular anti-aliasing effect between 0 and 1. Higher values produce a blurrier result with less aliasing. This property only appears if you enable Geometric Specular AA. |
||
- Threshold | The maximum value for the offset that HDRP subtracts from the smoothness value to reduce artifacts. This property only appears if you enable Geometric Specular AA. |
||
Displacement Mode | Specifies the method HDRP uses to alter the height of the Material’s surface. The options are: • None: Applies no displacement to the material. • Vertex displacement: Displaces the mesh's vertices according to the Height Map. • Pixel displacement: Displaces the pixels on the mesh surface according to the Height Map. For more information about the feature and for the list of properties each Displacement Mode exposes, see the Displacement Mode documentation. |
||
- Lock With Object Scale | Indicates whether to alter the height of the displacement using the Scale of the Transform. This allows you to preserve the ratio between the amplitude of the displacement and the Scale of the Transform. This property only appears if you set Displacement Mode to Vertex Displacement or Pixel Displacement. |
||
- Lock With Height Map Tiling Rate | Indicates whether to alter the amplitude of the displacement using the tiling of the Height Map. This allows you to preserve the ratio between the amplitude of the displacement and the scale of the Height Map Texture. This property only appears if you set Displacement Mode to Vertex Displacement or Pixel Displacement. |
||
- Minimum Steps | The minimum number of Texture samples which Unity performs to process pixel displacement. This property only appears if you set Displacement Mode to Pixel Displacement. |
||
- Maximum Steps | The maximum number of Texture samples which Unity performs to process pixel displacement. This property only appears if you set Displacement Mode to Pixel Displacement. |
||
- Fading Mip Level Start | The mip level at which the pixel displacement effect begins to fade out. This property only appears if you set Displacement Mode to Pixel Displacement. |
||
- Primitive Length | The length of the mesh (in meters) on which Unity applies the displacement mapping. This property only appears if you set Displacement Mode to Pixel Displacement. |
||
- Primitive Width | The width of the mesh (in meters) on which Unity applies the displacement mapping. This property only appears if you set Displacement Mode to Pixel Displacement. |
||
- Depth Offset | Indicates whether HDRP modifies the depth buffer according to the displacement. This allows effects that use the depth buffer (Contact Shadows for example) to capture pixel displacement details. This property only appears if you set Displacement Mode to Pixel Displacement. |
Exposed Properties
Sclera
Property | Description |
---|---|
Sclera Texture | Assign a Texture that controls color of the Sclera. |
Sclera Smoothness | Sets the smoothness of the Sclera. |
Sclera Normal | Assign a Texture that defines the normal map for the Sclera. |
Sclera Normal Strength | Modulates the Sclera normal intensity between 0 and 8. |
Sclera Diffusion Profile | Sets a Diffusion Profile, controlling the Subsurface Scattering properties of the Sclera. |
Iris
Property | Description |
---|---|
Iris Texture | Assign a Texture that controls color of the eye’s Iris. |
Iris Clamp Color | Sets the color that will be used if the refraction ray reached the inside of the Cornea |
Iris Offset | Sets the offset of the Iris placement, useful since real world eyes are never symmetrical and centered. |
Iris Normal | Assign a Texture that defines the normal map for the eye’s Iris. |
Iris Normal Strength | Modulates the Iris’ normal intensity between 0 and 8. |
Iris Diffusion Profile | Sets a Diffusion Profile, controlling the Subsurface Scattering properties of the Iris. |
Pupil
Property | Description |
---|---|
Pupil Radius | Sets the radius of the Pupil in the Iris Map as a percentage. |
Pupil Debug Mode | When enabled, displays a debug mode that allows you to calibrate the desired Pupil Radius for your Iris Map. For proper calibration, ensure that the Iris Offset is 0, the Pupil Aperture is 0.5 (the neutral position) and then the white circle must be inside the iris pattern. See the following screenshot for an example: |
Pupil Aperture | Sets the state of the pupil’s aperture, 0 being the smallest aperture (Min Pupil Aperture) and 1 the widest aperture (Max Pupil Aperture). |
Minimal Pupil Aperture | Sets the minimum pupil aperture value. |
Maximal Pupil Aperture | Sets the maximum pupil aperture value. |
Limbal Ring
Property | Description |
---|---|
Limbal Ring Size Iris | Sets the relative size of the Limbal Ring in the Iris. |
Limbal Ring Size Sclera | Sets the relative size of the Limbal Ring in the Sclera. |
Limbal Ring Fade | Sets the fade out strength of the Limbal Ring. |
Limbal Ring Intensity | Sets the darkness of the Limbal Ring. |
Cornea
Property | Description |
---|---|
Cornea Smoothness | Sets the smoothness of the Cornea. |
Geometry
Property | Description |
---|---|
Mesh Scale | The Eye Shader expects a Mesh of size 1 in Object space. If needed, set this parameter to compensate the mesh size. This is independant of the scale on the Transform component. |
Advanced Options
Property | Description |
---|---|
Enable GPU Instancing | Enable the checkbox to tell HDRP to render Meshes with the same geometry and Material in one batch when possible. This makes rendering faster. HDRP cannot render Meshes in one batch if they have different Materials, or if the hardware does not support GPU instancing. For example, you cannot static-batch GameObjects that have an animation based on the object pivot, but the GPU can instance them. |
Baked Emission | Indicates whether the emission color affects global illumination. |
Motion Vectors For Vertex Animation | Indicates whether HDRP writes motion vectors for GameObjects that use vertex animation. This removes the ghosting that vertex animation can cause. |
Add Precomputed Velocity |
Indicates whether to use precomputed velocity information stored in an Alembic file. |