File size: 5,178 Bytes
d883ffe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_GameObject: {fileID: 0}
  m_Enabled: 1
  m_EditorHideFlags: 0
  m_Script: {fileID: 11500000, guid: 4510294d23d964fe59443526f1ca7c4b, type: 3}
  m_Name: Shaders
  m_EditorClassIdentifier: 
  m_displayName: Shaders
  m_hierarchyName: Shaders
  m_context: {fileID: 11400000, guid: 3080cc436228df445a6aee56abe1ac33, type: 2}
  m_markdownFile: {fileID: 0}
  m_priority: 1007
  m_overrideMarkdownText: '# Custom Hair, Cloth, and Skin Shaders


    We developed
    custom shaders with unique lighting models for scenarios where standard PBR diffuse/specular
    was insufficient. These shaders were created in Shadergraph using a custom lighting
    node, similar to a regular PBR master node. Initially, we used the Unlit Shadergraph
    target, but it lacked some lighting, shadow, and lightmap shader variants. Therefore,
    we created a CustomLit target with these keywords enabled.


    ## Hair Shader


    The
    hair shader is inspired by [Physically Based Hair Shading in Unreal](https://blog.selfshadow.com/publications/s2016-shading-course/karis/s2016_pbs_epic_hair.pdf).
    This technique typically requires an extra texture to define hair strand rotation
    for consistent highlight directions. To enhance performance, we oriented the
    UVs so the strands run lengthwise from left to right, achieving similar results
    at a lower cost.


    We implemented the paper''s specular and environment lighting
    equations but found the multi-scatter equation unsuitable for our needs. Instead,
    we used a simple Lambert diffuse, which also improves performance.


    The
    shader is implemented in HairLighting.hlsl, with most hair-specific logic in
    the "CalculateLighting" function. We simplified vector calculations like cosThetaI/cosThetaR/cosThetaD
    using the normal, avoiding re-derivation from sinThetaI/sinThetaR. This approach
    yields the same results with simpler dot products instead of sqrt/trigonometric
    instructions.


    The result improves upon the standard Lit specular equation.
    The primary specular highlight stretches across hair strands, creating long bands
    instead of focused circles. A secondary transmitted highlight (TT) allows light
    to shine through when behind the hair surface. A shifted, tinted reflection (TRT)
    replicates the metallic/sheen highlight effect often seen in hair.


    The
    hair shader can use regular albedo, normal, roughness, and occlusion maps. However,
    we found a single color and smoothness value, combined with a packed Normal/AO
    map, provided sufficient control. We also included a "micro shadow" technique
    using normal and AO data to calculate small-scale direct light self-shadowing,
    enhancing depth within the hair.


    ## Cloth Shader


    For the cloth shader,
    we replaced the specular term with a "Charlie Sheen" distribution, combined with
    the Ashikmin visibility term described in [Cloth Shading | Krzysztof Narkowicz](https://knarkowicz.wordpress.com/2018/01/04/cloth-shading/).
    This creates a more natural highlight on cloth, simulating individual fiber lighting
    instead of a hard, flat surface. We also replaced the diffuse lighting with a
    wrapped diffuse term for a softer falloff and a configurable subsurface color
    to simulate scattering in shadowed sections, as detailed in section 4.12.2 of
    [Physically Based Rendering in Filament](https://google.github.io/filament/Filament.md.html#materialsystem/clothmodel).


    The
    cloth shader uses regular albedo, roughness, and normal maps. However, roughness
    is interpreted as a distribution of random fibers and their alignment to the
    normal direction.


    ## Skin Shader


    The character skin shader replaces
    the diffuse term with a subsurface scattering approximation known as pre-integrated
    skin shading. A resource on this topic is available here: [Simon''s Tech Blog:
    Pre-Integrated Skin Shading](https://simonstechblog.blogspot.com/2015/02/pre-integrated-skin-shading.html).
    We chose a lookup table over a function fit, requiring a "curvature map" baked
    in Substance Painter to control the effect''s strength. The curvature and dot
    product between light and normal index the lookup table to determine scattered
    diffuse lighting.


    The specular uses a regular GGX function, which produced
    satisfactory results for our purposes.


    We also added a secondary "deep
    scattering" approximation. This involves sampling the shadow map and comparing
    depths with the current pixel to estimate geometry thickness along the light
    source direction. This is added to the diffuse term using a simple transmittance
    formula. While effective in some situations, it is sensitive to shadowmap precision
    and flickering. URP has a hardcoded shadow constant bias, so we added bias and
    normal bias controls for shadowmap sampling to reduce artifacts.

'
  m_overrideMarkdownRoot: .\Documentation/