diff options
| author | yum <yum.food.vr@gmail.com> | 2024-05-25 12:51:26 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2024-05-25 12:51:26 -0700 |
| commit | 8dd60d9c674ea5859f13471525419aaa41534dce (patch) | |
| tree | 22ec2478dea1005437088df835599598af5f0e44 | |
| parent | 72a4f411ff04375caffebc557592b98bcf700ae1 (diff) | |
Add scale & offset to some texture fields
| -rw-r--r-- | Editor/tooner.cs | 35 | ||||
| -rw-r--r-- | globals.cginc | 10 | ||||
| -rw-r--r-- | tooner.shader | 2 | ||||
| -rw-r--r-- | tooner_lighting.cginc | 25 |
4 files changed, 65 insertions, 7 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs index ca2d1c8..29d6a67 100644 --- a/Editor/tooner.cs +++ b/Editor/tooner.cs @@ -54,6 +54,9 @@ public class ToonerGUI : ShaderGUI { MakeLabel(bct, "Base color (RGBA)"), bct, bc); + if (bct.textureValue) { + editor.TextureScaleOffsetProperty(bct); + } SetKeyword("_BASECOLOR_MAP", bct.textureValue); } @@ -63,6 +66,9 @@ public class ToonerGUI : ShaderGUI { MakeLabel(bct, "Normal"), bct, FindProperty("_Tex_NormalStr")); + if (bct.textureValue) { + editor.TextureScaleOffsetProperty(bct); + } SetKeyword("_NORMAL_MAP", bct.textureValue); } @@ -73,6 +79,9 @@ public class ToonerGUI : ShaderGUI { MakeLabel(bct, "Metallic (RGBA)"), bct, bc); + if (bct.textureValue) { + editor.TextureScaleOffsetProperty(bct); + } SetKeyword("_METALLIC_MAP", bct.textureValue); } @@ -83,6 +92,9 @@ public class ToonerGUI : ShaderGUI { MakeLabel(bct, "Roughness (RGBA)"), bct, bc); + if (bct.textureValue) { + editor.TextureScaleOffsetProperty(bct); + } SetKeyword("_ROUGHNESS_MAP", bct.textureValue); } @@ -102,6 +114,9 @@ public class ToonerGUI : ShaderGUI { MakeLabel(bct, "Base color (RGBA)"), bct, bc); + if (bct.textureValue) { + editor.TextureScaleOffsetProperty(bct); + } SetKeyword("_PBR_OVERLAY_BASECOLOR_MAP", bct.textureValue); bct = FindProperty("_PBR_Overlay_NormalTex"); @@ -109,6 +124,9 @@ public class ToonerGUI : ShaderGUI { MakeLabel(bct, "Normal"), bct, FindProperty("_PBR_Overlay_Tex_NormalStr")); + if (bct.textureValue) { + editor.TextureScaleOffsetProperty(bct); + } SetKeyword("_PBR_OVERLAY_NORMAL_MAP", bct.textureValue); bc = FindProperty("_PBR_Overlay_Metallic"); @@ -117,6 +135,9 @@ public class ToonerGUI : ShaderGUI { MakeLabel(bct, "Metallic (RGBA)"), bct, bc); + if (bct.textureValue) { + editor.TextureScaleOffsetProperty(bct); + } SetKeyword("_PBR_OVERLAY_METALLIC_MAP", bct.textureValue); bc = FindProperty("_PBR_Overlay_Roughness"); @@ -125,7 +146,16 @@ public class ToonerGUI : ShaderGUI { MakeLabel(bct, "Roughness (RGBA)"), bct, bc); + if (bct.textureValue) { + editor.TextureScaleOffsetProperty(bct); + } SetKeyword("_PBR_OVERLAY_ROUGHNESS_MAP", bct.textureValue); + + bct = FindProperty("_PBR_Overlay_Mask"); + editor.TexturePropertySingleLine( + MakeLabel(bct, "Mask"), + bct); + SetKeyword("_PBR_OVERLAY_MASK", bct.textureValue); } } @@ -474,6 +504,11 @@ public class ToonerGUI : ShaderGUI { editor.FloatProperty( bc, "Glitter angle"); + + bc = FindProperty("_Glitter_Power"); + editor.FloatProperty( + bc, + "Glitter power"); } } diff --git a/globals.cginc b/globals.cginc index 275326c..4d80955 100644 --- a/globals.cginc +++ b/globals.cginc @@ -8,18 +8,27 @@ float _Metallic; float _Roughness; texture2D _BaseColorTex; +float4 _BaseColorTex_ST; texture2D _NormalTex; +float4 _NormalTex_ST; texture2D _MetallicTex; +float4 _MetallicTex_ST; texture2D _RoughnessTex; +float4 _RoughnessTex_ST; float4 _PBR_Overlay_BaseColor; float _PBR_Overlay_Metallic; float _PBR_Overlay_Roughness; texture2D _PBR_Overlay_BaseColorTex; +float4 _PBR_Overlay_BaseColorTex_ST; texture2D _PBR_Overlay_NormalTex; +float4 _PBR_Overlay_NormalTex_ST; texture2D _PBR_Overlay_MetallicTex; +float4 _PBR_Overlay_MetallicTex_ST; texture2D _PBR_Overlay_RoughnessTex; +float4 _PBR_Overlay_RoughnessTex_ST; float _PBR_Overlay_Tex_NormalStr; +texture2D _PBR_Overlay_Mask; texture2D _EmissionTex; float _EmissionStrength; @@ -51,6 +60,7 @@ float _Glitter_Speed; float _Glitter_Seed; float _Glitter_Brightness; float _Glitter_Angle; +float _Glitter_Power; float _Explode_Phase; diff --git a/tooner.shader b/tooner.shader index a0c3209..29a2afb 100644 --- a/tooner.shader +++ b/tooner.shader @@ -20,6 +20,7 @@ Shader "yum_food/tooner" [NoScaleOffset] _PBR_Overlay_MetallicTex("Metallic", 2D) = "white" {} [NoScaleOffset] _PBR_Overlay_RoughnessTex("Roughness", 2D) = "black" {} [NoScaleOffset] _PBR_Overlay_Tex_NormalStr("Normal texture strength", Range(0, 10)) = 1 + [NoScaleOffset] _PBR_Overlay_Mask("Mask", 2D) = "white" {} [NoScaleOffset] _EmissionTex("Emission map", 2D) = "black" {} _EmissionStrength("Emission strength", Range(0, 2)) = 0 @@ -53,6 +54,7 @@ Shader "yum_food/tooner" _Glitter_Seed("Glitter seed", float) = 1 _Glitter_Brightness("Glitter brightness", float) = 1 _Glitter_Angle("Glitter angle", Range(0, 90)) = 90 + _Glitter_Power("Glitter power", float) = 30 [MaterialToggle] _Explode_Toggle("Explode toggle", Float) = 0 _Explode_Phase("Explode phase", Range(0, 1)) = 0 diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc index 787b911..baf3080 100644 --- a/tooner_lighting.cginc +++ b/tooner_lighting.cginc @@ -360,7 +360,7 @@ float get_glitter(float2 uv, float iddx, float iddy, float3 worldPos, float3 nor float ndotl = abs(dot(normal, normalize(_WorldSpaceCameraPos.xyz - worldPos))); float cutoff = cos((_Glitter_Angle / 180) * 3.14159); - glitter *= saturate(pow(ndotl / cutoff, 30)); + glitter *= saturate(pow(ndotl / cutoff, _Glitter_Power)); //glitter = ndotl > cutoff ? glitter : 0; } @@ -385,6 +385,8 @@ float2 matcap_distortion0(float2 matcap_uv) { return matcap_uv; } +#define UV_SCOFF(uv, tex_st) (uv) * (tex_st).xy + (tex_st).zw + float4 effect(inout v2f i) { float iddx = ddx(i.uv.x) / 4; @@ -398,7 +400,7 @@ float4 effect(inout v2f i) #endif #if defined(_BASECOLOR_MAP) - float4 albedo = _BaseColorTex.SampleGrad(linear_repeat_s, i.uv, iddx, iddy); + float4 albedo = _BaseColorTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _BaseColorTex_ST), iddx, iddy); albedo *= _BaseColor; #else float4 albedo = _BaseColor; @@ -423,11 +425,19 @@ float4 effect(inout v2f i) #if defined(_PBR_OVERLAY) #if defined(_PBR_OVERLAY_BASECOLOR_MAP) - float4 ov_albedo = _PBR_Overlay_BaseColorTex.SampleGrad(linear_repeat_s, i.uv, iddx, iddy); + float4 ov_albedo = _PBR_Overlay_BaseColorTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _PBR_Overlay_BaseColorTex_ST), iddx, iddy); ov_albedo *= _PBR_Overlay_BaseColor; #else float4 ov_albedo = _BaseColor; #endif // _PBR_OVERLAY_BASECOLOR_MAP + +#if defined(_PBR_OVERLAY_MASK) + float ov_mask = _PBR_Overlay_Mask.SampleGrad(linear_repeat_s, i.uv, iddx, iddy); +#else + float ov_mask = 1; +#endif + ov_albedo.a *= ov_mask; + #endif // _PBR_OVERLAY #if defined(_NORMAL_MAP) @@ -435,7 +445,8 @@ float4 effect(inout v2f i) // flat normals when far away. If we don't do this, then we see moire effects // on e.g. striped normal maps. float fw = clamp(fwidth(i.uv), .001, 1) * 1200; - float3 raw_normal = UnpackScaleNormal(_NormalTex.SampleGrad(linear_repeat_s, i.uv, iddx/2, iddy/2), _Tex_NormalStr); + float3 raw_normal = UnpackScaleNormal(_NormalTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _NormalTex_ST), iddx/2, iddy/2), _Tex_NormalStr); + raw_normal = normalize(raw_normal); raw_normal = BlendNormals( (1/fw) * raw_normal, @@ -447,7 +458,7 @@ float4 effect(inout v2f i) // flat normals when far away. If we don't do this, then we see moire effects // on e.g. striped normal maps. //float3 raw_normal = UnpackScaleNormal(_PBR_Overlay_NormalTex.SampleGrad(linear_repeat_s, i.uv, iddx/2, iddy/2), _PBR_Overlay_Tex_NormalStr); - float3 raw_normal_2 = UnpackScaleNormal(_PBR_Overlay_NormalTex.SampleGrad(linear_repeat_s, i.uv, iddx/2, iddy/2), _PBR_Overlay_Tex_NormalStr * ov_albedo.a); + float3 raw_normal_2 = UnpackScaleNormal(_PBR_Overlay_NormalTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _PBR_Overlay_NormalTex_ST), iddx/2, iddy/2), _PBR_Overlay_Tex_NormalStr * ov_albedo.a); raw_normal = BlendNormals( raw_normal, @@ -466,12 +477,12 @@ float4 effect(inout v2f i) #endif // _NORMAL_MAP #if defined(_METALLIC_MAP) - float metallic = _MetallicTex.SampleGrad(linear_repeat_s, i.uv, iddx, iddy); + float metallic = _MetallicTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _MetallicTex_ST), iddx, iddy); #else float metallic = _Metallic; #endif #if defined(_ROUGHNESS_MAP) - float roughness = _RoughnessTex.SampleGrad(linear_repeat_s, i.uv, iddx, iddy); + float roughness = _RoughnessTex.SampleGrad(linear_repeat_s, UV_SCOFF(i.uv, _RoughnessTex_ST), iddx, iddy); #else float roughness = _Roughness; #endif |
