Skip to content

Commit

Permalink
Merge pull request #1357 from anatawa12/fix-outline-masks
Browse files Browse the repository at this point in the history
fix: optimize texture broke outline mask
  • Loading branch information
anatawa12 authored Nov 30, 2024
2 parents d599bdf + c2b32ca commit cc85d9a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 71 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog].
### Removed

### Fixed
- Optimize Texture may break liltoon outline mask `#1357`

### Security

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog].
### Removed

### Fixed
- Optimize Texture may break liltoon outline mask `#1357`

### Security

Expand Down
146 changes: 75 additions & 71 deletions Editor/APIInternal/ShaderInformation.Liltoon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ namespace Anatawa12.AvatarOptimizer.APIInternal;
[InitializeOnLoad]
internal class LiltoonShaderInformation : ShaderInformation
{
private bool isOutline;

private LiltoonShaderInformation(string name)
{
isOutline = name.Contains("Outline");
}

internal override bool IsInternalInformation => true;

public override ShaderInformationKind SupportedInformationKind =>
Expand All @@ -30,87 +37,84 @@ private static void Register()
// check if version is supported version
if (versionValue > supportedLiltoon) return;

var information = new LiltoonShaderInformation();
foreach (var guid in guids)
foreach (var (guid, name) in guids)
{
ShaderInformationRegistry.RegisterShaderInformationWithGUID(guid, information);
ShaderInformationRegistry.RegisterShaderInformationWithGUID(guid, new LiltoonShaderInformation(name));
}
}

private static int supportedLiltoon = 44;

