Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the rendering of simulated stockings in Unity

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to achieve simulation stockings rendering in Unity, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to know it.

Let's go

Since it is based on PBR, create a new Surface Shader file, and then delete it slightly as needed:

Shader "Custom/NewSurfaceShader" {Properties {_ NormalTex ("Normal", 2D) = "bump" {} _ Smoothness ("Smoothness", Range (0Power1)) = 0.5} SubShader {Tags {"RenderType" = "Opaque"} CGPROGRAM # pragma surface surf Standard fullforwardshadows # pragma target 3.0 sampler2D _ NormalTex; struct Input {float2 uv_NormalTex;} Half _ Smoothness; fixed4 _ Color; void surf (Input IN, inout SurfaceOutputStandard o) {o.Albedo = 1; o.Normal = UnpackNormal (tex2D (_ NormalTex, IN.uv_NormalTex)); o.Metallic = 0; o.Smoothness = _ Smoothness; o.Alpha = 1;} ENDCG} FallBack "Diffuse"}

Some unwanted attributes such as metallicity are deleted and normals are added.

On this basis, let's start our journey of exploring silk stockings.

Calculate

The density of stockings defines a property called Density, which ranges from 0 (almost no fiber) to 1 (completely covered by fibers). Provide color to the Albedo channel according to the density, the higher the density, the more the color of the stockings, and the lower the color of the skin.

Three steps are required to calculate the sparse density:

The effect of Daniel value on the overall density.

Affected by the good elasticity of stockings, a grayscale map is needed to control the degree of stretching in different areas. the larger the stretch, the lower the thinning density.

Under the influence of the observer's line of sight, the smaller the angle between the stockings plane and the observer's line of sight, the greater the thinning density. It is called edge degree influence.

For these points, we define several attributes:

Properties {_ Denier ("Denier", Range (5120)) = 25.0 _ DenierTex ("Density Texture", 2D) = "black" {} [Enum (Strong,6,Normal,12,Weak,20)] _ RimPower ("RimPower", float) = 12 _ SkinTint ("Skin Color Tint", Color) = (1Jing 0.9, Color) _ SkinTex ("Skin Color", 2D) = "white" {} _ StockingTint ("Stocking Color Tint", Color) = (1mem1) 1Magol 1) _ StockingTex ("Stocking Color", 2D) = "white" {}} (1), (2) Daniel value and stretch degree map float denier = (_ Denier-5) / 115 Float density = denier * (1-tex2D (_ DenierTex, IN.uv_DenierTex))

Normalize the value of _ Denier. _ DenierTex is a grayscale map, and the lighter it is, the more stretched the stockings are, and the thinner the fibers will show more skin color. Multiply the two.

As an example, it is generally believed that the knee and thigh will be pulled more strongly the closer to the base.

_ Denier is generally only used for adjustment when there is no _ DenierTex map. When using _ DenierTex, make sure that the value of _ Denier is the maximum (120) to restore the effect of the map correctly.

(3) calculation of edge degree

There is a very common effect called Rim Lighting, which is simply the inner glow effect at the edge of the model, and we can refer to the code that calculates the degree of edge. The relevant code can be found in the Surface Shader examples of the Unity official documentation.

Rewrite according to your own needs:

Float rim = pow (1-dot (normalize (IN.viewDir), o.Normal), _ RimPower / 10)

The quantitative product of line of sight direction and normal direction is calculated by point multiplication (dot). When the direction of the line of sight is completely opposite to the normal direction, that is, the most central part of the stockings, the value is 1, while when the direction of the outermost line of sight is perpendicular to the normal direction, the value is 0. Because we define the edge degree, it should be the higher the edge value, and subtract 1 from it to get the correct value. Finally, the numerical value is carried out to the power of (_ RimPower / 10). In practical application, the _ RimPower is adjusted according to the effect to make the edge degree more in line with the reality.

Final blend color

First of all, you need to calculate the skin color (SkinColor) and stockings color (StockingColor), which is very simple without much explanation.

Float4 skinColor = tex2D (_ SkinTex, IN.uv_SkinTex) * _ SkinTint;float4 stockingColor = tex2D (_ StockingTex, IN.uv_StockingTex) * _ StockingTint

Simply mix the two colors according to the thinning density, the higher the thinning density, the more silk stockings color, the lower the skin color, a very simple lerp.

Lerp (skinColor, stockingColor, density) Complete ShaderShader "Custom/Stocking" {Properties {_ Denier ("Denier", Range (5120)) = 25.0 _ DenierTex ("Density Texture", 2D) = "black" {} [Enum (Strong,6,Normal,12,Weak,20)] _ RimPower ("RimPower", float) = 12 _ SkinTint ("Skin Color Tint", Color) = (1Jing 0.9, 0.8) _ SkinTex ("Skin Color") 2D) = "white" {} _ StockingTint ("Stocking Color Tint", Color) = (1LJE 1Jet 1) _ StockingTex ("Stocking Color", 2D) = "white" {} _ NormalTex ("Normal", 2D) = "bump" {} _ Smoothness ("Smoothness") Range (0mem1) = 0.1} SubShader {Tags {"RenderType" = "Opaque"} CGPROGRAM # pragma surface surf Standard fullforwardshadows # pragma target 3.0 struct Input {float2 uv_SkinTex Float2 uv_StockingTex; float2 uv_DenierTex; float2 uv_NormalTex; float3 viewDir;}; float _ RimPower; float _ Denier; float _ Smoothness; float4 _ SkinTint; float4 _ StockingTint; sampler2D _ DenierTex; sampler2D _ SkinTex; sampler2D _ StockingTex; sampler2D _ NormalTex Void surf (Input IN, inout SurfaceOutputStandard o) {o.Normal = UnpackNormal (tex2D (_ NormalTex, IN.uv_NormalTex)); float4 skinColor = tex2D (_ SkinTex, IN.uv_SkinTex) * _ SkinTint; float4 stockingColor = tex2D (_ StockingTex, IN.uv_StockingTex) * _ StockingTint; float rim = pow (1-dot (normalize (IN.viewDir), o.Normal), _ RimPower / 10) Float denier = (_ Denier-5) / 115; float density = max (rim, (denier * (1-tex2D (_ DenierTex, IN.uv_DenierTex); o.Albedo = lerp (skinColor, stockingColor, density); o.Metallic = 0; o.Smoothness = _ Smoothness } ENDCG} FallBack "Diffuse"} Post-processing screen space subsurface scattering (SSSSS)

SSSSS you may not know, but you should have heard of SSS, which is often referred to as 3s material. This is found on Github, using screen space to achieve the SSS effect.

Finally, it is also necessary to use Unity's official Post Processing Stack to adjust the picture.

Link:

Custom Phase Screen-Space Subsurface Scattering

Post Processing Stack

Final effect

Thank you for reading this article carefully. I hope the article "how to realize the rendering of simulated stockings in Unity" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report