diff options
| author | yum <yum.food.vr@gmail.com> | 2025-03-17 19:02:12 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-03-17 19:18:16 -0700 |
| commit | 1f96ed7dd57831f0d4c817dacebb1ecd2dfcca9f (patch) | |
| tree | 6583bf70ce0d2f5547121b629335b26e4bfc5b3e | |
| parent | 0bdd12598e22932d14fb71b16f9ad840d544d12d (diff) | |
converting decals to static branching
and add a shit ton of features
and add 3 more slots, for a total of 4
| -rw-r--r-- | 2ner.cginc | 19 | ||||
| -rw-r--r-- | 2ner.shader | 146 | ||||
| -rw-r--r-- | decals.cginc | 283 | ||||
| -rw-r--r-- | features.cginc | 24 | ||||
| -rw-r--r-- | globals.cginc | 63 | ||||
| -rw-r--r-- | interpolators.cginc | 3 | ||||
| -rw-r--r-- | yum_pbr.cginc | 12 |
7 files changed, 496 insertions, 54 deletions
@@ -24,28 +24,28 @@ v2f vert(appdata v) { return (v2f) (0.0/0.0);
#endif
#if defined(MASKED_STENCIL1_PASS)
- float masked_stencil1_mask = _Masked_Stencil1_Mask.SampleLevel(linear_repeat_s, v.uv01, 0);
+ float masked_stencil1_mask = _Masked_Stencil1_Mask.SampleLevel(linear_repeat_s, v.uv0, 0);
[branch]
if (masked_stencil1_mask < 0.5) {
return (v2f) (0.0/0.0);
}
#endif
#if defined(MASKED_STENCIL2_PASS)
- float masked_stencil2_mask = _Masked_Stencil2_Mask.SampleLevel(linear_repeat_s, v.uv01, 0);
+ float masked_stencil2_mask = _Masked_Stencil2_Mask.SampleLevel(linear_repeat_s, v.uv0, 0);
[branch]
if (masked_stencil2_mask < 0.5) {
return (v2f) (0.0/0.0);
}
#endif
#if defined(MASKED_STENCIL3_PASS)
- float masked_stencil3_mask = _Masked_Stencil3_Mask.SampleLevel(linear_repeat_s, v.uv01, 0);
+ float masked_stencil3_mask = _Masked_Stencil3_Mask.SampleLevel(linear_repeat_s, v.uv0, 0);
[branch]
if (masked_stencil3_mask < 0.5) {
return (v2f) (0.0/0.0);
}
#endif
#if defined(MASKED_STENCIL4_PASS)
- float masked_stencil4_mask = _Masked_Stencil4_Mask.SampleLevel(linear_repeat_s, v.uv01, 0);
+ float masked_stencil4_mask = _Masked_Stencil4_Mask.SampleLevel(linear_repeat_s, v.uv0, 0);
[branch]
if (masked_stencil4_mask < 0.5) {
return (v2f) (0.0/0.0);
@@ -68,7 +68,7 @@ v2f vert(appdata v) { return (v2f) (0.0/0.0);
}
#if defined(_OUTLINE_MASK)
- float thickness = _Outline_Mask.SampleLevel(linear_repeat_s, v.uv01, 0);
+ float thickness = _Outline_Mask.SampleLevel(linear_repeat_s, v.uv0, 0);
thickness = (_Outline_Mask_Invert == 0 ? thickness : 1 - thickness);
#else
float thickness = 1;
@@ -122,7 +122,8 @@ v2f vert(appdata v) { o.pos = UnityObjectToClipPos(v.vertex);
#endif
- o.uv01 = v.uv01;
+ o.uv01.xy = v.uv0;
+ o.uv01.zw = v.uv1;
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
o.objPos = v.vertex;
o.eyeVec.xyz = normalize(o.worldPos - _WorldSpaceCameraPos);
@@ -134,7 +135,7 @@ v2f vert(appdata v) { o.binormal = cross(o.normal, o.tangent) * v.tangent.w *
unity_WorldTransformParams.w;
- UNITY_TRANSFER_LIGHTING(o, v.uv1);
+ UNITY_TRANSFER_LIGHTING(o, v.uv0);
UNITY_TRANSFER_FOG_COMBINED_WITH_EYE_VEC(o, o.pos);
#if defined(SHADOW_CASTER_PASS)
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o);
@@ -201,7 +202,7 @@ float4 frag(v2f i #if defined(FORWARD_BASE_PASS) || defined(FORWARD_ADD_PASS)
applyMatcapsAndRimLighting(i, pbr, l);
- pbr.albedo.rgb = max(0, pbr.albedo.rgb);
+ //pbr.albedo.rgb = max(0, pbr.albedo.rgb);
l.diffuse = max(0, l.diffuse);
l.specular = max(0, l.specular);
#endif
@@ -227,7 +228,7 @@ float4 frag(v2f i }
#endif
-#if defined(_EMISSION) || (defined(_GLITTER) && defined(FORWARD_BASE_PASS))
+#if defined(_EMISSION) || (defined(_GLITTER) && defined(FORWARD_BASE_PASS)) || defined(OUTLINE_PASS)
lit.rgb += pbr.emission;
#endif
diff --git a/2ner.shader b/2ner.shader index c8d2d00..4a20161 100644 --- a/2ner.shader +++ b/2ner.shader @@ -95,6 +95,7 @@ Shader "yum_food/2ner" [ThryToggle(_OUTLINES)]_Outlines_Enabled("Enable", Float) = 0 _Outlines_Enabled_Dynamic("Enable (dynamic)", Float) = 1 _Outline_Color("Color", Color) = (0, 0, 0, 1) + _Outline_Emission("Emission strength", Range(0, 10)) = 0 _Outline_Width("Width", Float) = 0.01 [HideInInspector] m_start_OutlinesMask("Mask", Float) = 0 [ThryToggle(_OUTLINE_MASK)]_Outline_Mask_Enabled("Enable", Float) = 0 @@ -297,11 +298,13 @@ Shader "yum_food/2ner" _Decal0_MainTex("Base color", 2D) = "white" {} _Decal0_Opacity("Opacity", Range(0, 1)) = 1.0 _Decal0_Angle("Angle", Range(0, 1)) = 0.0 + _Decal0_UV_Channel("UV channel", Range(0, 1)) = 0 [ThryWideEnum(Clamp, 0, Tiling, 1)]_Decal0_Tiling_Mode("Tiling mode", Int) = 0 + [ThryWideEnum(AlphaBlend, 0, Replace, 1)]_Decal0_Alpha_Blend_Mode("Alpha blend mode", Int) = 0 //ifex _Decal0_Normal_Enabled==0 [HideInInspector] m_start_Decal0_Normal("Normal", Float) = 0 [ThryToggle(_DECAL0_NORMAL)] _Decal0_Normal_Enabled("Enable", Float) = 0 - _Decal0_Normal("Normal", 2D) = "bump" {} + [Normal]_Decal0_Normal("Normal", 2D) = "bump" {} _Decal0_Normal_Scale("Normal scale", Float) = 1.0 [HideInInspector] m_end_Decal0_Normal("Normal", Float) = 0 //endex @@ -313,8 +316,149 @@ Shader "yum_food/2ner" _Decal0_Metallic("Metallic", Range(0, 1)) = 0.0 [HideInInspector] m_end_Decal0_Reflections("Reflections", Float) = 0 //endex + //ifex _Decal0_SDF_Enabled==0 + [HideInInspector] m_start_Decal0_SDF("SDF mode", Float) = 0 + [ThryToggle(_DECAL0_SDF)] _Decal0_SDF_Enabled("Enable", Float) = 0 + _Decal0_SDF_Threshold("SDF threshold", Range(0, 1)) = 0.5 + [MaterialToggle] _Decal0_SDF_Invert("SDF invert", Float) = 0 + _Decal0_SDF_Softness("SDF softness", Range(0, 1)) = 0.01 + _Decal0_SDF_Px_Range("SDF px range", Float) = 2 + [HideInInspector] m_end_Decal0_SDF("SDF", Float) = 0 + //endex + //ifex _Decal0_Mask_Enabled==0 + [HideInInspector] m_start_Decal0_Mask("Mask", Float) = 0 + [ThryToggle(_DECAL0_MASK)] _Decal0_Mask_Enabled("Enable", Float) = 0 + _Decal0_Mask("Mask", 2D) = "white" {} + [HideInInspector] m_end_Decal0_Mask("Mask", Float) = 0 + //endex [HideInInspector] m_end_Decal0("Decal 0", Float) = 0 //endex + //ifex _Decal1_Enabled==0 + [HideInInspector] m_start_Decal1("Decal 1", Float) = 0 + [ThryToggle(_DECAL1)] _Decal1_Enabled("Enable", Float) = 0 + _Decal1_Color("Tint", Color) = (1, 1, 1, 1) + _Decal1_MainTex("Base color", 2D) = "white" {} + _Decal1_Opacity("Opacity", Range(0, 1)) = 1.0 + _Decal1_Angle("Angle", Range(0, 1)) = 0.0 + _Decal1_UV_Channel("UV channel", Range(0, 1)) = 0 + [ThryWideEnum(Clamp, 0, Tiling, 1)]_Decal1_Tiling_Mode("Tiling mode", Int) = 0 + [ThryWideEnum(AlphaBlend, 0, Replace, 1)]_Decal1_Alpha_Blend_Mode("Alpha blend mode", Int) = 0 + //ifex _Decal1_Normal_Enabled==0 + [HideInInspector] m_start_Decal1_Normal("Normal", Float) = 0 + [ThryToggle(_DECAL1_NORMAL)] _Decal1_Normal_Enabled("Enable", Float) = 0 + [Normal]_Decal1_Normal("Normal", 2D) = "bump" {} + _Decal1_Normal_Scale("Normal scale", Float) = 1.0 + [HideInInspector] m_end_Decal1_Normal("Normal", Float) = 0 + //endex + //ifex _Decal1_Reflections_Enabled==0 + [HideInInspector] m_start_Decal1_Reflections("Reflections", Float) = 0 + [ThryToggle(_DECAL1_REFLECTIONS)] _Decal1_Reflections_Enabled("Enable", Float) = 0 + _Decal1_MetallicGlossMap("Metallic gloss map", 2D) = "white" {} + _Decal1_Smoothness("Smoothness", Range(0, 1)) = 0.5 + _Decal1_Metallic("Metallic", Range(0, 1)) = 0.0 + [HideInInspector] m_end_Decal1_Reflections("Reflections", Float) = 0 + //endex + //ifex _Decal1_SDF_Enabled==0 + [HideInInspector] m_start_Decal1_SDF("SDF mode", Float) = 0 + [ThryToggle(_DECAL1_SDF)] _Decal1_SDF_Enabled("Enable", Float) = 0 + _Decal1_SDF_Threshold("SDF threshold", Range(0, 1)) = 0.5 + [MaterialToggle] _Decal1_SDF_Invert("SDF invert", Float) = 0 + _Decal1_SDF_Softness("SDF softness", Range(0, 1)) = 0.01 + _Decal1_SDF_Px_Range("SDF px range", Float) = 2 + [HideInInspector] m_end_Decal1_SDF("SDF", Float) = 0 + //endex + //ifex _Decal1_Mask_Enabled==0 + [HideInInspector] m_start_Decal1_Mask("Mask", Float) = 0 + [ThryToggle(_DECAL1_MASK)] _Decal1_Mask_Enabled("Enable", Float) = 0 + _Decal1_Mask("Mask", 2D) = "white" {} + [HideInInspector] m_end_Decal1_Mask("Mask", Float) = 0 + //endex + [HideInInspector] m_end_Decal1("Decal 1", Float) = 0 + //endex + //ifex _Decal2_Enabled==0 + [HideInInspector] m_start_Decal2("Decal 2", Float) = 0 + [ThryToggle(_DECAL2)] _Decal2_Enabled("Enable", Float) = 0 + _Decal2_Color("Tint", Color) = (1, 1, 1, 1) + _Decal2_MainTex("Base color", 2D) = "white" {} + _Decal2_Opacity("Opacity", Range(0, 1)) = 1.0 + _Decal2_Angle("Angle", Range(0, 1)) = 0.0 + _Decal2_UV_Channel("UV channel", Range(0, 1)) = 0 + [ThryWideEnum(Clamp, 0, Tiling, 1)]_Decal2_Tiling_Mode("Tiling mode", Int) = 0 + [ThryWideEnum(AlphaBlend, 0, Replace, 1)]_Decal2_Alpha_Blend_Mode("Alpha blend mode", Int) = 0 + //ifex _Decal2_Normal_Enabled==0 + [HideInInspector] m_start_Decal2_Normal("Normal", Float) = 0 + [ThryToggle(_DECAL2_NORMAL)] _Decal2_Normal_Enabled("Enable", Float) = 0 + [Normal]_Decal2_Normal("Normal", 2D) = "bump" {} + _Decal2_Normal_Scale("Normal scale", Float) = 1.0 + [HideInInspector] m_end_Decal2_Normal("Normal", Float) = 0 + //endex + //ifex _Decal2_Reflections_Enabled==0 + [HideInInspector] m_start_Decal2_Reflections("Reflections", Float) = 0 + [ThryToggle(_DECAL2_REFLECTIONS)] _Decal2_Reflections_Enabled("Enable", Float) = 0 + _Decal2_MetallicGlossMap("Metallic gloss map", 2D) = "white" {} + _Decal2_Smoothness("Smoothness", Range(0, 1)) = 0.5 + _Decal2_Metallic("Metallic", Range(0, 1)) = 0.0 + [HideInInspector] m_end_Decal2_Reflections("Reflections", Float) = 0 + //endex + //ifex _Decal2_SDF_Enabled==0 + [HideInInspector] m_start_Decal2_SDF("SDF mode", Float) = 0 + [ThryToggle(_DECAL2_SDF)] _Decal2_SDF_Enabled("Enable", Float) = 0 + _Decal2_SDF_Threshold("SDF threshold", Range(0, 1)) = 0.5 + [MaterialToggle] _Decal2_SDF_Invert("SDF invert", Float) = 0 + _Decal2_SDF_Softness("SDF softness", Range(0, 1)) = 0.01 + _Decal2_SDF_Px_Range("SDF px range", Float) = 2 + [HideInInspector] m_end_Decal2_SDF("SDF", Float) = 0 + //endex + //ifex _Decal2_Mask_Enabled==0 + [HideInInspector] m_start_Decal2_Mask("Mask", Float) = 0 + [ThryToggle(_DECAL2_MASK)] _Decal2_Mask_Enabled("Enable", Float) = 0 + _Decal2_Mask("Mask", 2D) = "white" {} + [HideInInspector] m_end_Decal2_Mask("Mask", Float) = 0 + //endex + [HideInInspector] m_end_Decal2("Decal 2", Float) = 0 + //endex + //ifex _Decal3_Enabled==0 + [HideInInspector] m_start_Decal3("Decal 3", Float) = 0 + [ThryToggle(_DECAL3)] _Decal3_Enabled("Enable", Float) = 0 + _Decal3_Color("Tint", Color) = (1, 1, 1, 1) + _Decal3_MainTex("Base color", 2D) = "white" {} + _Decal3_Opacity("Opacity", Range(0, 1)) = 1.0 + _Decal3_Angle("Angle", Range(0, 1)) = 0.0 + _Decal3_UV_Channel("UV channel", Range(0, 1)) = 0 + [ThryWideEnum(Clamp, 0, Tiling, 1)]_Decal3_Tiling_Mode("Tiling mode", Int) = 0 + [ThryWideEnum(AlphaBlend, 0, Replace, 1)]_Decal3_Alpha_Blend_Mode("Alpha blend mode", Int) = 0 + //ifex _Decal3_Normal_Enabled==0 + [HideInInspector] m_start_Decal3_Normal("Normal", Float) = 0 + [ThryToggle(_DECAL3_NORMAL)] _Decal3_Normal_Enabled("Enable", Float) = 0 + [Normal]_Decal3_Normal("Normal", 2D) = "bump" {} + _Decal3_Normal_Scale("Normal scale", Float) = 1.0 + [HideInInspector] m_end_Decal3_Normal("Normal", Float) = 0 + //endex + //ifex _Decal3_Reflections_Enabled==0 + [HideInInspector] m_start_Decal3_Reflections("Reflections", Float) = 0 + [ThryToggle(_DECAL3_REFLECTIONS)] _Decal3_Reflections_Enabled("Enable", Float) = 0 + _Decal3_MetallicGlossMap("Metallic gloss map", 2D) = "white" {} + _Decal3_Smoothness("Smoothness", Range(0, 1)) = 0.5 + _Decal3_Metallic("Metallic", Range(0, 1)) = 0.0 + [HideInInspector] m_end_Decal3_Reflections("Reflections", Float) = 0 + //endex + //ifex _Decal3_SDF_Enabled==0 + [HideInInspector] m_start_Decal3_SDF("SDF mode", Float) = 0 + [ThryToggle(_DECAL3_SDF)] _Decal3_SDF_Enabled("Enable", Float) = 0 + _Decal3_SDF_Threshold("SDF threshold", Range(0, 1)) = 0.5 + [MaterialToggle] _Decal3_SDF_Invert("SDF invert", Float) = 0 + _Decal3_SDF_Softness("SDF softness", Range(0, 1)) = 0.01 + _Decal3_SDF_Px_Range("SDF px range", Float) = 2 + [HideInInspector] m_end_Decal3_SDF("SDF", Float) = 0 + //endex + //ifex _Decal3_Mask_Enabled==0 + [HideInInspector] m_start_Decal3_Mask("Mask", Float) = 0 + [ThryToggle(_DECAL3_MASK)] _Decal3_Mask_Enabled("Enable", Float) = 0 + _Decal3_Mask("Mask", 2D) = "white" {} + [HideInInspector] m_end_Decal3_Mask("Mask", Float) = 0 + //endex + [HideInInspector] m_end_Decal3("Decal 3", Float) = 0 + //endex [HideInInspector] m_end_Decals("Decals", Float) = 0 //ifex _Face_Me_Enabled==0 diff --git a/decals.cginc b/decals.cginc index c356d45..bf09b6c 100644 --- a/decals.cginc +++ b/decals.cginc @@ -5,31 +5,266 @@ #include "globals.cginc"
#include "math.cginc"
+// Struct to hold all decal parameters
+struct DecalParams {
+ float4 color;
+ float opacity;
+ float angle;
+ float uv_channel;
+ float4 mainTex_ST;
+ int tiling_mode;
+ int alpha_blend_mode;
+ Texture2D mainTex;
+ bool sdf_enabled;
+ bool sdf_invert;
+ float sdf_threshold;
+ bool mask_enabled;
+ Texture2D mask;
+ bool normal_enabled;
+ Texture2D normalTex;
+ float normal_scale;
+ bool reflections_enabled;
+ Texture2D metallicGlossMap;
+ float metallic_value;
+ float smoothness_value;
+};
+
+// Macro to initialize decal parameters
+#define INIT_DECAL_PARAMS(params, prefix) \
+ params.color = prefix##Color; \
+ params.opacity = prefix##Opacity; \
+ params.angle = prefix##Angle; \
+ params.uv_channel = prefix##UV_Channel; \
+ params.mainTex_ST = prefix##MainTex_ST; \
+ params.tiling_mode = prefix##Tiling_Mode; \
+ params.alpha_blend_mode = prefix##Alpha_Blend_Mode; \
+ params.mainTex = prefix##MainTex; \
+ params.sdf_enabled = prefix##SDF_Enabled; \
+ params.sdf_invert = prefix##SDF_Invert; \
+ params.sdf_threshold = prefix##SDF_Threshold; \
+ params.mask_enabled = prefix##Mask_Enabled; \
+ params.mask = prefix##Mask; \
+ params.normal_enabled = prefix##Normal_Enabled; \
+ params.normalTex = prefix##Normal; \
+ params.normal_scale = prefix##Normal_Scale; \
+ params.reflections_enabled = prefix##Reflections_Enabled; \
+ params.metallicGlossMap = prefix##MetallicGlossMap; \
+ params.metallic_value = prefix##Metallic; \
+ params.smoothness_value = prefix##Smoothness
+
+#define APPLY_DECAL_SEC00_GENERIC(i, albedo, normal_tangent, metallic, smoothness, params) \
+ float2x2 decal_rot = float2x2( \
+ cos(params.angle * TAU), -sin(params.angle * TAU), \
+ sin(params.angle * TAU), cos(params.angle * TAU) \
+ ); \
+ \
+ float2 raw_decal_uv = (params.uv_channel == 0) ? i.uv01.xy : i.uv01.zw; \
+ float2 decal_uv = (raw_decal_uv * params.mainTex_ST.xy + params.mainTex_ST.zw); \
+ decal_uv = mul(decal_rot, decal_uv); \
+ decal_uv = (params.tiling_mode == DECAL_TILING_MODE_CLAMP ? saturate(decal_uv) : decal_uv);
+
+#define APPLY_DECAL_SEC01_SDF_ON(i, albedo, normal_tangent, metallic, smoothness, params) \
+ float4 decal_albedo; \
+ { \
+ float4 sdf_sample = params.mainTex.SampleLevel(linear_repeat_s, decal_uv, 0); \
+ float sd = sdf_sample.r; \
+ sd = params.sdf_invert ? 1 - sd : sd; \
+ sd = (sd > params.sdf_threshold ? 1 : 0); \
+ decal_albedo = params.color * sd; \
+ decal_albedo.a *= params.opacity; \
+ }
+
+#define APPLY_DECAL_SEC01_SDF_OFF(i, albedo, normal_tangent, metallic, smoothness, params) \
+ float4 decal_albedo; \
+ { \
+ decal_albedo = params.mainTex.Sample(linear_repeat_s, decal_uv); \
+ decal_albedo *= params.color; \
+ decal_albedo.a *= params.opacity; \
+ }
+
+#define APPLY_DECAL_SEC02_CLAMP_ON(i, albedo, normal_tangent, metallic, smoothness, params) \
+ { \
+ float eps = 1e-4; \
+ float2 uv_clamped = step(eps, decal_uv) * step(decal_uv, 1 - eps); \
+ decal_albedo.a *= uv_clamped.x * uv_clamped.y; \
+ }
+
+#define APPLY_DECAL_SEC02_CLAMP_OFF(i, albedo, normal_tangent, metallic, smoothness, params) {}
+
+#define APPLY_DECAL_SEC03_MASK_ON(i, albedo, normal_tangent, metallic, smoothness, params) \
+ float decal_mask = params.mask.Sample(linear_repeat_s, raw_decal_uv); \
+ decal_albedo.a *= decal_mask;
+
+#define APPLY_DECAL_SEC03_MASK_OFF(i, albedo, normal_tangent, metallic, smoothness, params) \
+ float decal_mask = 1;
+
+#define APPLY_DECAL_SEC04_BLEND_MODE_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, params) \
+ albedo = alphaBlend(albedo, decal_albedo);
+
+#define APPLY_DECAL_SEC04_BLEND_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, params) \
+ albedo = lerp(albedo, decal_albedo, decal_mask);
+
+#define APPLY_DECAL_SEC05_NORMAL_ON(i, albedo, normal_tangent, metallic, smoothness, params) \
+ float3 decal_normal = UnpackScaleNormal( \
+ params.normalTex.Sample(linear_repeat_s, decal_uv), \
+ params.normal_scale * decal_albedo.a); \
+ normal_tangent = lerp(normal_tangent, decal_normal, decal_albedo.a);
+
+#define APPLY_DECAL_SEC05_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, params) {}
+
+#define APPLY_DECAL_SEC06_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, params) \
+ float4 metallic_gloss = params.metallicGlossMap.Sample(linear_repeat_s, decal_uv); \
+ metallic = lerp(metallic, metallic_gloss.r * params.metallic_value, decal_albedo.a); \
+ smoothness = lerp(smoothness, metallic_gloss.a * params.smoothness_value, decal_albedo.a);
+
+#define APPLY_DECAL_SEC06_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, params) {}
+
void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, inout float metallic, inout float smoothness) {
-#if defined(_DECAL0)
- float2x2 decal0_rot = float2x2(
- cos(_Decal0_Angle * TAU), -sin(_Decal0_Angle * TAU),
- sin(_Decal0_Angle * TAU), cos(_Decal0_Angle * TAU)
- );
- float2 decal0_uv = mul(decal0_rot, i.uv01.xy);
- decal0_uv = (decal0_uv * _Decal0_MainTex_ST.xy + _Decal0_MainTex_ST.zw) * _Decal0_Tiling_Mode;
- decal0_uv = (_Decal0_Tiling_Mode == DECAL_TILING_MODE_CLAMP ? saturate(decal0_uv) : decal0_uv);
-
- float4 decal0_albedo = _Decal0_MainTex.Sample(linear_repeat_s, decal0_uv) * _Decal0_Color;
- decal0_albedo.a *= _Decal0_Opacity;
- albedo = alphaBlend(albedo, decal0_albedo);
-
-#if defined(_DECAL0_NORMAL)
- float3 decal0_normal = UnpackScaleNormal(
- _Decal0_Normal.Sample(linear_repeat_s, decal0_uv), _Decal0_Normal_Scale * _Decal0_Opacity);
- normal_tangent = blendNormalsHill12(normal_tangent, decal0_normal);
-#endif
-#if defined(_DECAL0_REFLECTIONS)
- float4 metallic_gloss = _Decal0_MetallicGlossMap.Sample(linear_repeat_s, decal0_uv);
- metallic = lerp(metallic, metallic_gloss.r * _Decal0_Metallic, decal0_albedo.a);
- smoothness = lerp(smoothness, metallic_gloss.a * _Decal0_Smoothness, decal0_albedo.a);
-#endif
-#endif
+ DecalParams decal;
+ #if defined(_DECAL0)
+ {
+ INIT_DECAL_PARAMS(decal, _Decal0_);
+ APPLY_DECAL_SEC00_GENERIC(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #if defined(_DECAL0_SDF)
+ APPLY_DECAL_SEC01_SDF_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC01_SDF_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
+ if (decal.tiling_mode == DECAL_TILING_MODE_CLAMP) {
+ APPLY_DECAL_SEC02_CLAMP_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ } else {
+ APPLY_DECAL_SEC02_CLAMP_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ }
+ #if defined(_DECAL0_MASK)
+ APPLY_DECAL_SEC03_MASK_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC03_MASK_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
+ if (decal.alpha_blend_mode == DECAL_ALPHA_BLEND_MODE_ALPHA_BLEND) {
+ APPLY_DECAL_SEC04_BLEND_MODE_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, decal);
+ } else {
+ APPLY_DECAL_SEC04_BLEND_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, decal);
+ }
+ #if defined(_DECAL0_NORMAL)
+ APPLY_DECAL_SEC05_NORMAL_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC05_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
+ #if defined(_DECAL0_REFLECTIONS)
+ APPLY_DECAL_SEC06_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC06_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
+ }
+ #endif // _DECAL0
+ #if defined(_DECAL1)
+ {
+ INIT_DECAL_PARAMS(decal, _Decal1_);
+ APPLY_DECAL_SEC00_GENERIC(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #if defined(_DECAL1_SDF)
+ APPLY_DECAL_SEC01_SDF_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC01_SDF_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
+ if (decal.tiling_mode == DECAL_TILING_MODE_CLAMP) {
+ APPLY_DECAL_SEC02_CLAMP_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ } else {
+ APPLY_DECAL_SEC02_CLAMP_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ }
+ #if defined(_DECAL1_MASK)
+ APPLY_DECAL_SEC03_MASK_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC03_MASK_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
+ if (decal.alpha_blend_mode == DECAL_ALPHA_BLEND_MODE_ALPHA_BLEND) {
+ APPLY_DECAL_SEC04_BLEND_MODE_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, decal);
+ } else {
+ APPLY_DECAL_SEC04_BLEND_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, decal);
+ }
+ #if defined(_DECAL1_NORMAL)
+ APPLY_DECAL_SEC05_NORMAL_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC05_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
+ #if defined(_DECAL1_REFLECTIONS)
+ APPLY_DECAL_SEC06_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC06_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
+ }
+ #endif // _DECAL1
+ #if defined(_DECAL2)
+ {
+ INIT_DECAL_PARAMS(decal, _Decal2_);
+ APPLY_DECAL_SEC00_GENERIC(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #if defined(_DECAL2_SDF)
+ APPLY_DECAL_SEC01_SDF_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC01_SDF_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
+ if (decal.tiling_mode == DECAL_TILING_MODE_CLAMP) {
+ APPLY_DECAL_SEC02_CLAMP_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ } else {
+ APPLY_DECAL_SEC02_CLAMP_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ }
+ #if defined(_DECAL2_MASK)
+ APPLY_DECAL_SEC03_MASK_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC03_MASK_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
+ if (decal.alpha_blend_mode == DECAL_ALPHA_BLEND_MODE_ALPHA_BLEND) {
+ APPLY_DECAL_SEC04_BLEND_MODE_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, decal);
+ } else {
+ APPLY_DECAL_SEC04_BLEND_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, decal);
+ }
+ #if defined(_DECAL2_NORMAL)
+ APPLY_DECAL_SEC05_NORMAL_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC05_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
+ #if defined(_DECAL2_REFLECTIONS)
+ APPLY_DECAL_SEC06_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC06_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
+ }
+ #endif // _DECAL2
+ #if defined(_DECAL3)
+ {
+ INIT_DECAL_PARAMS(decal, _Decal3_);
+ APPLY_DECAL_SEC00_GENERIC(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #if defined(_DECAL3_SDF)
+ APPLY_DECAL_SEC01_SDF_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC01_SDF_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
+ if (decal.tiling_mode == DECAL_TILING_MODE_CLAMP) {
+ APPLY_DECAL_SEC02_CLAMP_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ } else {
+ APPLY_DECAL_SEC02_CLAMP_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ }
+ #if defined(_DECAL3_MASK)
+ APPLY_DECAL_SEC03_MASK_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC03_MASK_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
+ if (decal.alpha_blend_mode == DECAL_ALPHA_BLEND_MODE_ALPHA_BLEND) {
+ APPLY_DECAL_SEC04_BLEND_MODE_ALPHA_BLEND(i, albedo, normal_tangent, metallic, smoothness, decal);
+ } else {
+ APPLY_DECAL_SEC04_BLEND_MODE_REPLACE(i, albedo, normal_tangent, metallic, smoothness, decal);
+ }
+ #if defined(_DECAL3_NORMAL)
+ APPLY_DECAL_SEC05_NORMAL_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC05_NORMAL_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
+ #if defined(_DECAL3_REFLECTIONS)
+ APPLY_DECAL_SEC06_REFLECTIONS_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC06_REFLECTIONS_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
+ }
+ #endif // _DECAL3
}
#endif // __DECALS
diff --git a/features.cginc b/features.cginc index e087359..9a0d838 100644 --- a/features.cginc +++ b/features.cginc @@ -111,7 +111,29 @@ #pragma shader_feature_local _DECAL0 #pragma shader_feature_local _DECAL0_NORMAL #pragma shader_feature_local _DECAL0_REFLECTIONS -//endex +#pragma shader_feature_local _DECAL0_SDF +#pragma shader_feature_local _DECAL0_MASK +//endex +//ifex _Decal1_Enabled==0 +#pragma shader_feature_local _DECAL1 +#pragma shader_feature_local _DECAL1_NORMAL +#pragma shader_feature_local _DECAL1_REFLECTIONS +#pragma shader_feature_local _DECAL1_SDF +#pragma shader_feature_local _DECAL1_MASK +//endex +//ifex _Decal2_Enabled==0 +#pragma shader_feature_local _DECAL2 +#pragma shader_feature_local _DECAL2_NORMAL +#pragma shader_feature_local _DECAL2_REFLECTIONS +#pragma shader_feature_local _DECAL2_SDF +#pragma shader_feature_local _DECAL2_MASK +//endex +//ifex _Decal3_Enabled==0 +#pragma shader_feature_local _DECAL3 +#pragma shader_feature_local _DECAL3_NORMAL +#pragma shader_feature_local _DECAL3_REFLECTIONS +#pragma shader_feature_local _DECAL3_SDF +#pragma shader_feature_local _DECAL3_MASK //ifex _Vertex_Domain_Warping_Enabled==0 #pragma shader_feature_local _VERTEX_DOMAIN_WARPING diff --git a/globals.cginc b/globals.cginc index 4f1d419..1e56785 100644 --- a/globals.cginc +++ b/globals.cginc @@ -3,6 +3,7 @@ #include "features.cginc"
+SamplerState point_repeat_s;
SamplerState linear_repeat_s;
SamplerState linear_clamp_s;
@@ -104,6 +105,7 @@ float _Clearcoat_Roughness; #if defined(OUTLINE_PASS)
float _Outlines_Enabled_Dynamic;
float4 _Outline_Color;
+float _Outline_Emission;
float _Outline_Width;
#if defined(_OUTLINE_MASK)
texture2D _Outline_Mask;
@@ -234,24 +236,53 @@ float _Rim_Lighting3_Quantization_Steps; #define DECAL_TILING_MODE_CLAMP 0
#define DECAL_TILING_MODE_TILE 1
+#define DECAL_ALPHA_BLEND_MODE_ALPHA_BLEND 0
+#define DECAL_ALPHA_BLEND_MODE_REPLACE 1
+
+#define DECLARE_DECAL_VARIABLES(n) \
+texture2D _Decal##n##_MainTex; \
+float4 _Decal##n##_MainTex_ST; \
+float4 _Decal##n##_Color; \
+float _Decal##n##_Opacity; \
+float _Decal##n##_Angle; \
+float _Decal##n##_UV_Channel; \
+float _Decal##n##_Tiling_Mode; \
+float _Decal##n##_Alpha_Blend_Mode; \
+float _Decal##n##_Normal_Enabled; \
+texture2D _Decal##n##_Normal; \
+float4 _Decal##n##_Normal_ST; \
+float _Decal##n##_Normal_Scale; \
+\
+float _Decal##n##_Reflections_Enabled; \
+texture2D _Decal##n##_MetallicGlossMap; \
+float4 _Decal##n##_MetallicGlossMap_ST; \
+float _Decal##n##_Smoothness; \
+float _Decal##n##_Metallic; \
+\
+float _Decal##n##_SDF_Enabled; \
+float _Decal##n##_SDF_Threshold; \
+float _Decal##n##_SDF_Invert; \
+float _Decal##n##_SDF_Softness; \
+float _Decal##n##_SDF_Px_Range; \
+\
+float _Decal##n##_Mask_Enabled; \
+texture2D _Decal##n##_Mask; \
+float4 _Decal##n##_Mask_ST;
+
#if defined(_DECAL0)
-texture2D _Decal0_MainTex;
-float4 _Decal0_MainTex_ST;
-float4 _Decal0_Color;
-float _Decal0_Opacity;
-float _Decal0_Angle;
-float _Decal0_Tiling_Mode;
-#if defined(_DECAL0_NORMAL)
-texture2D _Decal0_Normal;
-float4 _Decal0_Normal_ST;
-float _Decal0_Normal_Scale;
-#endif
-#if defined(_DECAL0_REFLECTIONS)
-texture2D _Decal0_MetallicGlossMap;
-float4 _Decal0_MetallicGlossMap_ST;
-float _Decal0_Smoothness;
-float _Decal0_Metallic;
+DECLARE_DECAL_VARIABLES(0)
+#endif
+
+#if defined(_DECAL1)
+DECLARE_DECAL_VARIABLES(1)
#endif
+
+#if defined(_DECAL2)
+DECLARE_DECAL_VARIABLES(2)
+#endif
+
+#if defined(_DECAL3)
+DECLARE_DECAL_VARIABLES(3)
#endif
#if defined(_VERTEX_DOMAIN_WARPING)
diff --git a/interpolators.cginc b/interpolators.cginc index 285d042..9db505c 100644 --- a/interpolators.cginc +++ b/interpolators.cginc @@ -5,7 +5,8 @@ struct appdata {
float4 vertex : POSITION;
- float4 uv01 : TEXCOORD0; // uv channels 0:1
+ float2 uv0 : TEXCOORD0;
+ float2 uv1 : TEXCOORD1;
float3 normal : NORMAL;
float4 tangent : TANGENT;
diff --git a/yum_pbr.cginc b/yum_pbr.cginc index 457f831..85d653e 100644 --- a/yum_pbr.cginc +++ b/yum_pbr.cginc @@ -12,7 +12,7 @@ struct YumPbr { float4 albedo; float3 normal; -#if defined(_EMISSION) || (defined(_GLITTER) && (defined(FORWARD_BASE_PASS) || defined(FORWARD_ADD_PASS))) +#if defined(_EMISSION) || (defined(_GLITTER) && (defined(FORWARD_BASE_PASS) || defined(FORWARD_ADD_PASS))) || defined(OUTLINE_PASS) float3 emission; #endif float smoothness; @@ -50,7 +50,7 @@ YumPbr GetYumPbr(v2f i) { _BumpScale); #if defined(_DETAIL_MAPS) - float detail_mask = _DetailMask.SampleLevel(linear_repeat_s, i.uv01.xy, 0); + float detail_mask = _DetailMask.SampleLevel(point_repeat_s, i.uv01.xy, 0); float4 detail_albedo = tex2D(_DetailAlbedoMap, UV_SCOFF(i, _DetailAlbedoMap_ST, /*which_channel=*/0)); float3 detail_normal = UnpackScaleNormal( @@ -58,6 +58,7 @@ YumPbr GetYumPbr(v2f i) { UV_SCOFF(i, _DetailNormalMap_ST, /*which_channel=*/0)), _DetailNormalMapScale); result.albedo = lerp(result.albedo, result.albedo * detail_albedo, detail_mask); + //result.albedo.a *= detail_albedo.a; normal_tangent = lerp(normal_tangent, blendNormalsHill12(normal_tangent, detail_normal), detail_mask); #endif @@ -68,6 +69,13 @@ YumPbr GetYumPbr(v2f i) { #if defined(_EMISSION) result.emission = tex2D(_EmissionMap, UV_SCOFF(i, _EmissionMap_ST, /*which_channel=*/0)) * _EmissionColor; #endif +#if defined(OUTLINE_PASS) +#if defined(_EMISSION) + result.emission += _Outline_Color * _Outline_Emission; +#else + result.emission = _Outline_Color * _Outline_Emission; +#endif +#endif #if defined(_METALLICS) float4 metallic_gloss = tex2D(_MetallicGlossMap, UV_SCOFF(i, _MetallicGlossMap_ST, /*which_channel=*/0)); |