private static string[] guids =
private static (string, string)[] guids =
{
"544c75f56e9af8048b29a6ace5f52091", // lts_fur_cutout.shader
"7ec9f85eb7ee04943adfe19c2ba5901f", // lts_furonly_cutout.shader
"00795bf598b44dc4e9bd363348e77085", // lts_fakeshadow.shader
"3eef4aee6ba0de047b0d40409ea2891c", // lts_tess.shader
"61b4f98a5d78b4a4a9d89180fac793fc", // ltspass_opaque.shader
"df12117ecd77c31469c224178886498e", // lts.shader
"dce3f3e248acc7b4daeda00daf616b4d", // lts_ref.shader
"14006db8206fb304aa86110d57626d40", // ltspass_tess_cutout.shader
"bdf24b2e925ce8a4fb0e903889a52e0e", // ltspass_tess_transparent.shader
"fba17785d6b2c594ab6c0303c834da65", // lts_oo.shader
"62df797f407281640a224388953448cc", // ltsl_twotrans_o.shader
"afa1a194f5a2fd243bda3a17bca1b36e", // lts_tess_trans.shader
"b269573b9937b8340b3e9e191a3ba5a8", // lts_onetrans.shader
"165365ab7100a044ca85fc8c33548a62", // lts_trans.shader
"9294844b15dca184d914a632279b24e1", // ltsmulti.shader
"59b5e58e88aae8a4ca42d1a7253e2fb2", // ltspass_lite_opaque.shader
"583a88005abb81a4ebbce757b4851a0d", // ltsl_o.shader
"82226adb1a0b8c4418f574cfdcf523da", // ltsl_twotrans.shader
"7171688840c632447b22ec14e2bdef7e", // lts_onetrans_o.shader
"c6d605ee23b18fc46903f38c67db701f", // lts_tess_o.shader
"33aad051c4a3a844a8f9330addb86a97", // lts_furonly.shader
"0e3ece1bd59542743bccadb21f68318e", // ltsl_trans.shader
"381af8ba8e1740a41b9768ccfb0416c2", // ltsl.shader
"d7af54cdd86902d41b8c240e06b93009", // ltsmulti_ref.shader
"8cf5267d397b04846856f6d3d9561da0", // ltsl_cutout_o.shader
"90f83c35b0769a748abba5d0880f36d5", // lts_tess_onetrans.shader
"3c79b10c7e0b2784aaa4c2f8dd17d55e", // lts_trans_o.shader
"85d6126cae43b6847aff4b13f4adb8ec", // lts_cutout.shader
"3b3957e6c393b114bab6f835b4ed8f5d", // lts_cutout_oo.shader
"d28e4b78ba8368e49a44f86c0291df58", // ltsl_overlay.shader
"2683fad669f20ec49b8e9656954a33a8", // ltspass_transparent.shader
"7e61dbad981ad4f43a03722155db1c6a", // lts_tess_twotrans_o.shader
"67ed0252d63362a4ab23707a720508b7", // lts_tess_onetrans_o.shader
"7e398ea50f9b70045b1774e05b46a39f", // lts_tess_twotrans.shader
"7a7ac427f85673a45a3e4190fc10bc28", // ltspass_tess_opaque.shader
"9b0c2630b12933248922527d4507cfa9", // lts_tess_trans_o.shader
"33e950d038b8dfd4f824f3985c2abfb7", // lts_overlay_one.shader
"efa77a80ca0344749b4f19fdd5891cbe", // lts_o.shader
"8a6ef0489c3ffbf46812460af3d52bb0", // ltspass_lite_cutout.shader
"f8d9dfac6dbfaaf4c9c3aaf4bd8c955f", // lts_furonly_two.shader
"3fb94a39b2685ee4d9817dcaf6542d99", // lts_ref_blur.shader
"69f861c14129e724096c0955f8079012", // ltsmulti_gem.shader
"3b4aa19949601f046a20ca8bdaee929f", // lts_cutout_o.shader
"0c762f24b85918a49812fc5690619178", // lts_trans_oo.shader
"ad219df2a46e841488aee6a013e84e36", // ltspass_cutout.shader
"55706696b2bdb5d4d8541b89e17085c8", // lts_fur.shader
"94274b8ef5d3af842b9427384cba3a8f", // lts_overlay.shader
"fd68f52288a6b0243bf6c217bf0930ea", // ltspass_proponly.shader
"9cf054060007d784394b8b0bb703e441", // lts_twotrans_o.shader
"6a77405f7dfdc1447af58854c7f43f39", // lts_twotrans.shader
"bbfffd5515b843c41a85067191cbf687", // lts_tess_cutout.shader
"dc9ded9f9d6f16c4e92cbb8f4269ae31", // ltsl_overlay_one.shader
"2bde4bd29a2a70a4d9cf98772a6717ac", // ltspass_dummy.shader
"34c2907eba944ed45a43970e0c11bcfd", // ltsl_onetrans.shader
"a8d94439709469942bc7dcc9156ba110", // lts_gem.shader
"701268c07d37f5441b25b2cb99fae4b3", // ltsl_onetrans_o.shader
"51b2dee0ab07bd84d8147601ff89e511", // ltsmulti_o.shader
"1c12a37046f07ac4486881deaf0187ea", // ltsl_trans_o.shader
"b957dce3d03ff5445ac989f8de643c7f", // ltsl_cutout.shader
"5ba517885727277409feada18effa4a6", // lts_tess_cutout_o.shader
"8773c83ab40fff24b800f74360819a6c", // ltspass_lite_transparent.shader
"54bc8b41278802d4a81b27fe402994e2", // lts_fur_two.shader
"1e50f1bc4d1b0e34cbf16b82589f6407", // ltsmulti_fur.shader
"f96a89829ccb1e54b85214550519a8d6", // ltspass_baker.shader
("544c75f56e9af8048b29a6ace5f52091", "Hidden/lilToonFurCutout"), // lts_fur_cutout.shader
("7ec9f85eb7ee04943adfe19c2ba5901f", "_lil/[Optional] lilToonFurOnlyCutout"), // lts_furonly_cutout.shader
("00795bf598b44dc4e9bd363348e77085", "_lil/[Optional] lilToonFakeShadow"), // lts_fakeshadow.shader
("3eef4aee6ba0de047b0d40409ea2891c", "Hidden/lilToonTessellation"), // lts_tess.shader
("61b4f98a5d78b4a4a9d89180fac793fc", "Hidden/ltspass_opaque"), // ltspass_opaque.shader
("df12117ecd77c31469c224178886498e", "lilToon"), // lts.shader
("dce3f3e248acc7b4daeda00daf616b4d", "Hidden/lilToonRefraction"), // lts_ref.shader
("14006db8206fb304aa86110d57626d40", "Hidden/ltspass_tess_cutout"), // ltspass_tess_cutout.shader
("bdf24b2e925ce8a4fb0e903889a52e0e", "Hidden/ltspass_tess_transparent"), // ltspass_tess_transparent.shader
("fba17785d6b2c594ab6c0303c834da65", "_lil/[Optional] lilToonOutlineOnly"), // lts_oo.shader
("62df797f407281640a224388953448cc", "Hidden/lilToonLiteTwoPassTransparentOutline"), // ltsl_twotrans_o.shader
("afa1a194f5a2fd243bda3a17bca1b36e", "Hidden/lilToonTessellationTransparent"), // lts_tess_trans.shader
("b269573b9937b8340b3e9e191a3ba5a8", "Hidden/lilToonOnePassTransparent"), // lts_onetrans.shader
("165365ab7100a044ca85fc8c33548a62", "Hidden/lilToonTransparent"), // lts_trans.shader
("9294844b15dca184d914a632279b24e1", "_lil/lilToonMulti"), // ltsmulti.shader
("59b5e58e88aae8a4ca42d1a7253e2fb2", "Hidden/ltspass_lite_opaque"), // ltspass_lite_opaque.shader
("583a88005abb81a4ebbce757b4851a0d", "Hidden/lilToonLiteOutline"), // ltsl_o.shader
("82226adb1a0b8c4418f574cfdcf523da", "Hidden/lilToonLiteTwoPassTransparent"), // ltsl_twotrans.shader
("7171688840c632447b22ec14e2bdef7e", "Hidden/lilToonOnePassTransparentOutline"), // lts_onetrans_o.shader
("c6d605ee23b18fc46903f38c67db701f", "Hidden/lilToonTessellationOutline"), // lts_tess_o.shader
("33aad051c4a3a844a8f9330addb86a97", "_lil/[Optional] lilToonFurOnlyTransparent"), // lts_furonly.shader
("0e3ece1bd59542743bccadb21f68318e", "Hidden/lilToonLiteTransparent"), // ltsl_trans.shader
("381af8ba8e1740a41b9768ccfb0416c2", "Hidden/lilToonLite"), // ltsl.shader
("d7af54cdd86902d41b8c240e06b93009", "Hidden/lilToonMultiRefraction"), // ltsmulti_ref.shader
("8cf5267d397b04846856f6d3d9561da0", "Hidden/lilToonLiteCutoutOutline"), // ltsl_cutout_o.shader
("90f83c35b0769a748abba5d0880f36d5", "Hidden/lilToonTessellationOnePassTransparent"), // lts_tess_onetrans.shader
("3c79b10c7e0b2784aaa4c2f8dd17d55e", "Hidden/lilToonTransparentOutline"), // lts_trans_o.shader
("85d6126cae43b6847aff4b13f4adb8ec", "Hidden/lilToonCutout"), // lts_cutout.shader
("3b3957e6c393b114bab6f835b4ed8f5d", "_lil/[Optional] lilToonOutlineOnlyCutout"), // lts_cutout_oo.shader
("d28e4b78ba8368e49a44f86c0291df58", "_lil/[Optional] lilToonLiteOverlay"), // ltsl_overlay.shader
("2683fad669f20ec49b8e9656954a33a8", "Hidden/ltspass_transparent"), // ltspass_transparent.shader
("7e61dbad981ad4f43a03722155db1c6a", "Hidden/lilToonTessellationTwoPassTransparentOutline"), // lts_tess_twotrans_o.shader
("67ed0252d63362a4ab23707a720508b7", "Hidden/lilToonTessellationOnePassTransparentOutline"), // lts_tess_onetrans_o.shader
("7e398ea50f9b70045b1774e05b46a39f", "Hidden/lilToonTessellationTwoPassTransparent"), // lts_tess_twotrans.shader
("7a7ac427f85673a45a3e4190fc10bc28", "Hidden/ltspass_tess_opaque"), // ltspass_tess_opaque.shader
("9b0c2630b12933248922527d4507cfa9", "Hidden/lilToonTessellationTransparentOutline"), // lts_tess_trans_o.shader
("33e950d038b8dfd4f824f3985c2abfb7", "_lil/[Optional] lilToonOverlayOnePass"), // lts_overlay_one.shader
("efa77a80ca0344749b4f19fdd5891cbe", "Hidden/lilToonOutline"), // lts_o.shader
("8a6ef0489c3ffbf46812460af3d52bb0", "Hidden/ltspass_lite_cutout"), // ltspass_lite_cutout.shader
("f8d9dfac6dbfaaf4c9c3aaf4bd8c955f", "_lil/[Optional] lilToonFurOnlyTwoPass"), // lts_furonly_two.shader
("3fb94a39b2685ee4d9817dcaf6542d99", "Hidden/lilToonRefractionBlur"), // lts_ref_blur.shader
("69f861c14129e724096c0955f8079012", "Hidden/lilToonMultiGem"), // ltsmulti_gem.shader
("3b4aa19949601f046a20ca8bdaee929f", "Hidden/lilToonCutoutOutline"), // lts_cutout_o.shader
("0c762f24b85918a49812fc5690619178", "_lil/[Optional] lilToonOutlineOnlyTransparent"), // lts_trans_oo.shader
("ad219df2a46e841488aee6a013e84e36", "Hidden/ltspass_cutout"), // ltspass_cutout.shader
("55706696b2bdb5d4d8541b89e17085c8", "Hidden/lilToonFur"), // lts_fur.shader
("94274b8ef5d3af842b9427384cba3a8f", "_lil/[Optional] lilToonOverlay"), // lts_overlay.shader
("fd68f52288a6b0243bf6c217bf0930ea", "Hidden/ltspass_proponly"), // ltspass_proponly.shader
("9cf054060007d784394b8b0bb703e441", "Hidden/lilToonTwoPassTransparentOutline"), // lts_twotrans_o.shader
("6a77405f7dfdc1447af58854c7f43f39", "Hidden/lilToonTwoPassTransparent"), // lts_twotrans.shader
("bbfffd5515b843c41a85067191cbf687", "Hidden/lilToonTessellationCutout"), // lts_tess_cutout.shader
("dc9ded9f9d6f16c4e92cbb8f4269ae31", "_lil/[Optional] lilToonLiteOverlayOnePass"), // ltsl_overlay_one.shader
("2bde4bd29a2a70a4d9cf98772a6717ac", "Hidden/ltspass_dummy"), // ltspass_dummy.shader
("34c2907eba944ed45a43970e0c11bcfd", "Hidden/lilToonLiteOnePassTransparent"), // ltsl_onetrans.shader
("a8d94439709469942bc7dcc9156ba110", "Hidden/lilToonGem"), // lts_gem.shader
("701268c07d37f5441b25b2cb99fae4b3", "Hidden/lilToonLiteOnePassTransparentOutline"), // ltsl_onetrans_o.shader
("51b2dee0ab07bd84d8147601ff89e511", "Hidden/lilToonMultiOutline"), // ltsmulti_o.shader
("1c12a37046f07ac4486881deaf0187ea", "Hidden/lilToonLiteTransparentOutline"), // ltsl_trans_o.shader
("b957dce3d03ff5445ac989f8de643c7f", "Hidden/lilToonLiteCutout"), // ltsl_cutout.shader
("5ba517885727277409feada18effa4a6", "Hidden/lilToonTessellationCutoutOutline"), // lts_tess_cutout_o.shader
("8773c83ab40fff24b800f74360819a6c", "Hidden/ltspass_lite_transparent"), // ltspass_lite_transparent.shader
("54bc8b41278802d4a81b27fe402994e2", "Hidden/lilToonFurTwoPass"), // lts_fur_two.shader
("1e50f1bc4d1b0e34cbf16b82589f6407", "Hidden/lilToonMultiFur"), // ltsmulti_fur.shader
("f96a89829ccb1e54b85214550519a8d6", "Hidden/ltsother_baker"), // ltspass_baker.shader
};

public override void GetMaterialInformation(MaterialInformationCallback matInfo)
{
// TODO: version check

var uvMain = UsingUVChannels.UV0;
var uvMainScaleOffset = "_MainTex_ST";
Matrix2x3? uvMainMatrix = ComputeUVMainMatrix();
Expand Down Expand Up @@ -519,7 +523,7 @@ public override void GetMaterialInformation(MaterialInformationCallback matInfo)
);
}

if (matInfo.GetInt("_UseOutline") != 0)
if (isOutline) // _UseOutline is not used, use shader name to determine
{
// not on material side, on editor side toggle
LIL_SAMPLE_2D_WithMat("_OutlineTex", "_OutlineTex", uvMain, uvMainMatrix);
Expand Down

0 comments on commit cc85d9a

Please sign in to comment.