summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2024-08-10 02:09:15 -0700
committeryum <yum.food.vr@gmail.com>2024-08-10 02:09:15 -0700
commit4e2422becccc311349325fe436f10326b7210c73 (patch)
tree7363ccbd1a6b9c428c82ed685114e99dfffaf9e6
parent1aa73f3471b12d5fed9feb76a25c40ccf3969ce8 (diff)
Decals can now use a secondary UV channel
This lets you efficiently create a shit ton of tattoos using a single texture. It also lets you place them over seamlines. Just create a secondary UV map in blender and export as FBX. The shader will pick up this secondary channel and use it, if instructed to do so in the decals UI.
-rw-r--r--Editor/tooner.cs3
-rw-r--r--interpolators.cginc32
-rw-r--r--tooner_lighting.cginc28
3 files changed, 38 insertions, 25 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs
index 76aaffc..3673e8c 100644
--- a/Editor/tooner.cs
+++ b/Editor/tooner.cs
@@ -341,8 +341,7 @@ public class ToonerGUI : ShaderGUI {
bc = FindProperty($"_Decal{i}_UV_Select");
editor.RangeProperty(
bc,
- "UV");
-
+ "UV channel");
}
EditorGUI.indentLevel -= 1;
diff --git a/interpolators.cginc b/interpolators.cginc
index 1b04192..00cc5c6 100644
--- a/interpolators.cginc
+++ b/interpolators.cginc
@@ -10,7 +10,7 @@ struct appdata
float4 vertex : POSITION;
float3 normal : NORMAL;
float2 uv0 : TEXCOORD0;
- float2 uv1 : TEXCOORD1;
+ float2 uv2 : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
@@ -19,14 +19,15 @@ struct v2f
{
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
+ float2 uv2 : TEXCOORD1;
#if defined(LIGHTMAP_ON)
- float2 lmuv : TEXCOORD1;
+ float2 lmuv : TEXCOORD2;
#endif
- float3 worldPos : TEXCOORD2;
- float3 normal : TEXCOORD3;
- float3 objPos : TEXCOORD4;
+ float3 worldPos : TEXCOORD3;
+ float3 normal : TEXCOORD4;
+ float3 objPos : TEXCOORD5;
#if defined(SSR_ENABLED)
- float4 screenPos : TEXCOORD5;
+ float4 screenPos : TEXCOORD6;
#endif
UNITY_VERTEX_OUTPUT_STEREO
@@ -38,7 +39,7 @@ struct appdata
{
float4 vertex : POSITION;
float2 uv0 : TEXCOORD0;
- float2 uv1 : TEXCOORD1;
+ float2 uv2 : TEXCOORD1;
float3 normal : NORMAL;
float4 tangent : TANGENT;
@@ -49,20 +50,21 @@ struct v2f
{
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
+ float2 uv2 : TEXCOORD1;
#if defined(LIGHTMAP_ON)
- float2 lmuv : TEXCOORD1;
+ float2 lmuv : TEXCOORD2;
#endif
- float3 normal : TEXCOORD2;
- float4 tangent : TEXCOORD3;
- float3 worldPos : TEXCOORD4;
- float3 objPos : TEXCOORD5;
+ float3 normal : TEXCOORD3;
+ float4 tangent : TEXCOORD4;
+ float3 worldPos : TEXCOORD5;
+ float3 objPos : TEXCOORD6;
- SHADOW_COORDS(6)
+ SHADOW_COORDS(7)
#if defined(VERTEXLIGHT_ON)
- float3 vertexLightColor : TEXCOORD7;
+ float3 vertexLightColor : TEXCOORD8;
#endif
#if defined(SSR_ENABLED)
- float4 screenPos : TEXCOORD8;
+ float4 screenPos : TEXCOORD9;
#endif
UNITY_VERTEX_OUTPUT_STEREO
diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc
index 03e3084..dc16b40 100644
--- a/tooner_lighting.cginc
+++ b/tooner_lighting.cginc
@@ -22,6 +22,7 @@ struct tess_data
{
float4 pos : INTERNALTESSPOS;
float2 uv0 : TEXCOORD0;
+ float2 uv2 : TEXCOORD1;
#if defined(LIGHTMAP_ON)
float2 lmuv : TEXCOORD1;
#endif
@@ -180,10 +181,12 @@ v2f vert(appdata v)
#else
o.normal = UnityObjectToWorldNormal(v.normal);
#endif
+
o.tangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w);
o.uv0 = v.uv0;
+ o.uv2 = v.uv2;
#if defined(LIGHTMAP_ON)
- o.lmuv = v.uv1 * unity_LightmapST.xy + unity_LightmapST.zw;
+ o.lmuv = v.uv2 * unity_LightmapST.xy + unity_LightmapST.zw;
#endif
#if defined(SHADOWS_SCREEN)
TRANSFER_SHADOW(o);
@@ -232,8 +235,9 @@ tess_data hull_vertex(appdata v)
o.normal = UnityObjectToWorldNormal(v.normal);
o.tangent = float4(UnityObjectToWorldDir(v.tangent.xyz), v.tangent.w);
o.uv0 = v.uv0.xy;
+ o.uv2 = v.uv2.xy;
#if defined(LIGHTMAP_ON)
- o.lmuv = v.uv1 * unity_LightmapST.xy + unity_LightmapST.zw;
+ o.lmuv = v.uv2 * unity_LightmapST.xy + unity_LightmapST.zw;
#endif
getVertexLightColorTess(o);
@@ -286,6 +290,7 @@ v2f domain(
patch[1].fieldName * baryc.y + \
patch[2].fieldName * baryc.z;
DOMAIN_INTERP(uv0);
+ DOMAIN_INTERP(uv2);
#if defined(LIGHTMAP_ON)
DOMAIN_INTERP(lmuv);
#endif
@@ -661,6 +666,8 @@ void getOverlayAlbedoRoughness(inout PbrOverlay ov,
#endif // _PBR_OVERLAY3
}
+#define GET_UV(i, which_channel) (which_channel == 0 ? i.uv0 : i.uv2)
+
void applyDecalImpl(
inout float4 albedo,
inout float3 decal_emission,
@@ -674,9 +681,10 @@ void applyDecalImpl(
float emission_strength,
float angle,
bool do_roughness,
- bool do_metallic)
+ bool do_metallic,
+ float which_uv)
{
- float2 d0_uv = ((i.uv0 - 0.5) - tex_st.zw) * tex_st.xy + 0.5;
+ float2 d0_uv = ((GET_UV(i, which_uv) - 0.5) - tex_st.zw) * tex_st.xy + 0.5;
if (abs(angle) > 1E-6) {
float theta = angle * 2.0 * 3.14159265;
@@ -745,7 +753,8 @@ void applyDecal(inout float4 albedo,
_Decal0_Emission_Strength,
_Decal0_Angle,
d0_do_roughness,
- d0_do_metallic);
+ d0_do_metallic,
+ _Decal0_UV_Select);
#endif // _DECAL0
#if defined(_DECAL1)
#if defined(_DECAL1_ROUGHNESS)
@@ -766,7 +775,8 @@ void applyDecal(inout float4 albedo,
_Decal1_Emission_Strength,
_Decal1_Angle,
d1_do_roughness,
- d1_do_metallic);
+ d1_do_metallic,
+ _Decal1_UV_Select);
#endif // _DECAL1
#if defined(_DECAL2)
#if defined(_DECAL2_ROUGHNESS)
@@ -787,7 +797,8 @@ void applyDecal(inout float4 albedo,
_Decal2_Emission_Strength,
_Decal2_Angle,
d2_do_roughness,
- d2_do_metallic);
+ d2_do_metallic,
+ _Decal2_UV_Select);
#endif // _DECAL2
#if defined(_DECAL3)
#if defined(_DECAL3_ROUGHNESS)
@@ -808,7 +819,8 @@ void applyDecal(inout float4 albedo,
_Decal3_Emission_Strength,
_Decal3_Angle,
d3_do_roughness,
- d3_do_metallic);
+ d3_do_metallic,
+ _Decal3_UV_Select);
#endif // _DECAL3
}