Unity | HDRP high-definition rendering pipeline study notes: material system Lit shader

Table of contents

1. Lit shader

1. Surface Options

2. Surface Inputs

3. Transparency Inputs

2. HDRP rendering priority


Table of contents

1. Lit shader

1. Surface Options

2. Surface Inputs

3. Transparency Inputs

4. Emission Inputs

2. HDRP rendering priority


       We can divide objects in the real world into opaque objects and transparent objects (including transparent or translucent). In real-time rendering, what we actually simulate is the surface of the object. Of course, when simulating transparent objects, we also need to consider the absorption and refraction phenomena that occur when light passes through the object.

1. Lit shader

1. Surface Options

  • Surface Type

        Surface types are divided into two categories in Lit: Opaque (opaque) and Transparent (transparent).

  • Rendering Pass

        This option appears under selecting the Transparent surface type, and we can choose the following render passes for the current material:

  1. Before Refraction: Render the object associated with the current material before rendering the refraction effect. This means that HDRP will take into account the object associated with the current material into the calculation of refraction when rendering the refraction effect.
  2. Default: Participate in rendering during the default rendering phase.
  3. Low Resolution: After the default rendering stage is completed, render the objects associated with the current material at half the resolution.
  • Blending Mode

        This option appears under selecting a Surface type of Transparent. This option is used to determine which mixing method is used to mix the color of each pixel on the surface of the current transparent material with the background color, so as to obtain the final color value of each pixel on the transparent material.

        If the Base Map is specified and the Alpha channel of the Base Map is pure black (representing complete transparency), then it is meaningless for us to adjust the A (Alpha) value in the color selector. If the Base Map is not specified or the Alpha channel is not included in the Base Map, the transparency of the glass material is controlled by the A (Alpha) value of the color selector. (As shown in the figure below, the surroundings of the Alpha channel of the Base Map are not pure black, so adjusting the A (Alpha) value in the color selector will also affect the surroundings of the object.)

  • Preserve specular lighting (keep highlight lighting information)

This option appears under selecting a Surface type of Transparent. After alpha blending, the intensity of the highlights will be weakened. Enabling this option allows transparent surfaces to maintain the intensity of highlights, which is suitable for expressing the reflection of light on glass or water.

  • Receive Fog

        This option appears under selecting a Surface type of Transparent. Turn this on to make the fog in the scene affect transparent surfaces. If this option is disabled, HDRP will not take the current material into account when calculating scene fog.

  • Back Then Front Rendering (rendering from back to front)

        (Requires the Transparent Backface option to be enabled in the HDRP configuration file): This option appears under selecting the Transparent surface type. After enabling this option, HDRP will use two Draw Calls to render the objects associated with the current material. HDRP will use the first Draw Call to render the triangular faces on the back of the object, and use the second Draw Call to render the front triangular faces.

  • Transparent Depth Prepass (transparent depth preprocessing)

        (Requires the Transparent Depth Prepass option to be enabled in the HDRP configuration file): This option appears under selecting the Transparent surface type. When this option is enabled, HDRP will add the polygon data of the transparent surface to the depth buffer (Depth Buffer). Render ordering can be optimized using the polygon data in these depth buffers. This process is done before lighting, so it helps improve GPU performance. Note that this depth information is written to a separate render pass before rendering the transparency pass, which is then used to handle rendering ordering.

  • Transparent Depth Postpass (transparent depth post-processing)

        (Requires the option Transparent Depth Postpass to be enabled in the HDRP configuration file): This option appears under selecting the Surface Type Transparent. When this option is enabled, HDRP will add the polygon data of the transparent surface to the depth buffer (Depth Buffer) for post-processing (Post Processing). This process will be done before dealing with lighting. If you want to perform post-processing such as Motion Blur (motion blur) and Depth of Field (depth of field) that require depth information, you can enable this option, which is very helpful for the correct calculation of these post-processing effects

  • Transparent Writes Motion Vectors

        (Requires the Motion Vectors option to be enabled in the HDRP configuration file): This option appears under selecting the Transparent surface type. When enabled, HDRP writes the Motion Vector data of transparent objects using this material so that HDRP can calculate post-processing effects such as Motion Blur for transparent objects using the current material.

  • Cull Mode

        Used to determine whether to cull the front (Front) or back (Back) of transparent object meshes.

  • Alpha Clipping (transparency clipping)

        With this option enabled, we can use the alpha channel of the material to control which areas of the surface are rendered and which are not, creating a sharp boundary between transparent and opaque parts.

        Threshold: Use the Threshold value to control the critical value of Alpha. If the Threshold value is set to 0.05, the area with an Alpha value less than or equal to 0.05 will be rendered, and the area with an Alpha value greater than 0.05 will not be rendered.

  • Material Type
  1. The Standard material type can be used to simulate most materials.
  2. Specular Color: Use this material type to generate a colored highlight effect on the surface of the object. Because Specular Color is not using the Metallic workflow, but the Specular workflow, there is no longer a Metallic slider in the Surface Inputs below.
  3. Iridescence: Iridescence, used to make soap bubbles.
  • Receive Decals (Show Decals)

        Enable this option to have the current material display decals, such as white dots on glass.

  • Receive SSR (shown in Screen Space Reflection)

        When this option is enabled, HDRP will take objects associated with the current material into account when calculating screen space reflections.

  • Displacement Mode

        Displacement modes and heightmaps are used to add detail to the model's mesh. When the displacement mode is set, a Height Map option appears in the Surface Inputs section below. (See the details below for the height map) HDRP provides two displacement modes.

  • Vertex displacement: Displaces vertices on the mesh according to the heightmap.
  • Pixel displacement: Displace the pixels on the surface of the model according to the height map.

