Skip to content

Commit 25bd13e

Browse files
fix: SRP Batcher compatibility
1 parent 0485927 commit 25bd13e

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

render-dev/Assets/Shaders/Toon Lit.shader

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
"RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"
2222
}
2323
LOD 100
24-
//Render pass
24+
2525
Pass
2626
{
27+
Name "Base"
2728
Tags
2829
{
2930
"LightMode" = "UniversalForward"
@@ -35,13 +36,15 @@
3536
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
3637
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
3738

38-
CBUFFER_START(UnityPerMaterial)
3939
TEXTURE2D(_MainTex);
4040
SAMPLER(sampler_MainTex);
41+
CBUFFER_START(UnityPerMaterial)
4142
float4 _BaseColor;
4243
float4 _ShadowColor;
4344
float1 _ShadowRange;
4445
float1 _ShadowSmooth;
46+
float4 _OutlineColor;
47+
float1 _OutlineWidth;
4548
CBUFFER_END
4649

4750
struct app_data
@@ -78,18 +81,19 @@
7881
{
7982
const float4 shadow_coords = TransformWorldToShadowCoord(vertex_data.world_position);
8083
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;
8285
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);
8488
const float1 half_lambert_shadow = dot(vertex_data.world_normal, main_light_direction) * 0.5 + 0.5;
8589

8690
const float4 base_texture_color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, vertex_data.uv);
8791

8892
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;
9094

9195
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;
9397
return color;
9498
}
9599
ENDHLSL
@@ -98,6 +102,7 @@
98102
//Outline pass
99103
Pass
100104
{
105+
Name "Outline"
101106
Tags
102107
{
103108
"LightMode" = "SRPDefaultUnlit"
@@ -107,9 +112,14 @@
107112
#pragma vertex vert
108113
#pragma fragment frag
109114
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
115+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
110116
#include "./Build-in.hlsl"
111117

112118
CBUFFER_START(UnityPerMaterial)
119+
float4 _BaseColor;
120+
float4 _ShadowColor;
121+
float1 _ShadowRange;
122+
float1 _ShadowSmooth;
113123
float4 _OutlineColor;
114124
float1 _OutlineWidth;
115125
CBUFFER_END
@@ -135,7 +145,8 @@
135145
float4 vertex_position = position_inputs.positionCS;
136146

137147
//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;
139150
const float3x3 rotation = float3x3(app_data.object_tangent.xyz, bi_normal, app_data.object_normal.xyz);
140151

141152
//Remapping [0,1] to [-1,1]

0 commit comments

Comments
 (0)