summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-05-04 12:37:29 -0700
committeryum <yum.food.vr@gmail.com>2025-05-04 12:37:29 -0700
commit4066ad88b311a99345e168ad9f31ce9ce86684e9 (patch)
treee3fc11cde0c6c82ca782925ca4b835f9a7971fff
parent9a3459e7ba2c33376d9e705f751b1ac571509f92 (diff)
add domain warping to decals
-rw-r--r--2ner.shader42
-rw-r--r--decals.cginc67
-rw-r--r--features.cginc4
-rw-r--r--globals.cginc11
-rw-r--r--yum_pbr.cginc16
5 files changed, 123 insertions, 17 deletions
diff --git a/2ner.shader b/2ner.shader
index 9816621..aa26212 100644
--- a/2ner.shader
+++ b/2ner.shader
@@ -315,6 +315,16 @@ Shader "yum_food/2ner"
_Decal0_Metallic("Metallic", Range(0, 1)) = 0.0
[HideInInspector] m_end_Decal0_Reflections("Reflections", Float) = 0
//endex
+ //ifex _Decal0_Domain_Warping_Enabled==0
+ [HideInInspector] m_start_Decal0_Domain_Warping("Domain warping", Float) = 0
+ [ThryToggle(_DECAL0_DOMAIN_WARPING)] _Decal0_Domain_Warping_Enabled("Enable", Float) = 0
+ _Decal0_Domain_Warping_Noise("Noise", 2D) = "black" {}
+ _Decal0_Domain_Warping_Octaves("Octaves", Float) = 1
+ _Decal0_Domain_Warping_Strength("Strength", Float) = 0.1
+ _Decal0_Domain_Warping_Scale("Scale", Float) = 0.1
+ _Decal0_Domain_Warping_Speed("Speed", Float) = 1.0
+ [HideInInspector] m_end_Decal0_Domain_Warping("Domain warping", 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
@@ -366,6 +376,16 @@ Shader "yum_food/2ner"
_Decal1_Metallic("Metallic", Range(0, 1)) = 0.0
[HideInInspector] m_end_Decal1_Reflections("Reflections", Float) = 0
//endex
+ //ifex _Decal1_Domain_Warping_Enabled==0
+ [HideInInspector] m_start_Decal1_Domain_Warping("Domain warping", Float) = 0
+ [ThryToggle(_DECAL1_DOMAIN_WARPING)] _Decal1_Domain_Warping_Enabled("Enable", Float) = 0
+ _Decal1_Domain_Warping_Noise("Noise", 2D) = "black" {}
+ _Decal1_Domain_Warping_Octaves("Octaves", Float) = 1
+ _Decal1_Domain_Warping_Strength("Strength", Float) = 0.1
+ _Decal1_Domain_Warping_Scale("Scale", Float) = 0.1
+ _Decal1_Domain_Warping_Speed("Speed", Float) = 1.0
+ [HideInInspector] m_end_Decal1_Domain_Warping("Domain warping", 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
@@ -417,6 +437,16 @@ Shader "yum_food/2ner"
_Decal2_Metallic("Metallic", Range(0, 1)) = 0.0
[HideInInspector] m_end_Decal2_Reflections("Reflections", Float) = 0
//endex
+ //ifex _Decal2_Domain_Warping_Enabled==0
+ [HideInInspector] m_start_Decal2_Domain_Warping("Domain warping", Float) = 0
+ [ThryToggle(_DECAL2_DOMAIN_WARPING)] _Decal2_Domain_Warping_Enabled("Enable", Float) = 0
+ _Decal2_Domain_Warping_Noise("Noise", 2D) = "black" {}
+ _Decal2_Domain_Warping_Octaves("Octaves", Float) = 1
+ _Decal2_Domain_Warping_Strength("Strength", Float) = 0.1
+ _Decal2_Domain_Warping_Scale("Scale", Float) = 0.1
+ _Decal2_Domain_Warping_Speed("Speed", Float) = 1.0
+ [HideInInspector] m_end_Decal2_Domain_Warping("Domain warping", 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
@@ -468,6 +498,16 @@ Shader "yum_food/2ner"
_Decal3_Metallic("Metallic", Range(0, 1)) = 0.0
[HideInInspector] m_end_Decal3_Reflections("Reflections", Float) = 0
//endex
+ //ifex _Decal3_Domain_Warping_Enabled==0
+ [HideInInspector] m_start_Decal3_Domain_Warping("Domain warping", Float) = 0
+ [ThryToggle(_DECAL3_DOMAIN_WARPING)] _Decal3_Domain_Warping_Enabled("Enable", Float) = 0
+ _Decal3_Domain_Warping_Noise("Noise", 2D) = "black" {}
+ _Decal3_Domain_Warping_Octaves("Octaves", Float) = 1
+ _Decal3_Domain_Warping_Strength("Strength", Float) = 0.1
+ _Decal3_Domain_Warping_Scale("Scale", Float) = 0.1
+ _Decal3_Domain_Warping_Speed("Speed", Float) = 1.0
+ [HideInInspector] m_end_Decal3_Domain_Warping("Domain warping", 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
@@ -500,6 +540,8 @@ Shader "yum_food/2ner"
[HideInInspector] m_start_3D_SDF("3D SDF", Float) = 0
[ThryToggle(_3D_SDF)] _3D_SDF_Enabled("Enable", Float) = 0
_3D_SDF_Texture("Texture", 3D) = "white" {}
+ _3D_SDF_ST("Scale and offset", Vector) = (1, 1, 0, 0)
+ _3D_SDF_UV_Channel("UV channel", Range(0, 3)) = 0
_3D_SDF_Thresholds("Thresholds", Vector) = (0.2, 0.4, 0.6, 0.8)
_3D_SDF_Color_0("Color 0", Color) = (1, 0, 0, 1)
_3D_SDF_Color_1("Color 1", Color) = (0, 1, 0, 1)
diff --git a/decals.cginc b/decals.cginc
index 45a9354..706f297 100644
--- a/decals.cginc
+++ b/decals.cginc
@@ -16,18 +16,19 @@ struct DecalParams {
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;
+ Texture2D domain_warping_noise;
+ float domain_warping_octaves;
+ float domain_warping_strength;
+ float domain_warping_scale;
+ float domain_warping_speed;
Texture2D cmyk_warping_planes_noise;
float cmyk_warping_planes_strength;
float cmyk_warping_planes_scale;
@@ -44,23 +45,46 @@ struct DecalParams {
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; \
+ params.domain_warping_noise = prefix##Domain_Warping_Noise; \
+ params.domain_warping_octaves = prefix##Domain_Warping_Octaves; \
+ params.domain_warping_strength = prefix##Domain_Warping_Strength; \
+ params.domain_warping_scale = prefix##Domain_Warping_Scale; \
+ params.domain_warping_speed = prefix##Domain_Warping_Speed; \
params.cmyk_warping_planes_noise = prefix##CMYK_Warping_Planes_Noise; \
params.cmyk_warping_planes_strength = prefix##CMYK_Warping_Planes_Strength; \
params.cmyk_warping_planes_scale = prefix##CMYK_Warping_Planes_Scale; \
params.cmyk_warping_planes_speed = prefix##CMYK_Warping_Planes_Speed;
+float2 applyDomainWarping(DecalParams params, float2 uv) {
+ float2 warped_uv = uv;
+ float amplitude = 1.0;
+ float frequency = params.domain_warping_scale;
+ float2 total_offset = float2(0.0, 0.0);
+
+ float2 time_vec = float2(-0.83, 0.97) * _Time.y * params.domain_warping_speed;
+
+ [loop]
+ for (uint ii = 0; ii < params.domain_warping_octaves; ii++) {
+ float2 noise_uv = warped_uv * frequency + time_vec * frequency;
+ float2 noise_sample = params.domain_warping_noise.SampleLevel(trilinear_repeat_s, noise_uv, 0);
+ float2 noise_offset = (noise_sample.xy * 2.0 - 1.0);
+ total_offset += noise_offset * amplitude;
+ frequency *= 2.0;
+ amplitude *= 0.5;
+ }
+
+ warped_uv = uv + total_offset * params.domain_warping_strength;
+ return warped_uv;
+}
+
float4 getDecalColor(DecalParams params, float2 uv) {
float4 sdf_sample = params.mainTex.SampleLevel(linear_repeat_s, uv, 0);
float sd = sdf_sample.r;
@@ -104,7 +128,7 @@ float4 getCmykWarpingPlanesColor(DecalParams params, float2 uv) {
rgbToCmyk_K(decal_color3.rgb));
float3 final_rgb = saturate(cmykToRgb(final_cmyk));
- return float4(final_rgb, decal_color0.a + decal_color1.a + decal_color2.a + decal_color3.a);
+ return float4(final_rgb, saturate(decal_color0.a + decal_color1.a + decal_color2.a + decal_color3.a));
}
#define APPLY_DECAL_SEC00_GENERIC(i, albedo, normal_tangent, metallic, smoothness, params) \
@@ -119,6 +143,11 @@ float4 getCmykWarpingPlanesColor(DecalParams params, float2 uv) {
decal_uv = mul(decal_rot, decal_uv - 0.5) + 0.5; \
decal_uv = (params.tiling_mode == DECAL_TILING_MODE_CLAMP ? saturate(decal_uv) : decal_uv);
+#define APPLY_DECAL_SEC00B_DOMAIN_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, params) \
+ decal_uv = applyDomainWarping(params, decal_uv);
+
+#define APPLY_DECAL_SEC00B_DOMAIN_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, params) {}
+
#define APPLY_DECAL_SEC01_SDF_ON_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, params) \
float4 decal_albedo = getCmykWarpingPlanesColor(params, decal_uv);
@@ -177,6 +206,11 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino
{
INIT_DECAL_PARAMS(decal, _Decal0_);
APPLY_DECAL_SEC00_GENERIC(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #if defined(_DECAL0_DOMAIN_WARPING)
+ APPLY_DECAL_SEC00B_DOMAIN_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC00B_DOMAIN_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
#if defined(_DECAL0_SDF) && defined(_DECAL0_CMYK_WARPING_PLANES)
APPLY_DECAL_SEC01_SDF_ON_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
#elif defined(_DECAL0_SDF)
@@ -215,6 +249,11 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino
{
INIT_DECAL_PARAMS(decal, _Decal1_);
APPLY_DECAL_SEC00_GENERIC(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #if defined(_DECAL1_DOMAIN_WARPING)
+ APPLY_DECAL_SEC00B_DOMAIN_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC00B_DOMAIN_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
#if defined(_DECAL1_SDF) && defined(_DECAL1_CMYK_WARPING_PLANES)
APPLY_DECAL_SEC01_SDF_ON_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
#elif defined(_DECAL1_SDF)
@@ -253,6 +292,11 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino
{
INIT_DECAL_PARAMS(decal, _Decal2_);
APPLY_DECAL_SEC00_GENERIC(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #if defined(_DECAL2_DOMAIN_WARPING)
+ APPLY_DECAL_SEC00B_DOMAIN_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC00B_DOMAIN_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
#if defined(_DECAL2_SDF) && defined(_DECAL2_CMYK_WARPING_PLANES)
APPLY_DECAL_SEC01_SDF_ON_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
#elif defined(_DECAL2_SDF)
@@ -291,6 +335,11 @@ void applyDecals(in v2f i, inout float4 albedo, inout float3 normal_tangent, ino
{
INIT_DECAL_PARAMS(decal, _Decal3_);
APPLY_DECAL_SEC00_GENERIC(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #if defined(_DECAL3_DOMAIN_WARPING)
+ APPLY_DECAL_SEC00B_DOMAIN_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #else
+ APPLY_DECAL_SEC00B_DOMAIN_WARPING_OFF(i, albedo, normal_tangent, metallic, smoothness, decal);
+ #endif
#if defined(_DECAL3_SDF) && defined(_DECAL3_CMYK_WARPING_PLANES)
APPLY_DECAL_SEC01_SDF_ON_WARPING_ON(i, albedo, normal_tangent, metallic, smoothness, decal);
#elif defined(_DECAL3_SDF)
diff --git a/features.cginc b/features.cginc
index 4e10ec8..314aca0 100644
--- a/features.cginc
+++ b/features.cginc
@@ -120,6 +120,7 @@
#pragma shader_feature_local _DECAL0_TILING_MODE
#pragma shader_feature_local _DECAL0_REPLACE_ALPHA
#pragma shader_feature_local _DECAL0_CMYK_WARPING_PLANES
+#pragma shader_feature_local _DECAL0_DOMAIN_WARPING
//endex
//ifex _Decal1_Enabled==0
#pragma shader_feature_local _DECAL1
@@ -130,6 +131,7 @@
#pragma shader_feature_local _DECAL1_TILING_MODE
#pragma shader_feature_local _DECAL1_REPLACE_ALPHA
#pragma shader_feature_local _DECAL1_CMYK_WARPING_PLANES
+#pragma shader_feature_local _DECAL1_DOMAIN_WARPING
//endex
//ifex _Decal2_Enabled==0
#pragma shader_feature_local _DECAL2
@@ -140,6 +142,7 @@
#pragma shader_feature_local _DECAL2_TILING_MODE
#pragma shader_feature_local _DECAL2_REPLACE_ALPHA
#pragma shader_feature_local _DECAL2_CMYK_WARPING_PLANES
+#pragma shader_feature_local _DECAL2_DOMAIN_WARPING
//endex
//ifex _Decal3_Enabled==0
#pragma shader_feature_local _DECAL3
@@ -150,6 +153,7 @@
#pragma shader_feature_local _DECAL3_TILING_MODE
#pragma shader_feature_local _DECAL3_REPLACE_ALPHA
#pragma shader_feature_local _DECAL3_CMYK_WARPING_PLANES
+#pragma shader_feature_local _DECAL3_DOMAIN_WARPING
//endex
//ifex _3D_SDF_Enabled==0
diff --git a/globals.cginc b/globals.cginc
index bfe71cb..599098f 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -273,8 +273,13 @@ float4 _Decal##n##_Mask_ST; \
texture2D _Decal##n##_CMYK_Warping_Planes_Noise; \
float _Decal##n##_CMYK_Warping_Planes_Strength; \
float _Decal##n##_CMYK_Warping_Planes_Scale; \
-float _Decal##n##_CMYK_Warping_Planes_Speed;
-
+float _Decal##n##_CMYK_Warping_Planes_Speed; \
+\
+texture2D _Decal##n##_Domain_Warping_Noise; \
+float _Decal##n##_Domain_Warping_Octaves; \
+float _Decal##n##_Domain_Warping_Strength; \
+float _Decal##n##_Domain_Warping_Scale; \
+float _Decal##n##_Domain_Warping_Speed;
#if defined(_DECAL0)
DECLARE_DECAL_VARIABLES(0)
#endif
@@ -482,6 +487,8 @@ float _Spherize_Strength;
#if defined(_3D_SDF)
texture3D _3D_SDF_Texture;
+float4 _3D_SDF_ST;
+float _3D_SDF_UV_Channel;
float4 _3D_SDF_Thresholds;
float4 _3D_SDF_Color_0;
float4 _3D_SDF_Color_1;
diff --git a/yum_pbr.cginc b/yum_pbr.cginc
index 8ecbe2a..e1928f4 100644
--- a/yum_pbr.cginc
+++ b/yum_pbr.cginc
@@ -67,13 +67,17 @@ YumPbr GetYumPbr(v2f i) {
#if defined(_3D_SDF)
{
- float3 sdf_uv = float3(i.uv01.xy, _3D_SDF_Z + _Time.y * _3D_SDF_Z_Speed);
+ float2 sdf_uv_raw = get_uv_by_channel(i, _3D_SDF_UV_Channel);
+ float3 sdf_uv = float3(sdf_uv_raw, _3D_SDF_Z + _Time.y * _3D_SDF_Z_Speed);
+ sdf_uv.xy = saturate((sdf_uv.xy - (_3D_SDF_ST.zw + 0.5)) * _3D_SDF_ST.xy + (_3D_SDF_ST.zw + 0.5));
float sdf_value = _3D_SDF_Texture.SampleLevel(trilinear_repeat_s, sdf_uv, 0).r;
- float4 is_lit = sdf_value < _3D_SDF_Thresholds;
- result.albedo.rgb = lerp(result.albedo.rgb, _3D_SDF_Color_3, is_lit.w);
- result.albedo.rgb = lerp(result.albedo.rgb, _3D_SDF_Color_2, is_lit.z);
- result.albedo.rgb = lerp(result.albedo.rgb, _3D_SDF_Color_1, is_lit.y);
- result.albedo.rgb = lerp(result.albedo.rgb, _3D_SDF_Color_0, is_lit.x);
+ float eps = 1E-4;
+ float4 is_lit = sdf_value < _3D_SDF_Thresholds && sdf_uv.x > eps && sdf_uv.x < 1 - eps && sdf_uv.y > eps && sdf_uv.y < 1 - eps;
+ float4 skin_albedo = result.albedo;
+ result.albedo.rgb = lerp(result.albedo.rgb, lerp(skin_albedo.rgb, _3D_SDF_Color_3.rgb, _3D_SDF_Color_3.a), is_lit.w);
+ result.albedo.rgb = lerp(result.albedo.rgb, lerp(skin_albedo.rgb, _3D_SDF_Color_2.rgb, _3D_SDF_Color_2.a), is_lit.z);
+ result.albedo.rgb = lerp(result.albedo.rgb, lerp(skin_albedo.rgb, _3D_SDF_Color_1.rgb, _3D_SDF_Color_1.a), is_lit.y);
+ result.albedo.rgb = lerp(result.albedo.rgb, lerp(skin_albedo.rgb, _3D_SDF_Color_0.rgb, _3D_SDF_Color_0.a), is_lit.x);
}
#endif