|
21 | 21 | "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" |
22 | 22 | } |
23 | 23 | LOD 100 |
24 | | - //Render pass |
| 24 | + |
25 | 25 | Pass |
26 | 26 | { |
| 27 | + Name "Base" |
27 | 28 | Tags |
28 | 29 | { |
29 | 30 | "LightMode" = "UniversalForward" |
|
35 | 36 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" |
36 | 37 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" |
37 | 38 |
|
38 | | - CBUFFER_START(UnityPerMaterial) |
39 | 39 | TEXTURE2D(_MainTex); |
40 | 40 | SAMPLER(sampler_MainTex); |
| 41 | + CBUFFER_START(UnityPerMaterial) |
41 | 42 | float4 _BaseColor; |
42 | 43 | float4 _ShadowColor; |
43 | 44 | float1 _ShadowRange; |
44 | 45 | float1 _ShadowSmooth; |
| 46 | + float4 _OutlineColor; |
| 47 | + float1 _OutlineWidth; |
45 | 48 | CBUFFER_END |
46 | 49 |
|
47 | 50 | struct app_data |
|
78 | 81 | { |
79 | 82 | const float4 shadow_coords = TransformWorldToShadowCoord(vertex_data.world_position); |
80 | 83 | const Light main_light = GetMainLight(shadow_coords); |
81 | | - const float1 main_light_color = main_light.color; |
| 84 | + const float3 main_light_color = main_light.color; |
82 | 85 | const float3 main_light_direction = normalize(main_light.direction); |
83 | | - const float3 view_direction = normalize(_WorldSpaceCameraPos.xyz - vertex_data.world_position.xyz); |
| 86 | + |
| 87 | + //const float3 view_direction = normalize(_WorldSpaceCameraPos.xyz - vertex_data.world_position.xyz); |
84 | 88 | const float1 half_lambert_shadow = dot(vertex_data.world_normal, main_light_direction) * 0.5 + 0.5; |
85 | 89 |
|
86 | 90 | const float4 base_texture_color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, vertex_data.uv); |
87 | 91 |
|
88 | 92 | const float1 ramp_smooth = smoothstep(0, _ShadowSmooth, half_lambert_shadow - _ShadowRange); |
89 | | - const float3 diffuse_color = lerp(_ShadowColor, _BaseColor, ramp_smooth); |
| 93 | + const float3 diffuse_color = lerp(_ShadowColor, _BaseColor, ramp_smooth.x).xyz; |
90 | 94 |
|
91 | 95 | float4 color = 1; |
92 | | - color.rgb = diffuse_color * base_texture_color * main_light_color; |
| 96 | + color.rgb = diffuse_color * base_texture_color.rgb * main_light_color; |
93 | 97 | return color; |
94 | 98 | } |
95 | 99 | ENDHLSL |
|
98 | 102 | //Outline pass |
99 | 103 | Pass |
100 | 104 | { |
| 105 | + Name "Outline" |
101 | 106 | Tags |
102 | 107 | { |
103 | 108 | "LightMode" = "SRPDefaultUnlit" |
|
107 | 112 | #pragma vertex vert |
108 | 113 | #pragma fragment frag |
109 | 114 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" |
| 115 | + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" |
110 | 116 | #include "./Build-in.hlsl" |
111 | 117 |
|
112 | 118 | CBUFFER_START(UnityPerMaterial) |
| 119 | + float4 _BaseColor; |
| 120 | + float4 _ShadowColor; |
| 121 | + float1 _ShadowRange; |
| 122 | + float1 _ShadowSmooth; |
113 | 123 | float4 _OutlineColor; |
114 | 124 | float1 _OutlineWidth; |
115 | 125 | CBUFFER_END |
|
135 | 145 | float4 vertex_position = position_inputs.positionCS; |
136 | 146 |
|
137 | 147 | //rotation is the matrix of model space to tangent space |
138 | | - float3 bi_normal = cross(app_data.object_normal, app_data.object_tangent.xyz) * app_data.object_tangent.w; |
| 148 | + float3 bi_normal = cross(app_data.object_normal.xyz, app_data.object_tangent.xyz) * app_data. |
| 149 | + object_tangent.w; |
139 | 150 | const float3x3 rotation = float3x3(app_data.object_tangent.xyz, bi_normal, app_data.object_normal.xyz); |
140 | 151 |
|
141 | 152 | //Remapping [0,1] to [-1,1] |
|
0 commit comments