summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-x3ner.cginc2
-rwxr-xr-x3ner.shader21
-rw-r--r--decal.cginc55
-rwxr-xr-xfeatures.cginc5
-rwxr-xr-xglobals.cginc22
-rwxr-xr-xmath.cginc4
6 files changed, 109 insertions, 0 deletions
diff --git a/3ner.cginc b/3ner.cginc
index 8ddbce8..ea5ccfb 100755
--- a/3ner.cginc
+++ b/3ner.cginc
@@ -10,6 +10,7 @@
#include "brdf.cginc"
#include "cnlohr.cginc"
+#include "decal.cginc"
#include "geometry.cginc"
#include "pbr.cginc"
#include "lighting.cginc"
@@ -301,6 +302,7 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace
i.normal *= facing ? 1 : -1;
Pbr pbr = getPbr(i);
+ applyDecals(i, pbr);
#if defined(_DEBUG_VIEW_UNLIT)
return pbr.albedo;
diff --git a/3ner.shader b/3ner.shader
index 476a7f4..8cbbd09 100755
--- a/3ner.shader
+++ b/3ner.shader
@@ -65,6 +65,27 @@ Shader "yum_food/3ner"
[HideInInspector] m_end_Ambient_Occlusion("Ambient Occlusion", Float) = 0
//endex
+ [HideInInspector] m_start_Matcaps("Decals", Float) = 0
+ //ifex _Decal0_Enabled==0
+ [HideInInspector] m_start_Decal0("Decal 0", Float) = 0
+ [ThryToggle(_DECAL0)] _Decal0_Enabled("Enable", Float) = 0
+ _Decal0_MainTex("Base color", 2D) = "white" {}
+ _Decal0_Color("Tint", Color) = (1, 1, 1, 1)
+ _Decal0_Opacity("Opacity", Range(0, 1)) = 1
+ [ThryWideEnum(Repeat, 0, Mirror, 1, Clamp, 2)] _Decal0_UV_Mode("UV Mode", Int) = 0
+ [ThryWideEnum(AlphaBlend, 0, Multiply, 1)] _Decal0_Mix_Mode("Mix Mode", Int) = 0
+ [IntRange] _Decal0_UV_Channel("UV Channel", Range(0, 3)) = 0
+
+ //ifex _Decal0_Rotation_Enabled==0
+ [HideInInspector] m_start_Decal0_Rotation("Rotation", Float) = 0
+ [ThryToggle(_DECAL0_ROTATION)] _Decal0_Rotation_Enabled("Enable", Float) = 0
+ _Decal0_Rotation("Rotation", Range(-0.5, 0.5)) = 0
+ [HideInInspector] m_end_Decal0_Rotation("Rotation", Float) = 0
+ //endex
+ [HideInInspector] m_end_Decal0("Decal 0", Float) = 0
+ //endex
+ [HideInInspector] m_end_Decals("Decals", Float) = 0
+
[HideInInspector] m_start_Matcaps("Matcaps", Float) = 0
//ifex _Matcap0_Enabled==0
[HideInInspector] m_start_Matcap0("Matcap 0", Float) = 0
diff --git a/decal.cginc b/decal.cginc
new file mode 100644
index 0000000..69fb9e5
--- /dev/null
+++ b/decal.cginc
@@ -0,0 +1,55 @@
+#ifndef __DECAL_INC
+#define __DECAL_INC
+
+#include "globals.cginc"
+#include "pbr.cginc"
+#include "interpolators.cginc"
+#include "texture_utils.cginc"
+
+float4 decal_sample(texture2D tex, float2 uv, int uv_mode) {
+ [forcecase]
+ switch (uv_mode) {
+ case DECAL_UV_MODE_REPEAT:
+ return tex.Sample(aniso4_trilinear_repeat_s, uv);
+ case DECAL_UV_MODE_MIRROR:
+ return tex.Sample(aniso4_trilinear_mirror_s, uv);
+ case DECAL_UV_MODE_CLAMP:
+ return tex.Sample(aniso4_trilinear_clamp_s, uv);
+ default:
+ return 0;
+ }
+}
+
+float2 decal_rotate(float2 uv, float rotation) {
+ float s, c;
+ sincos(rotation * TAU, s, c);
+ float2 d = uv - 0.5;
+ return float2(d.x * c - d.y * s, d.x * s + d.y * c) + 0.5;
+}
+
+void applyDecals(v2f i, inout Pbr pbr) {
+#if defined(_DECAL0)
+ {
+ float2 uv = get_uv_by_channel(i, _Decal0_UV_Channel);
+ uv -= _Decal0_MainTex_ST.zw;
+ uv *= _Decal0_MainTex_ST.xy;
+#if defined(_DECAL0_ROTATION)
+ uv = decal_rotate(uv, _Decal0_Rotation);
+#endif
+ float4 albedo = decal_sample(_Decal0_MainTex, uv, _Decal0_UV_Mode);
+ albedo *= _Decal0_Color;
+ albedo.a *= _Decal0_Opacity;
+ [forcecase]
+ switch (_Decal0_Mix_Mode) {
+ case DECAL_MIX_MODE_ALPHA_BLEND:
+ pbr.albedo = alpha_blend(albedo, pbr.albedo);
+ break;
+ case DECAL_MIX_MODE_MULTIPLY:
+ pbr.albedo.rgb *= lerp(1, albedo.rgb, albedo.a);
+ break;
+ }
+ }
+#endif
+}
+
+#endif // __DECAL_INC
diff --git a/features.cginc b/features.cginc
index 2919950..8107e94 100755
--- a/features.cginc
+++ b/features.cginc
@@ -158,6 +158,11 @@
#pragma shader_feature_local _RAY_MARCHING_HEXAGON
//endex
+//ifex _Decal0_Enabled==0
+#pragma shader_feature_local _DECAL0
+#pragma shader_feature_local _DECAL0_ROTATION
+//endex
+
//ifex _Matcap0_Enabled==0
#pragma shader_feature_local _MATCAP0
#pragma shader_feature_local _MATCAP0_QUANTIZATION
diff --git a/globals.cginc b/globals.cginc
index 2f4dc1e..df9552e 100755
--- a/globals.cginc
+++ b/globals.cginc
@@ -6,6 +6,8 @@
SamplerState point_repeat_s;
SamplerState linear_repeat_s;
SamplerState aniso4_trilinear_repeat_s;
+SamplerState aniso4_trilinear_mirror_s;
+SamplerState aniso4_trilinear_clamp_s;
SamplerState bilinear_repeat_s;
SamplerState linear_clamp_s;
SamplerState bilinear_clamp_s;
@@ -239,6 +241,26 @@ float _Parallax_Heightmap_Bias;
float _Parallax_Heightmap_Ray_Marching_Steps;
#endif // _PARALLAX_HEIGHTMAP_RAY_MARCHING
+#define DECAL_UV_MODE_REPEAT 0
+#define DECAL_UV_MODE_MIRROR 1
+#define DECAL_UV_MODE_CLAMP 2
+
+#define DECAL_MIX_MODE_ALPHA_BLEND 0
+#define DECAL_MIX_MODE_MULTIPLY 1
+
+#if defined(_DECAL0)
+float4 _Decal0_Color;
+texture2D _Decal0_MainTex;
+float4 _Decal0_MainTex_ST;
+float _Decal0_Opacity;
+int _Decal0_UV_Mode;
+int _Decal0_UV_Channel;
+int _Decal0_Mix_Mode;
+#if defined(_DECAL0_ROTATION)
+float _Decal0_Rotation;
+#endif // _DECAL0_ROTATION
+#endif // _DECAL0
+
#define MATCAP_MODE_REPLACE 0
#define MATCAP_MODE_ADD 1
#define MATCAP_MODE_MULTIPLY 2
diff --git a/math.cginc b/math.cginc
index e2d4169..5becd0e 100755
--- a/math.cginc
+++ b/math.cginc
@@ -105,5 +105,9 @@ float luminance(float3 rgb) {
return dot(float3(0.2126, 0.7152, 0.0722), rgb);
}
+float4 alpha_blend(float4 src, float4 dst) {
+ return float4(src.rgb * src.a + dst.rgb * (1 - src.a), src.a + dst.a * (1 - src.a));
+}
+
#endif // __MATH_INC