2. Surface Inputs

        The parameters in Surface Inputs are used to control various properties of the surface of the object, such as color, transparency, highlights, surface details, UVs used for textures, etc.

  • Base Map (base texture)

        Used to control the color and transparency of the surface. If no texture is specified, the object will use the color in the color picker as the surface color; if a texture is specified, the final color of the object's surface is determined by the texture and the color selected by the color picker.

  • Mask Map
The four channels of Mask Map are used to save textures with different purposes

         The textures saved in the four channels of Red, Green, Blue and Alpha are actually grayscale images. The grayscale image provides the value corresponding to each pixel on the final texture (each grayscale image controls different parameters). Pure white corresponds to a maximum value of 1 (with effect), and the darker the color, the smaller the value until it is 0 (without effect) .

        The advantage of saving four textures in the same Mask Map is: because the UV coordinates of these four textures are the same, the renderer only needs to sample once to get the information of up to four textures. Note that it is not necessary to use 4 channels every time when using Mask Map. You can choose one or more channels to use according to your needs.

         If we do not specify Mask Map, the values ​​of the Metallic and Smoothness options are both between 0 and 1. The higher the Metallic value, the stronger the metal reflection on the surface of the object. The higher the value of Smoothness, the smoother the surface of the object, more like a mirror; otherwise, the rougher the surface of the object looks.

        If we specify a Mask Map, sliders will appear for the Metallic Remapping, Smoothness Remapping, and Ambient Occlusion Remapping options.

  1. Metallic is used to control the reflectivity of the metal surface, the higher the value, the stronger the metal reflection. Its value is between 0 and 1. Because we added a Mask Map, HDRP will obtain the grayscale information of the Metallic map in the Red channel to calculate the metal reflection intensity on the surface of the object: pure black corresponds to a value of 0, pure white corresponds to a value of 1, and other grayscales correspond to 0 A value between ~1. As shown in the picture above, what we want to simulate is a ceramic cup. The red channel is a pure black texture, because the value of Metallic is controlled, and pure black corresponds to a value of 0. So no matter how you adjust the Metallic slider on the material interface, the value will always be 0. If the texture color in the red channel is changed to white, the Metallic value provided by the texture is 1. At this time, you can use the Metallic slider to adjust the value between 0 and 1 (at this time, you will see that the bottle will have metal reflections. But what we want to simulate is ceramics, and it is actually wrong to have metal reflections).
  2. The Smoothness Remapping slider can map the grayscale information obtained from the Alpha channel of the Mask Map to the corresponding minimum and maximum value intervals of the slider to control the glossiness of the object surface.
  3. The Ambient Occlusion Remapping slider can map the grayscale information obtained from the Green channel of the Mask Map to the minimum and maximum value intervals corresponding to the slider to control the ambient light occlusion on the surface of the object.
  • Normal Map Space (normal map space) and Normal Map (normal map)

        In Normal Map Space, you can choose TangentSpace (tangent space) or ObjectSpace (object space). The difference between the two normal map spaces is:

  1. TangentSpace can be applied to any type of mesh, including character models whose mesh deforms during animation.
  2. ObjectSpace can be applied to static objects using Planar-mapping (objects whose meshes do not deform). This type of normal map contains not only tangent space normal map information, but also direction data. And because Unity doesn't need to do Transform calculations on it, it saves performance compared to tangent space normal maps.

        We can associate a normal map with the Normal Map to add details to the surface of the object. The intensity of detail information can be controlled through the slider (the value is between 0 and 8). The principle of the normal map to add details to the surface of the object is to use the information stored in the normal map to make the surface "look" with more details by changing the lighting information on the surface of the object. But in essence, no real deformation occurs on the surface of the object.

  • Height Map

        This option appears when the displacement mode is set. A height map is essentially a grayscale image with black and white colors. White areas represent where the affected surface is high; the darker the color, the lower the affected surface. Unlike normal maps, height maps change the area of ​​the affected surface, adding more detail. General height maps are used in conjunction with normal maps.

  • Parameter Amplitude (amplitude)

        This option appears when the displacement mode is set to Pixel displacement. Used to control the strength of the heightmap displacement effect.

  • Iridescence Mask

        Occurs when using the material type Iridescence. You can use a grayscale image here to control the intensity of the rainbow colors. 0 means no iridescence, 1 means the most iridescent effect. We can also directly use a fixed value (between 0 and 1) to control the intensity of the rainbow color of the entire surface.

  • Specular Color

        Occurs when using the Specular Color material type. This option allows you to manually set the Specular Color. The texture associated here allows us to define the specular color at the pixel level. If you choose a color in the color picker, HDRP will multiply this color with every pixel in the texture to get the final highlight color.

  • Energy Conserving Specular Color

        Occurs when using the Specular Color material type. If enabled, HDRP will reduce the diffuse color of the material when the specular effect is too strong, which can make the material look more "physically correct". Because the Energy Conservation (Energy Conservation) code of PBR (Physically Based Rendering) is very important for the correct rendering of object surfaces. This code states that the energy of reflected and scattered light must be less than the energy of light received by the object's surface. 

