From 2356cdf85d2c52f70052828bb5a18419a30d4de9 Mon Sep 17 00:00:00 2001 From: yum Date: Thu, 5 Dec 2024 18:20:03 -0800 Subject: Add second mask for rim lighting & matcap --- Editor/tooner.cs | 66 ++++++++++---- Third_Party/gen_atlas | 239 +++++++++++++++++++++++++++++++++++++++++++++++--- feature_macros.cginc | 4 + globals.cginc | 31 +++++-- tooner.shader | 23 ++++- tooner_lighting.cginc | 46 ++++++++-- 6 files changed, 363 insertions(+), 46 deletions(-) diff --git a/Editor/tooner.cs b/Editor/tooner.cs index 9f444d4..c92f35d 100644 --- a/Editor/tooner.cs +++ b/Editor/tooner.cs @@ -691,7 +691,14 @@ public class ToonerGUI : ShaderGUI { bc = FindProperty($"_Matcap{i}_Mask2_Invert"); enabled = bc.floatValue > 1E-6; EditorGUI.BeginChangeCheck(); - enabled = Toggle("Invert mask", enabled); + enabled = Toggle("Invert mask colors", enabled); + EditorGUI.EndChangeCheck(); + bc.floatValue = enabled ? 1.0f : 0.0f; + + bc = FindProperty($"_Matcap{i}_Mask2_Invert_Alpha"); + enabled = bc.floatValue > 1E-6; + EditorGUI.BeginChangeCheck(); + enabled = Toggle("Invert mask alpha", enabled); EditorGUI.EndChangeCheck(); bc.floatValue = enabled ? 1.0f : 0.0f; @@ -823,7 +830,6 @@ public class ToonerGUI : ShaderGUI { MakeLabel(bc, "Mask"), bc); SetKeyword($"_RIM_LIGHTING{i}_MASK", bc.textureValue); - if (bc.textureValue) { EditorGUI.indentLevel += 1; @@ -835,27 +841,53 @@ public class ToonerGUI : ShaderGUI { bc.floatValue = enabled ? 1.0f : 0.0f; bc = FindProperty($"_Rim_Lighting{i}_Mask_UV_Select"); - RangeProperty( - bc, - "UV channel"); + RangeProperty(bc, "UV channel"); - bc = FindProperty($"_Rim_Lighting{i}_Mask_Sampler_Mode"); - SamplerMode sampler_mode = (SamplerMode) Math.Round(bc.floatValue); - sampler_mode = (SamplerMode) EnumPopup( - MakeLabel("Sampler mode"), sampler_mode); + EditorGUI.indentLevel -= 1; + } + + bc = FindProperty($"_Rim_Lighting{i}_Mask2"); + TexturePropertySingleLine( + MakeLabel(bc, "Mask 2"), + bc); + SetKeyword($"_RIM_LIGHTING{i}_MASK2", bc.textureValue); + if (bc.textureValue) { + EditorGUI.indentLevel += 1; + + bc = FindProperty($"_Rim_Lighting{i}_Mask2_Invert_Colors"); + enabled = bc.floatValue > 1E-6; + EditorGUI.BeginChangeCheck(); + enabled = Toggle("Invert mask colors", enabled); EditorGUI.EndChangeCheck(); - bc.floatValue = (int) sampler_mode; + bc.floatValue = enabled ? 1.0f : 0.0f; + + bc = FindProperty($"_Rim_Lighting{i}_Mask2_Invert_Alpha"); + enabled = bc.floatValue > 1E-6; + EditorGUI.BeginChangeCheck(); + enabled = Toggle("Invert mask alpha", enabled); + EditorGUI.EndChangeCheck(); + bc.floatValue = enabled ? 1.0f : 0.0f; - SetKeyword($"_RIM_LIGHTING{i}_SAMPLER_LINEAR_REPEAT", sampler_mode == SamplerMode.LinearRepeat); - SetKeyword($"_RIM_LIGHTING{i}_SAMPLER_LINEAR_CLAMP", sampler_mode == SamplerMode.LinearClamp); - SetKeyword($"_RIM_LIGHTING{i}_SAMPLER_BILINEAR_REPEAT", sampler_mode == SamplerMode.BilinearRepeat); - SetKeyword($"_RIM_LIGHTING{i}_SAMPLER_BILINEAR_CLAMP", sampler_mode == SamplerMode.BilinearClamp); - SetKeyword($"_RIM_LIGHTING{i}_SAMPLER_POINT_REPEAT", sampler_mode == SamplerMode.PointRepeat); - SetKeyword($"_RIM_LIGHTING{i}_SAMPLER_POINT_CLAMP", sampler_mode == SamplerMode.PointClamp); + bc = FindProperty($"_Rim_Lighting{i}_Mask2_UV_Select"); + RangeProperty(bc, "UV channel"); EditorGUI.indentLevel -= 1; } + bc = FindProperty($"_Rim_Lighting{i}_Mask_Sampler_Mode"); + SamplerMode sampler_mode = (SamplerMode) Math.Round(bc.floatValue); + sampler_mode = (SamplerMode) EnumPopup( + MakeLabel("Sampler mode"), sampler_mode); + EditorGUI.EndChangeCheck(); + bc.floatValue = (int) sampler_mode; + + SetKeyword($"_RIM_LIGHTING{i}_SAMPLER_LINEAR_REPEAT", sampler_mode == SamplerMode.LinearRepeat); + SetKeyword($"_RIM_LIGHTING{i}_SAMPLER_LINEAR_CLAMP", sampler_mode == SamplerMode.LinearClamp); + SetKeyword($"_RIM_LIGHTING{i}_SAMPLER_BILINEAR_REPEAT", sampler_mode == SamplerMode.BilinearRepeat); + SetKeyword($"_RIM_LIGHTING{i}_SAMPLER_BILINEAR_CLAMP", sampler_mode == SamplerMode.BilinearClamp); + SetKeyword($"_RIM_LIGHTING{i}_SAMPLER_POINT_REPEAT", sampler_mode == SamplerMode.PointRepeat); + SetKeyword($"_RIM_LIGHTING{i}_SAMPLER_POINT_CLAMP", sampler_mode == SamplerMode.PointClamp); + bc = FindProperty($"_Rim_Lighting{i}_Center_Eye_Fix"); enabled = bc.floatValue > 1E-6; EditorGUI.BeginChangeCheck(); @@ -2051,6 +2083,8 @@ public class ToonerGUI : ShaderGUI { FloatProperty(bc, "Minimum screen px range"); bc = FindProperty("_Gimmick_Letter_Grid_2_Blurriness"); FloatProperty(bc, "Blurriness"); + bc = FindProperty("_Gimmick_Letter_Grid_2_Alpha_Threshold"); + RangeProperty(bc, "Alpha threshold"); EditorGUI.indentLevel -= 1; } diff --git a/Third_Party/gen_atlas b/Third_Party/gen_atlas index b3a8eff..d814c09 100644 --- a/Third_Party/gen_atlas +++ b/Third_Party/gen_atlas @@ -5,6 +5,7 @@ import subprocess import os import json from PIL import Image +import random # Define the character ranges we want to include CHAR_RANGES = [ @@ -21,22 +22,70 @@ def calculate_grid_size(char_ranges): grid_size += 1 return grid_size -def generate_atlas(font_path, resolution, draw_grid=False): +ATLAS_TYPES = [ + "hardmask", # binary image + "softmask", # anti-aliased image + "sdf", # signed distance field + "psdf", # perpendicular distance field + "msdf", # multi-channel signed distance field + "mtsdf" # combined MSDF and true SDF +] + +def calculate_font_size(resolution, base_size=None): + """Calculate the font size based on resolution, scaling from 512 resolution""" + if base_size is None: + base_size = 32 # Default size at 512 resolution + return (base_size * resolution) // 512 + +def generate_atlas(font_path, resolution, draw_grid=False, type="msdf", font_size=None): + """Generates a font atlas using various distance field techniques. + + This function creates a font atlas using msdf-atlas-gen, then rearranges the + characters to include gaps for non-printable characters. The output is saved + as 'atlas.png' in the current directory. + + Args: + font_path (str): Path to the input font file (.ttf/.otf) + resolution (int): Width and height of the output atlas in pixels + draw_grid (bool, optional): If True, draws red grid lines on the output. + Defaults to False. + type (str, optional): Atlas type to generate. See ATLAS_TYPES. + font_size (int, optional): Base font size in pixels at 512 resolution. + Will be scaled for other resolutions. + + Returns: + bool: True if atlas generation succeeded, False if an error occurred. + + Raises: + subprocess.CalledProcessError: If msdf-atlas-gen fails to execute. + """ + # Get font name from path + font_name = os.path.splitext(os.path.basename(font_path))[0] + # Calculate grid size based on character ranges grid_size = calculate_grid_size(CHAR_RANGES) cell_size = resolution // grid_size + # Calculate font size if not specified, scaling from 512 resolution + if font_size is None: + font_size = calculate_font_size(resolution) + else: + font_size = calculate_font_size(resolution, font_size) + # Convert character ranges to command-line format chars_str = ", ".join(f"[{start}, {end}]" for start, end in CHAR_RANGES) + # Update the output filename to include resolution + output_filename = f"atlas_{font_name}_{resolution}_{type}" + cmd = [ "msdf-atlas-gen/build/bin/Debug/msdf-atlas-gen.exe", "-font", font_path, - "-type", "msdf", + "-type", type, "-format", "png", - "-imageout", "atlas.png", - "-size", "72", - "-pxrange", "5", + "-imageout", f"{output_filename}.png", + "-size", str(font_size), + "-pxrange", "4", "-dimensions", str(resolution), str(resolution), "-chars", chars_str, "-uniformgrid", @@ -50,6 +99,13 @@ def generate_atlas(font_path, resolution, draw_grid=False): try: print("Running msdf-atlas-gen...") + print("Command:", end=" ") + for arg in cmd: + if arg.startswith('-'): + print(f"\n {arg}", end=" ") + else: + print(arg, end=" ") + print() result = subprocess.run(cmd, check=True, capture_output=True, text=True) # Print the output @@ -59,7 +115,10 @@ def generate_atlas(font_path, resolution, draw_grid=False): # Rearrange the atlas to include gaps for non-printable characters print("Rearranging atlas...") - rearrange_atlas(resolution, cell_size, cell_size, draw_grid) + rearrange_atlas(resolution, cell_size, cell_size, draw_grid, type, font_name) + + # Generate or update Unity meta file + generate_unity_meta(output_filename, resolution) return True except subprocess.CalledProcessError as e: print(f"Error generating atlas: {e}") @@ -85,10 +144,12 @@ def draw_grid_lines(image, resolution): draw.line([(resolution-1, 0), (resolution-1, resolution-1)], fill=(255, 0, 0), width=1) draw.line([(0, resolution-1), (resolution-1, resolution-1)], fill=(255, 0, 0), width=1) -def rearrange_atlas(resolution, cell_width, cell_height, draw_grid=False): +def rearrange_atlas(resolution, cell_width, cell_height, draw_grid=False, type="msdf", font_name=""): """Rearrange the atlas to include gaps for non-printable characters""" - original = Image.open("atlas.png") - new_atlas = Image.new('RGB', (resolution, resolution), (0, 0, 0)) + # Update input and output filenames to match generate_atlas format + input_filename = f"atlas_{font_name}_{resolution}_{type}.png" + original = Image.open(input_filename) + new_atlas = Image.new('RGBA', (resolution, resolution), (0, 0, 0, 255)) grid_size = calculate_grid_size(CHAR_RANGES) cell_size = resolution // grid_size @@ -127,16 +188,166 @@ def rearrange_atlas(resolution, cell_width, cell_height, draw_grid=False): used_atlas = new_atlas.crop((0, 0, used_resolution, used_resolution)) final_atlas = used_atlas.resize((resolution, resolution), Image.LANCZOS) - # Save the rearranged atlas, overwriting the original - final_atlas.save("atlas.png") + # Save with the same filename format (no change needed since input/output are the same) + final_atlas.save(input_filename) print("Atlas rearranged successfully!") +def generate_unity_meta(basename, resolution): + """Generate or update Unity meta file for the atlas texture.""" + meta_path = f"{basename}.png.meta" + existing_guid = None + + # Try to read existing GUID if meta file exists + if os.path.exists(meta_path): + with open(meta_path, 'r') as f: + for line in f: + if 'guid: ' in line: + existing_guid = line.split('guid: ')[1].strip() + break + + # Generate new GUID if none exists + guid = existing_guid or ''.join('%x' % random.randrange(16) for _ in range(32)) + + meta_template = f'''fileFormatVersion: 2 +guid: {guid} +TextureImporter: + internalIDToNameTable: [] + externalObjects: {{}} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: {resolution} + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {{x: 0.5, y: 0.5}} + spritePixelsToUnits: 100 + spriteBorder: {{x: 0, y: 0, z: 0, w: 0}} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: {resolution} + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 2 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: {resolution} + resizeAlgorithm: 0 + textureFormat: 3 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 1 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: {resolution} + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {{}} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: +''' + + with open(meta_path, 'w') as f: + f.write(meta_template) + def main(): parser = argparse.ArgumentParser(description='Generate a font atlas using msdf-atlas-gen') parser.add_argument('font_path', help='Path to the font file (.ttf/.otf)') parser.add_argument('resolution', type=int, help='Total atlas resolution (width=height)') - parser.add_argument('--grid', action='store_true', help='Draw grid lines on the output atlas') - + parser.add_argument('--grid', type=bool, default=False, help='Draw grid lines on the output atlas') + parser.add_argument('--type', type=str, default="msdf", choices=ATLAS_TYPES, + help='Type of atlas to generate') + parser.add_argument('--font-size', type=int, help='Base font size in pixels at 512 resolution. Will be scaled for other resolutions.') args = parser.parse_args() # Verify font file exists @@ -144,7 +355,7 @@ def main(): print(f"Error: Font file not found at {args.font_path}") return - generate_atlas(args.font_path, args.resolution, args.grid) + generate_atlas(args.font_path, args.resolution, draw_grid=args.grid, type=args.type, font_size=args.font_size) if __name__ == "__main__": main() diff --git a/feature_macros.cginc b/feature_macros.cginc index 277f159..a002525 100644 --- a/feature_macros.cginc +++ b/feature_macros.cginc @@ -39,6 +39,7 @@ #pragma shader_feature_local _ _MATCAP1_NORMAL #pragma shader_feature_local _ _RIM_LIGHTING0 #pragma shader_feature_local _ _RIM_LIGHTING0_MASK +#pragma shader_feature_local _ _RIM_LIGHTING0_MASK2 #pragma shader_feature_local _ _RIM_LIGHTING0_GLITTER #pragma shader_feature_local _ _RIM_LIGHTING0_POLAR_MASK #pragma shader_feature_local _ _RIM_LIGHTING0_SAMPLER_LINEAR_REPEAT @@ -51,6 +52,7 @@ #pragma shader_feature_local _ _RIM_LIGHTING0_REFLECT_IN_WORLD #pragma shader_feature_local _ _RIM_LIGHTING1 #pragma shader_feature_local _ _RIM_LIGHTING1_MASK +#pragma shader_feature_local _ _RIM_LIGHTING1_MASK2 #pragma shader_feature_local _ _RIM_LIGHTING1_GLITTER #pragma shader_feature_local _ _RIM_LIGHTING1_POLAR_MASK #pragma shader_feature_local _ _RIM_LIGHTING1_SAMPLER_LINEAR_REPEAT @@ -63,6 +65,7 @@ #pragma shader_feature_local _ _RIM_LIGHTING1_REFLECT_IN_WORLD #pragma shader_feature_local _ _RIM_LIGHTING2 #pragma shader_feature_local _ _RIM_LIGHTING2_MASK +#pragma shader_feature_local _ _RIM_LIGHTING2_MASK2 #pragma shader_feature_local _ _RIM_LIGHTING2_GLITTER #pragma shader_feature_local _ _RIM_LIGHTING2_POLAR_MASK #pragma shader_feature_local _ _RIM_LIGHTING2_SAMPLER_LINEAR_REPEAT @@ -75,6 +78,7 @@ #pragma shader_feature_local _ _RIM_LIGHTING2_REFLECT_IN_WORLD #pragma shader_feature_local _ _RIM_LIGHTING3 #pragma shader_feature_local _ _RIM_LIGHTING3_MASK +#pragma shader_feature_local _ _RIM_LIGHTING3_MASK2 #pragma shader_feature_local _ _RIM_LIGHTING3_GLITTER #pragma shader_feature_local _ _RIM_LIGHTING3_POLAR_MASK #pragma shader_feature_local _ _RIM_LIGHTING3_SAMPLER_LINEAR_REPEAT diff --git a/globals.cginc b/globals.cginc index 09bb36b..31e012d 100644 --- a/globals.cginc +++ b/globals.cginc @@ -375,7 +375,8 @@ float _Matcap0_Mask_Invert; float _Matcap0_Mask_UV_Select; float _Matcap0_Center_Eye_Fix; texture2D _Matcap0_Mask2; -float _Matcap0_Mask2_Invert; +float _Matcap0_Mask2_Invert_Colors; +float _Matcap0_Mask2_Invert_Alpha; float _Matcap0_Mask2_UV_Select; float _Matcap0Str; float _Matcap0MixFactor; @@ -403,7 +404,8 @@ float _Matcap1_Mask_Invert; float _Matcap1_Mask_UV_Select; float _Matcap1_Center_Eye_Fix; texture2D _Matcap1_Mask2; -float _Matcap1_Mask2_Invert; +float _Matcap1_Mask2_Invert_Colors; +float _Matcap1_Mask2_Invert_Alpha; float _Matcap1_Mask2_UV_Select; float _Matcap1Str; float _Matcap1MixFactor; @@ -430,8 +432,12 @@ float3 _Rim_Lighting0_Color; texture2D _Rim_Lighting0_Mask; float _Rim_Lighting0_Mask_Invert; float _Rim_Lighting0_Mask_UV_Select; -float _Rim_Lighting0_Center_Eye_Fix; float _Rim_Lighting0_Mask_Sampler_Mode; +texture2D _Rim_Lighting0_Mask2; +float _Rim_Lighting0_Mask2_Invert_Colors; +float _Rim_Lighting0_Mask2_Invert_Alpha; +float _Rim_Lighting0_Mask2_UV_Select; +float _Rim_Lighting0_Center_Eye_Fix; float _Rim_Lighting0_Center; float _Rim_Lighting0_Power; float _Rim_Lighting0_Strength; @@ -462,8 +468,12 @@ float3 _Rim_Lighting1_Color; texture2D _Rim_Lighting1_Mask; float _Rim_Lighting1_Mask_Invert; float _Rim_Lighting1_Mask_UV_Select; -float _Rim_Lighting1_Center_Eye_Fix; float _Rim_Lighting1_Mask_Sampler_Mode; +texture2D _Rim_Lighting1_Mask2; +float _Rim_Lighting1_Mask2_Invert_Colors; +float _Rim_Lighting1_Mask2_Invert_Alpha; +float _Rim_Lighting1_Mask2_UV_Select; +float _Rim_Lighting1_Center_Eye_Fix; float _Rim_Lighting1_Center; float _Rim_Lighting1_Power; float _Rim_Lighting1_Strength; @@ -494,8 +504,12 @@ float3 _Rim_Lighting2_Color; texture2D _Rim_Lighting2_Mask; float _Rim_Lighting2_Mask_Invert; float _Rim_Lighting2_Mask_UV_Select; -float _Rim_Lighting2_Center_Eye_Fix; float _Rim_Lighting2_Mask_Sampler_Mode; +texture2D _Rim_Lighting2_Mask2; +float _Rim_Lighting2_Mask2_Invert_Colors; +float _Rim_Lighting2_Mask2_Invert_Alpha; +float _Rim_Lighting2_Mask2_UV_Select; +float _Rim_Lighting2_Center_Eye_Fix; float _Rim_Lighting2_Center; float _Rim_Lighting2_Power; float _Rim_Lighting2_Strength; @@ -526,8 +540,12 @@ float3 _Rim_Lighting3_Color; texture2D _Rim_Lighting3_Mask; float _Rim_Lighting3_Mask_Invert; float _Rim_Lighting3_Mask_UV_Select; -float _Rim_Lighting3_Center_Eye_Fix; float _Rim_Lighting3_Mask_Sampler_Mode; +texture2D _Rim_Lighting3_Mask2; +float _Rim_Lighting3_Mask2_Invert_Colors; +float _Rim_Lighting3_Mask2_Invert_Alpha; +float _Rim_Lighting3_Mask2_UV_Select; +float _Rim_Lighting3_Center_Eye_Fix; float _Rim_Lighting3_Center; float _Rim_Lighting3_Power; float _Rim_Lighting3_Strength; @@ -761,6 +779,7 @@ float _Gimmick_Letter_Grid_2_Global_Offset; float _Gimmick_Letter_Grid_2_Screen_Px_Range; float _Gimmick_Letter_Grid_2_Min_Screen_Px_Range; float _Gimmick_Letter_Grid_2_Blurriness; +float _Gimmick_Letter_Grid_2_Alpha_Threshold; #endif #if defined(_GIMMICK_AL_CHROMA_00) diff --git a/tooner.shader b/tooner.shader index abbf57f..1f37a78 100644 --- a/tooner.shader +++ b/tooner.shader @@ -276,6 +276,7 @@ Shader "yum_food/tooner" _Gimmick_Letter_Grid_2_Screen_Px_Range("Screen px range (from msdfgen)", Float) = 10 _Gimmick_Letter_Grid_2_Min_Screen_Px_Range("Minimum screen px range", Float) = 1 _Gimmick_Letter_Grid_2_Blurriness("Blurriness", Float) = 0.5 + _Gimmick_Letter_Grid_2_Alpha_Threshold("Alpha threshold", Range(0, 1)) = 0.5 [MaterialToggle] _Explode_Toggle("Explode toggle", Float) = 0 _Explode_Phase("Explode phase", Range(0, 1)) = 0 @@ -310,7 +311,8 @@ Shader "yum_food/tooner" _Matcap0_Mask_Invert("Invert mask", Float) = 0.0 _Matcap0_Mask_UV_Select("Matcap mask UV select", Range(0, 7)) = 0 _Matcap0_Mask2("Matcap mask 2", 2D) = "white" {} - _Matcap0_Mask2_Invert("Invert mask", Float) = 0.0 + _Matcap0_Mask2_Invert_Colors("Invert mask", Float) = 0.0 + _Matcap0_Mask2_Invert_Alpha("Invert mask", Float) = 0.0 _Matcap0_Mask2_UV_Select("Matcap mask UV select", Range(0, 7)) = 0 _Matcap0Mode("Matcap mode", Float) = 0 _Matcap0Str("Matcap strength", Float) = 1 @@ -334,7 +336,8 @@ Shader "yum_food/tooner" _Matcap1_Mask_Invert("Invert mask", Float) = 0.0 _Matcap1_Mask_UV_Select("Matcap mask UV select", Range(0, 7)) = 0 _Matcap1_Mask2("Matcap mask 2", 2D) = "white" {} - _Matcap1_Mask2_Invert("Invert mask", Float) = 0.0 + _Matcap1_Mask2_Invert_Colors("Invert mask", Float) = 0.0 + _Matcap1_Mask2_Invert_Alpha("Invert mask", Float) = 0.0 _Matcap1_Mask2_UV_Select("Matcap mask UV select", Range(0, 7)) = 0 _Matcap1Mode("Matcap mode", Float) = 0 _Matcap1Str("Matcap strength", Float) = 1 @@ -359,6 +362,10 @@ Shader "yum_food/tooner" _Rim_Lighting0_Mask_Invert("Invert rim lighting mask", Float) = 0.0 _Rim_Lighting0_Mask_UV_Select("mask UV select", Range(0, 7)) = 0.0 _Rim_Lighting0_Mask_Sampler_Mode("mask sampler mode", Range(0, 1)) = 0.0 + _Rim_Lighting0_Mask2("Rim lighting mask 2", 2D) = "white" {} + _Rim_Lighting0_Mask2_Invert_Colors("Invert rim lighting mask 2", Float) = 0.0 + _Rim_Lighting0_Mask2_Invert_Alpha("Invert rim lighting mask 2", Float) = 0.0 + _Rim_Lighting0_Mask2_UV_Select("mask 2 UV select", Range(0, 7)) = 0.0 _Rim_Lighting0_Color("Rim lighting color", Color) = (1, 1, 1, 1) _Rim_Lighting0_Center("Rim lighting center", Float) = 0.5 _Rim_Lighting0_Power("Rim lighting power", Float) = 2.0 @@ -385,6 +392,10 @@ Shader "yum_food/tooner" _Rim_Lighting1_Mask_Invert("Invert rim lighting mask", Float) = 0.0 _Rim_Lighting1_Mask_UV_Select("mask UV select", Range(0, 7)) = 0.0 _Rim_Lighting1_Mask_Sampler_Mode("mask sampler mode", Range(0, 1)) = 0.0 + _Rim_Lighting1_Mask2("Rim lighting mask 2", 2D) = "white" {} + _Rim_Lighting1_Mask2_Invert_Colors("Invert rim lighting mask 2", Float) = 0.0 + _Rim_Lighting1_Mask2_Invert_Alpha("Invert rim lighting mask 2", Float) = 0.0 + _Rim_Lighting1_Mask2_UV_Select("mask 2 UV select", Range(0, 7)) = 0.0 _Rim_Lighting1_Color("Rim lighting color", Color) = (1, 1, 1, 1) _Rim_Lighting1_Center("Rim lighting center", Float) = 0.5 _Rim_Lighting1_Power("Rim lighting power", Float) = 2.0 @@ -411,6 +422,10 @@ Shader "yum_food/tooner" _Rim_Lighting2_Mask_Invert("Invert rim lighting mask", Float) = 0.0 _Rim_Lighting2_Mask_UV_Select("mask UV select", Range(0, 7)) = 0.0 _Rim_Lighting2_Mask_Sampler_Mode("mask sampler mode", Range(0, 1)) = 0.0 + _Rim_Lighting2_Mask2("Rim lighting mask 2", 2D) = "white" {} + _Rim_Lighting2_Mask2_Invert_Colors("Invert rim lighting mask 2", Float) = 0.0 + _Rim_Lighting2_Mask2_Invert_Alpha("Invert rim lighting mask 2", Float) = 0.0 + _Rim_Lighting2_Mask2_UV_Select("mask 2 UV select", Range(0, 7)) = 0.0 _Rim_Lighting2_Color("Rim lighting color", Color) = (1, 1, 1, 1) _Rim_Lighting2_Center("Rim lighting center", Float) = 0.5 _Rim_Lighting2_Power("Rim lighting power", Float) = 2.0 @@ -437,6 +452,10 @@ Shader "yum_food/tooner" _Rim_Lighting3_Mask_Invert("Invert rim lighting mask", Float) = 0.0 _Rim_Lighting3_Mask_UV_Select("mask UV select", Range(0, 7)) = 0.0 _Rim_Lighting3_Mask_Sampler_Mode("mask sampler mode", Range(0, 1)) = 0.0 + _Rim_Lighting3_Mask2("Rim lighting mask 2", 2D) = "white" {} + _Rim_Lighting3_Mask2_Invert_Colors("Invert rim lighting mask 2", Float) = 0.0 + _Rim_Lighting3_Mask2_Invert_Alpha("Invert rim lighting mask 2", Float) = 0.0 + _Rim_Lighting3_Mask2_UV_Select("mask 2 UV select", Range(0, 7)) = 0.0 _Rim_Lighting3_Color("Rim lighting color", Color) = (1, 1, 1, 1) _Rim_Lighting3_Center("Rim lighting center", Float) = 0.5 _Rim_Lighting3_Power("Rim lighting power", Float) = 2.0 diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc index 9b0388f..430d8a5 100644 --- a/tooner_lighting.cginc +++ b/tooner_lighting.cginc @@ -1195,7 +1195,7 @@ void mixOverlayAlbedoRoughnessMetallic(inout float4 albedo, #if defined(_PBR_OVERLAY2) #if defined(_PBR_OVERLAY2_MIX_ALPHA_BLEND) - albedo.rgb = lerp(albedo.rgb, ov.ov2_albedo.rgb, ov.ov2_albedo.a); + albedo.rgb = lerp(albedo.rgb, ov.ov2_albedo.rgb, a2); #if defined(_PBR_OVERLAY2_ROUGHNESS) roughness = lerp(roughness, ov.ov2_roughness, a2); #endif @@ -1617,8 +1617,8 @@ float4 effect(inout v2f i, out float depth) float4 matcap_mask2_raw = _Matcap0_Mask2.SampleLevel(linear_repeat_s, get_uv_by_channel(i, _Matcap0_Mask2_UV_Select), 0); float matcap_mask2 = matcap_mask2_raw.r; - matcap_mask2 = (bool) round(_Matcap0_Mask2_Invert) ? 1 - matcap_mask2 : matcap_mask2; - matcap_mask2 *= matcap_mask2_raw.a; + matcap_mask2 = _Matcap0_Mask2_Invert_Colors ? 1 - matcap_mask2 : matcap_mask2; + matcap_mask2 *= _Matcap0_Mask2_Invert_Alpha ? 1 - matcap_mask2_raw.a : matcap_mask2_raw.a; matcap_mask *= matcap_mask2; } #endif @@ -1705,8 +1705,8 @@ float4 effect(inout v2f i, out float depth) float4 matcap_mask2_raw = _Matcap1_Mask2.SampleLevel(linear_repeat_s, get_uv_by_channel(i, _Matcap1_Mask2_UV_Select), 0); float matcap_mask2 = matcap_mask2_raw.r; - matcap_mask2 = (bool) round(_Matcap1_Mask2_Invert) ? 1 - matcap_mask2 : matcap_mask2; - matcap_mask2 *= matcap_mask2_raw.a; + matcap_mask2 = _Matcap1_Mask2_Invert_Colors ? 1 - matcap_mask2 : matcap_mask2; + matcap_mask2 *= _Matcap1_Mask2_Invert_Alpha ? 1 - matcap_mask2_raw.a : matcap_mask2_raw.a; matcap_mask *= matcap_mask2; } #endif @@ -1864,6 +1864,14 @@ float4 effect(inout v2f i, out float depth) #else float matcap_mask = 1; #endif +#if defined(_RIM_LIGHTING0_MASK2) + float4 matcap_mask2_raw = _Rim_Lighting0_Mask2.SampleBias(GET_SAMPLER_RL0, + get_uv_by_channel(i, _Rim_Lighting0_Mask2_UV_Select), _Global_Sample_Bias); + float matcap_mask2 = matcap_mask2_raw.r; + matcap_mask2 = _Rim_Lighting0_Mask2_Invert_Colors ? 1 - matcap_mask2 : matcap_mask2; + matcap_mask2 *= _Rim_Lighting0_Mask2_Invert_Alpha ? 1 - matcap_mask2_raw.a : matcap_mask2_raw.a; + matcap_mask *= matcap_mask2; +#endif #if defined(_MATCAP0) if (_Matcap0_Overwrite_Rim_Lighting_0) { matcap_mask *= matcap_overwrite_mask[0]; @@ -1966,6 +1974,14 @@ float4 effect(inout v2f i, out float depth) #else float matcap_mask = 1; #endif +#if defined(_RIM_LIGHTING1_MASK2) + float4 matcap_mask2_raw = _Rim_Lighting1_Mask2.SampleBias(GET_SAMPLER_RL1, + get_uv_by_channel(i, _Rim_Lighting1_Mask2_UV_Select), _Global_Sample_Bias); + float matcap_mask2 = matcap_mask2_raw.r; + matcap_mask2 = _Rim_Lighting1_Mask2_Invert_Colors ? 1 - matcap_mask2 : matcap_mask2; + matcap_mask2 *= _Rim_Lighting1_Mask2_Invert_Alpha ? 1 - matcap_mask2_raw.a : matcap_mask2_raw.a; + matcap_mask *= matcap_mask2; +#endif #if defined(_MATCAP0) if (_Matcap0_Overwrite_Rim_Lighting_1) { matcap_mask *= matcap_overwrite_mask[0]; @@ -2068,6 +2084,14 @@ float4 effect(inout v2f i, out float depth) #else float matcap_mask = 1; #endif +#if defined(_RIM_LIGHTING2_MASK2) + float4 matcap_mask2_raw = _Rim_Lighting2_Mask2.SampleBias(GET_SAMPLER_RL2, + get_uv_by_channel(i, _Rim_Lighting2_Mask2_UV_Select), _Global_Sample_Bias); + float matcap_mask2 = matcap_mask2_raw.r; + matcap_mask2 = _Rim_Lighting2_Mask2_Invert_Colors ? 1 - matcap_mask2 : matcap_mask2; + matcap_mask2 *= _Rim_Lighting2_Mask2_Invert_Alpha ? 1 - matcap_mask2_raw.a : matcap_mask2_raw.a; + matcap_mask *= matcap_mask2; +#endif #if defined(_MATCAP0) if (_Matcap0_Overwrite_Rim_Lighting_2) { matcap_mask *= matcap_overwrite_mask[0]; @@ -2170,6 +2194,14 @@ float4 effect(inout v2f i, out float depth) #else float matcap_mask = 1; #endif +#if defined(_RIM_LIGHTING3_MASK2) + float4 matcap_mask2_raw = _Rim_Lighting3_Mask2.SampleBias(GET_SAMPLER_RL3, + get_uv_by_channel(i, _Rim_Lighting3_Mask2_UV_Select), _Global_Sample_Bias); + float matcap_mask2 = matcap_mask2_raw.r; + matcap_mask2 = _Rim_Lighting3_Mask2_Invert_Colors ? 1 - matcap_mask2 : matcap_mask2; + matcap_mask2 *= _Rim_Lighting3_Mask2_Invert_Alpha ? 1 - matcap_mask2_raw.a : matcap_mask2_raw.a; + matcap_mask *= matcap_mask2; +#endif #if defined(_MATCAP0) if (_Matcap0_Overwrite_Rim_Lighting_3) { matcap_mask *= matcap_overwrite_mask[0]; @@ -2376,9 +2408,7 @@ float4 effect(inout v2f i, out float depth) #endif screen_px_range = max(0.5 * dot(unit_range, screen_tex_size), _Gimmick_Letter_Grid_2_Min_Screen_Px_Range); } - float screen_px_distance = screen_px_range * (sd - 0.5); - - // Calculate smoothstep range based on screen size + float screen_px_distance = screen_px_range * (sd - _Gimmick_Letter_Grid_2_Alpha_Threshold); float smooth_range = (length(grid_res) / sqrt(screen_px_range)) * _Gimmick_Letter_Grid_2_Blurriness; float op = smoothstep(-smooth_range, smooth_range, screen_px_distance); op *= mask; -- cgit v1.2.3