diff options
| author | yum <yum.food.vr@gmail.com> | 2025-03-06 14:49:47 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-03-06 14:49:47 -0800 |
| commit | 6482b8edd3ecdbf136692e910258dc452f8be71b (patch) | |
| tree | 69d29e992004263bf699983d4828fde6025eb419 | |
| parent | dfa489b6e6090388186b1d32fb126a11b42d31c5 (diff) | |
Add basic decal system
| -rw-r--r-- | 2ner.shader | 29 | ||||
| -rw-r--r-- | decals.cginc | 35 | ||||
| -rw-r--r-- | features.cginc | 6 | ||||
| -rw-r--r-- | globals.cginc | 24 | ||||
| -rw-r--r-- | yum_pbr.cginc | 69 |
5 files changed, 128 insertions, 35 deletions
diff --git a/2ner.shader b/2ner.shader index 48846f6..7af8fde 100644 --- a/2ner.shader +++ b/2ner.shader @@ -287,9 +287,36 @@ Shader "yum_food/2ner" //endex [HideInInspector] m_end_Rim_Lighting3("Rim lighting", Float) = 0 //endex - [HideInInspector] m_end_Rim_Lighting("Rim lighting", Float) = 0 + [HideInInspector] m_start_Decals("Decals", Float) = 0 + //ifex _Decal0_Enabled==0 + [HideInInspector] m_start_Decal0("Decal 0", Float) = 0 + [ThryToggle(_DECAL0)] _Decal0_Enabled("Enable", Float) = 0 + _Decal0_Color("Tint", Color) = (1, 1, 1, 1) + _Decal0_MainTex("Base color", 2D) = "white" {} + _Decal0_Opacity("Opacity", Range(0, 1)) = 1.0 + _Decal0_Angle("Angle", Range(0, 1)) = 0.0 + [ThryWideEnum(Clamp, 0, Tiling, 1)]_Decal0_Tiling_Mode("Tiling 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" {} + _Decal0_Normal_Scale("Normal scale", Float) = 1.0 + [HideInInspector] m_end_Decal0_Normal("Normal", Float) = 0 + //endex + //ifex _Decal0_Reflections_Enabled==0 + [HideInInspector] m_start_Decal0_Reflections("Reflections", Float) = 0 + [ThryToggle(_DECAL0_REFLECTIONS)] _Decal0_Reflections_Enabled("Enable", Float) = 0 + _Decal0_MetallicGlossMap("Metallic gloss map", 2D) = "white" {} + _Decal0_Smoothness("Smoothness", Range(0, 1)) = 0.5 + _Decal0_Metallic("Metallic", Range(0, 1)) = 0.0 + [HideInInspector] m_end_Decal0_Reflections("Reflections", Float) = 0 + //endex + [HideInInspector] m_end_Decal0("Decal 0", Float) = 0 + //endex + [HideInInspector] m_end_Decals("Decals", Float) = 0 + //ifex _Vertex_Domain_Warping_Enabled==0 [HideInInspector] m_start_Vertex_Domain_Warping("Vertex domain warping", Float) = 0 [ThryToggle(_VERTEX_DOMAIN_WARPING)]_Vertex_Domain_Warping_Enabled("Enable", Float) = 0 diff --git a/decals.cginc b/decals.cginc new file mode 100644 index 0000000..c356d45 --- /dev/null +++ b/decals.cginc @@ -0,0 +1,35 @@ +#ifndef __DECALS
+#define __DECALS
+
+#include "features.cginc"
+#include "globals.cginc"
+#include "math.cginc"
+
+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
+}
+
+#endif // __DECALS
diff --git a/features.cginc b/features.cginc index 9e444ab..b709a21 100644 --- a/features.cginc +++ b/features.cginc @@ -89,6 +89,12 @@ #pragma shader_feature_local _RIM_LIGHTING3_QUANTIZATION //endex +//ifex _Decal0_Enabled==0 +#pragma shader_feature_local _DECAL0 +#pragma shader_feature_local _DECAL0_NORMAL +#pragma shader_feature_local _DECAL0_REFLECTIONS +//endex + //ifex _Vertex_Domain_Warping_Enabled==0 #pragma shader_feature_local _VERTEX_DOMAIN_WARPING //endex diff --git a/globals.cginc b/globals.cginc index 67fb1a5..79e25f4 100644 --- a/globals.cginc +++ b/globals.cginc @@ -4,6 +4,7 @@ #include "features.cginc"
SamplerState linear_repeat_s;
+SamplerState linear_clamp_s;
sampler2D _MainTex;
float4 _MainTex_ST;
@@ -216,6 +217,29 @@ float _Rim_Lighting3_Quantization_Steps; #endif
#endif
+#define DECAL_TILING_MODE_CLAMP 0
+#define DECAL_TILING_MODE_TILE 1
+
+#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;
+#endif
+#endif
+
#if defined(_VERTEX_DOMAIN_WARPING)
float _Vertex_Domain_Warping_Spatial_Strength;
float _Vertex_Domain_Warping_Spatial_Scale;
diff --git a/yum_pbr.cginc b/yum_pbr.cginc index 5faff90..457f831 100644 --- a/yum_pbr.cginc +++ b/yum_pbr.cginc @@ -1,6 +1,7 @@ #ifndef __YUM_PBR #define __YUM_PBR +#include "decals.cginc" #include "features.cginc" #include "filamented.cginc" #include "glitter.cginc" @@ -21,6 +22,11 @@ struct YumPbr { float ao; }; +void propagateRoughness(in float smoothness, out float roughness_perceptual, out float roughness) { + roughness_perceptual = normalFiltering(1.0 - smoothness, float3(0, 0, 1)); + roughness = roughness_perceptual * roughness_perceptual; +} + YumPbr GetYumPbr(v2f i) { YumPbr result; @@ -55,6 +61,35 @@ YumPbr GetYumPbr(v2f i) { normal_tangent = lerp(normal_tangent, blendNormalsHill12(normal_tangent, detail_normal), detail_mask); #endif +#if defined(_ALPHA_MULTIPLIER) + result.albedo.a = saturate(result.albedo.a * _Alpha_Multiplier); +#endif + +#if defined(_EMISSION) + result.emission = tex2D(_EmissionMap, UV_SCOFF(i, _EmissionMap_ST, /*which_channel=*/0)) * _EmissionColor; +#endif + +#if defined(_METALLICS) + float4 metallic_gloss = tex2D(_MetallicGlossMap, UV_SCOFF(i, _MetallicGlossMap_ST, /*which_channel=*/0)); + float metallic = metallic_gloss.r * _Metallic; + float smoothness = metallic_gloss.a * _Smoothness; + + result.smoothness = smoothness; + result.metallic = metallic; +#else + result.smoothness = 0.2; + result.metallic = 0; +#endif + +#if defined(_AMBIENT_OCCLUSION) + result.ao = lerp(1, tex2D(_OcclusionMap, i.uv01), _OcclusionStrength); +#else + result.ao = 1; +#endif + + applyDecals(i, result.albedo, normal_tangent, result.metallic, result.smoothness); + propagateRoughness(result.smoothness, result.roughness_perceptual, result.roughness); + float3x3 tangentToWorld = float3x3(i.tangent, i.binormal, i.normal); result.normal = normalize(mul(normal_tangent, tangentToWorld)); @@ -78,17 +113,7 @@ YumPbr GetYumPbr(v2f i) { #endif float4 glitter_albedo = getGlitter(i, glitter_p, result.normal); result.albedo = alphaBlend(result.albedo, glitter_albedo); -#endif - -#if defined(_ALPHA_MULTIPLIER) - result.albedo.a = saturate(result.albedo.a * _Alpha_Multiplier); -#endif - -#if defined(_EMISSION) - result.emission = tex2D(_EmissionMap, UV_SCOFF(i, _EmissionMap_ST, /*which_channel=*/0)) * _EmissionColor; -#endif -#if (defined(FORWARD_BASE_PASS) || defined(FORWARD_ADD_PASS)) && defined(_GLITTER) float3 gitter_emission = glitter_albedo.rgb * glitter_albedo.a * _Glitter_Emission; #if defined(_EMISSION) result.emission += gitter_emission; @@ -97,30 +122,6 @@ YumPbr GetYumPbr(v2f i) { #endif #endif -#if defined(_METALLICS) - float4 metallic_gloss = tex2D(_MetallicGlossMap, UV_SCOFF(i, _MetallicGlossMap_ST, /*which_channel=*/0)); - float metallic = metallic_gloss.r * _Metallic; - float smoothness = metallic_gloss.a * _Smoothness; - - result.smoothness = smoothness; - result.roughness_perceptual = - normalFiltering(1.0 - result.smoothness, result.normal); - result.roughness = result.roughness_perceptual * result.roughness_perceptual; - result.metallic = metallic; -#else - result.smoothness = 0.2; - result.roughness_perceptual = - normalFiltering(1.0 - result.smoothness, result.normal); - result.roughness = result.roughness_perceptual * result.roughness_perceptual; - result.metallic = 0; -#endif - -#if defined(_AMBIENT_OCCLUSION) - result.ao = lerp(1, tex2D(_OcclusionMap, i.uv01), _OcclusionStrength); -#else - result.ao = 1; -#endif - return result; } |