3. Transparency Inputs

        Below are all parameters related to refraction.

  • Refraction Model

        Here you can choose how HDRP handles refraction:

  1. None: Transparent materials have no refraction behavior.
  2. Box: The algorithm uses a cube-shaped model. A ray enters a plane when it enters a plane, and a ray passes through a plane when it exits. It is suitable for objects such as the hollow glass bottle we explained.
  3. Sphere: The algorithm uses a spherical model, which can generate a refraction effect similar to a magnifying glass. It is suitable for simulating solid transparent objects, such as magnifying glass lenses, glass balls, etc.
  4. Thin: The algorithm uses a cuboid-shaped model. Unlike the Box model, the thickness of the Thin model is defined as 5cm. Can be used to simulate glass on windows.
  • Index Of Refraction

        Used to control the strength of the refraction effect. The larger the value, the stronger the refraction effect. (Refractive index = speed of light in vacuum/speed of light in current transparent material) The refractive index of various substances can be referred to: https://zh.wikipedia.org/zh-cn/refractive index .

  • Thickness (object thickness)

        You can use a thickness map (Thickness Map) to control the thickness of the transparent material (based on the pixel level). If you don't use a thickness map, you can also use a slider to control the overall thickness of transparent objects. Note: This option does not appear in the Thin refraction model, because the thickness is specified as 5cm in the Thin model.

  • Transmittance Color

        Transparent objects with refractive properties can tint the light passing through the object. Here you can specify a texture (on a pixel-by-pixel basis) to tint passing light, or use the color picker alone to choose an overall color. If both methods are used, the final light color is determined by both the texture's color and the color selected from the color picker.

4.  Emission Inputs

        A mesh can be turned into a light source controlled by an emissive material.

2. HDRP rendering priority

        The rendering pipeline renders objects farthest from the camera first, and objects closest to the camera last. In HDRP, the rendering order of objects in the scene will be sorted according to the Sorting Priority of the material (Material) and the Priority value of the rendering component (Mesh Renderer). The larger the value, the further back the rendering is, and the closer it is to the camera.

        The priority used by HDRP to render and sort transparent objects: (from strong to weak) the depth information obtained by the material from Depth Write → the Sorting Priority value of the material → the Priority value of the Mesh Renderer component → the distance from the camera to the object.

Guess you like

Origin blog.csdn.net/weixin_39766005/article/details/131422647