yum/3ner
A toon shader for Unity's BIRP.
git clone https://git.yummers.dev/yum/3ner
ffbf55b
master
1// Fixed fields are intentional: Unity 2022.3 cannot animate custom nested classes or arrays. 2// Keep slot names stable; saved AnimationClips bind directly to these fields. 3using UnityEngine ; 4 5namespace Yum . Fold 6{ 7[ ExecuteAlways , DisallowMultipleComponent ] 8[ AddComponentMenu ( "" )] 9public sealed class FoldMaterialAnimator : MonoBehaviour 10{ 11[ HideInInspector ] public FoldStack owner ; 12[ HideInInspector ] public Renderer targetRenderer ; 13[ HideInInspector ] public Material material ; 14[ HideInInspector ] public int materialIndex ; 15public bool slot0_enabled ; 16[ UnityEngine . Animations . DiscreteEvaluation ] public int slot0_opcode ; 17public float slot0_float0 ; 18public float slot0_float1 ; 19public float slot0_float2 ; 20public float slot0_float3 ; 21public Vector4 slot0_vector0 ; 22public Vector4 slot0_vector1 ; 23public Vector4 slot0_vector2 ; 24public Vector4 slot0_vector3 ; 25public bool slot1_enabled ; 26[ UnityEngine . Animations . DiscreteEvaluation ] public int slot1_opcode ; 27public float slot1_float0 ; 28public float slot1_float1 ; 29public float slot1_float2 ; 30public float slot1_float3 ; 31public Vector4 slot1_vector0 ; 32public Vector4 slot1_vector1 ; 33public Vector4 slot1_vector2 ; 34public Vector4 slot1_vector3 ; 35public bool slot2_enabled ; 36[ UnityEngine . Animations . DiscreteEvaluation ] public int slot2_opcode ; 37public float slot2_float0 ; 38public float slot2_float1 ; 39public float slot2_float2 ; 40public float slot2_float3 ; 41public Vector4 slot2_vector0 ; 42public Vector4 slot2_vector1 ; 43public Vector4 slot2_vector2 ; 44public Vector4 slot2_vector3 ; 45public bool slot3_enabled ; 46[ UnityEngine . Animations . DiscreteEvaluation ] public int slot3_opcode ; 47public float slot3_float0 ; 48public float slot3_float1 ; 49public float slot3_float2 ; 50public float slot3_float3 ; 51public Vector4 slot3_vector0 ; 52public Vector4 slot3_vector1 ; 53public Vector4 slot3_vector2 ; 54public Vector4 slot3_vector3 ; 55public bool slot4_enabled ; 56[ UnityEngine . Animations . DiscreteEvaluation ] public int slot4_opcode ; 57public float slot4_float0 ; 58public float slot4_float1 ; 59public float slot4_float2 ; 60public float slot4_float3 ; 61public Vector4 slot4_vector0 ; 62public Vector4 slot4_vector1 ; 63public Vector4 slot4_vector2 ; 64public Vector4 slot4_vector3 ; 65public bool slot5_enabled ; 66[ UnityEngine . Animations . DiscreteEvaluation ] public int slot5_opcode ; 67public float slot5_float0 ; 68public float slot5_float1 ; 69public float slot5_float2 ; 70public float slot5_float3 ; 71public Vector4 slot5_vector0 ; 72public Vector4 slot5_vector1 ; 73public Vector4 slot5_vector2 ; 74public Vector4 slot5_vector3 ; 75public bool slot6_enabled ; 76[ UnityEngine . Animations . DiscreteEvaluation ] public int slot6_opcode ; 77public float slot6_float0 ; 78public float slot6_float1 ; 79public float slot6_float2 ; 80public float slot6_float3 ; 81public Vector4 slot6_vector0 ; 82public Vector4 slot6_vector1 ; 83public Vector4 slot6_vector2 ; 84public Vector4 slot6_vector3 ; 85public bool slot7_enabled ; 86[ UnityEngine . Animations . DiscreteEvaluation ] public int slot7_opcode ; 87public float slot7_float0 ; 88public float slot7_float1 ; 89public float slot7_float2 ; 90public float slot7_float3 ; 91public Vector4 slot7_vector0 ; 92public Vector4 slot7_vector1 ; 93public Vector4 slot7_vector2 ; 94public Vector4 slot7_vector3 ; 95public bool slot8_enabled ; 96[ UnityEngine . Animations . DiscreteEvaluation ] public int slot8_opcode ; 97public float slot8_float0 ; 98public float slot8_float1 ; 99public float slot8_float2 ; 100public float slot8_float3 ; 101public Vector4 slot8_vector0 ; 102public Vector4 slot8_vector1 ; 103public Vector4 slot8_vector2 ; 104public Vector4 slot8_vector3 ; 105public bool slot9_enabled ; 106[ UnityEngine . Animations . DiscreteEvaluation ] public int slot9_opcode ; 107public float slot9_float0 ; 108public float slot9_float1 ; 109public float slot9_float2 ; 110public float slot9_float3 ; 111public Vector4 slot9_vector0 ; 112public Vector4 slot9_vector1 ; 113public Vector4 slot9_vector2 ; 114public Vector4 slot9_vector3 ; 115public bool slot10_enabled ; 116[ UnityEngine . Animations . DiscreteEvaluation ] public int slot10_opcode ; 117public float slot10_float0 ; 118public float slot10_float1 ; 119public float slot10_float2 ; 120public float slot10_float3 ; 121public Vector4 slot10_vector0 ; 122public Vector4 slot10_vector1 ; 123public Vector4 slot10_vector2 ; 124public Vector4 slot10_vector3 ; 125public bool slot11_enabled ; 126[ UnityEngine . Animations . DiscreteEvaluation ] public int slot11_opcode ; 127public float slot11_float0 ; 128public float slot11_float1 ; 129public float slot11_float2 ; 130public float slot11_float3 ; 131public Vector4 slot11_vector0 ; 132public Vector4 slot11_vector1 ; 133public Vector4 slot11_vector2 ; 134public Vector4 slot11_vector3 ; 135public bool slot12_enabled ; 136[ UnityEngine . Animations . DiscreteEvaluation ] public int slot12_opcode ; 137public float slot12_float0 ; 138public float slot12_float1 ; 139public float slot12_float2 ; 140public float slot12_float3 ; 141public Vector4 slot12_vector0 ; 142public Vector4 slot12_vector1 ; 143public Vector4 slot12_vector2 ; 144public Vector4 slot12_vector3 ; 145public bool slot13_enabled ; 146[ UnityEngine . Animations . DiscreteEvaluation ] public int slot13_opcode ; 147public float slot13_float0 ; 148public float slot13_float1 ; 149public float slot13_float2 ; 150public float slot13_float3 ; 151public Vector4 slot13_vector0 ; 152public Vector4 slot13_vector1 ; 153public Vector4 slot13_vector2 ; 154public Vector4 slot13_vector3 ; 155public bool slot14_enabled ; 156[ UnityEngine . Animations . DiscreteEvaluation ] public int slot14_opcode ; 157public float slot14_float0 ; 158public float slot14_float1 ; 159public float slot14_float2 ; 160public float slot14_float3 ; 161public Vector4 slot14_vector0 ; 162public Vector4 slot14_vector1 ; 163public Vector4 slot14_vector2 ; 164public Vector4 slot14_vector3 ; 165public bool slot15_enabled ; 166[ UnityEngine . Animations . DiscreteEvaluation ] public int slot15_opcode ; 167public float slot15_float0 ; 168public float slot15_float1 ; 169public float slot15_float2 ; 170public float slot15_float3 ; 171public Vector4 slot15_vector0 ; 172public Vector4 slot15_vector1 ; 173public Vector4 slot15_vector2 ; 174public Vector4 slot15_vector3 ; 175 176public SlotAccess slots => new SlotAccess ( this ); 177public readonly struct SlotAccess 178{ 179readonly FoldMaterialAnimator driver ; 180public SlotAccess ( FoldMaterialAnimator driver ) { this . driver = driver ; } 181public int Length => 16 ; 182public FoldOperator this [ int index ] { get => driver . Read ( index , new FoldOperator ()); set => driver . Write ( index , value ); } 183} 184public FoldOperator Read ( int index , FoldOperator result ) 185{ 186switch ( index ) 187{ 188case 0 : 189result . enabled = slot0_enabled ; 190result . opcode = slot0_opcode ; 191result . float0 = slot0_float0 ; 192result . float1 = slot0_float1 ; 193result . float2 = slot0_float2 ; 194result . float3 = slot0_float3 ; 195result . vector0 = slot0_vector0 ; 196result . vector1 = slot0_vector1 ; 197result . vector2 = slot0_vector2 ; 198result . vector3 = slot0_vector3 ; 199break ; 200case 1 : 201result . enabled = slot1_enabled ; 202result . opcode = slot1_opcode ; 203result . float0 = slot1_float0 ; 204result . float1 = slot1_float1 ; 205result . float2 = slot1_float2 ; 206result . float3 = slot1_float3 ; 207result . vector0 = slot1_vector0 ; 208result . vector1 = slot1_vector1 ; 209result . vector2 = slot1_vector2 ; 210result . vector3 = slot1_vector3 ; 211break ; 212case 2 : 213result . enabled = slot2_enabled ; 214result . opcode = slot2_opcode ; 215result . float0 = slot2_float0 ; 216result . float1 = slot2_float1 ; 217result . float2 = slot2_float2 ; 218result . float3 = slot2_float3 ; 219result . vector0 = slot2_vector0 ; 220result . vector1 = slot2_vector1 ; 221result . vector2 = slot2_vector2 ; 222result . vector3 = slot2_vector3 ; 223break ; 224case 3 : 225result . enabled = slot3_enabled ; 226result . opcode = slot3_opcode ; 227result . float0 = slot3_float0 ; 228result . float1 = slot3_float1 ; 229result . float2 = slot3_float2 ; 230result . float3 = slot3_float3 ; 231result . vector0 = slot3_vector0 ; 232result . vector1 = slot3_vector1 ; 233result . vector2 = slot3_vector2 ; 234result . vector3 = slot3_vector3 ; 235break ; 236case 4 : 237result . enabled = slot4_enabled ; 238result . opcode = slot4_opcode ; 239result . float0 = slot4_float0 ; 240result . float1 = slot4_float1 ; 241result . float2 = slot4_float2 ; 242result . float3 = slot4_float3 ; 243result . vector0 = slot4_vector0 ; 244result . vector1 = slot4_vector1 ; 245result . vector2 = slot4_vector2 ; 246result . vector3 = slot4_vector3 ; 247break ; 248case 5 : 249result . enabled = slot5_enabled ; 250result . opcode = slot5_opcode ; 251result . float0 = slot5_float0 ; 252result . float1 = slot5_float1 ; 253result . float2 = slot5_float2 ; 254result . float3 = slot5_float3 ; 255result . vector0 = slot5_vector0 ; 256result . vector1 = slot5_vector1 ; 257result . vector2 = slot5_vector2 ; 258result . vector3 = slot5_vector3 ; 259break ; 260case 6 : 261result . enabled = slot6_enabled ; 262result . opcode = slot6_opcode ; 263result . float0 = slot6_float0 ; 264result . float1 = slot6_float1 ; 265result . float2 = slot6_float2 ; 266result . float3 = slot6_float3 ; 267result . vector0 = slot6_vector0 ; 268result . vector1 = slot6_vector1 ; 269result . vector2 = slot6_vector2 ; 270result . vector3 = slot6_vector3 ; 271break ; 272case 7 : 273result . enabled = slot7_enabled ; 274result . opcode = slot7_opcode ; 275result . float0 = slot7_float0 ; 276result . float1 = slot7_float1 ; 277result . float2 = slot7_float2 ; 278result . float3 = slot7_float3 ; 279result . vector0 = slot7_vector0 ; 280result . vector1 = slot7_vector1 ; 281result . vector2 = slot7_vector2 ; 282result . vector3 = slot7_vector3 ; 283break ; 284case 8 : 285result . enabled = slot8_enabled ; 286result . opcode = slot8_opcode ; 287result . float0 = slot8_float0 ; 288result . float1 = slot8_float1 ; 289result . float2 = slot8_float2 ; 290result . float3 = slot8_float3 ; 291result . vector0 = slot8_vector0 ; 292result . vector1 = slot8_vector1 ; 293result . vector2 = slot8_vector2 ; 294result . vector3 = slot8_vector3 ; 295break ; 296case 9 : 297result . enabled = slot9_enabled ; 298result . opcode = slot9_opcode ; 299result . float0 = slot9_float0 ; 300result . float1 = slot9_float1 ; 301result . float2 = slot9_float2 ; 302result . float3 = slot9_float3 ; 303result . vector0 = slot9_vector0 ; 304result . vector1 = slot9_vector1 ; 305result . vector2 = slot9_vector2 ; 306result . vector3 = slot9_vector3 ; 307break ; 308case 10 : 309result . enabled = slot10_enabled ; 310result . opcode = slot10_opcode ; 311result . float0 = slot10_float0 ; 312result . float1 = slot10_float1 ; 313result . float2 = slot10_float2 ; 314result . float3 = slot10_float3 ; 315result . vector0 = slot10_vector0 ; 316result . vector1 = slot10_vector1 ; 317result . vector2 = slot10_vector2 ; 318result . vector3 = slot10_vector3 ; 319break ; 320case 11 : 321result . enabled = slot11_enabled ; 322result . opcode = slot11_opcode ; 323result . float0 = slot11_float0 ; 324result . float1 = slot11_float1 ; 325result . float2 = slot11_float2 ; 326result . float3 = slot11_float3 ; 327result . vector0 = slot11_vector0 ; 328result . vector1 = slot11_vector1 ; 329result . vector2 = slot11_vector2 ; 330result . vector3 = slot11_vector3 ; 331break ; 332case 12 : 333result . enabled = slot12_enabled ; 334result . opcode = slot12_opcode ; 335result . float0 = slot12_float0 ; 336result . float1 = slot12_float1 ; 337result . float2 = slot12_float2 ; 338result . float3 = slot12_float3 ; 339result . vector0 = slot12_vector0 ; 340result . vector1 = slot12_vector1 ; 341result . vector2 = slot12_vector2 ; 342result . vector3 = slot12_vector3 ; 343break ; 344case 13 : 345result . enabled = slot13_enabled ; 346result . opcode = slot13_opcode ; 347result . float0 = slot13_float0 ; 348result . float1 = slot13_float1 ; 349result . float2 = slot13_float2 ; 350result . float3 = slot13_float3 ; 351result . vector0 = slot13_vector0 ; 352result . vector1 = slot13_vector1 ; 353result . vector2 = slot13_vector2 ; 354result . vector3 = slot13_vector3 ; 355break ; 356case 14 : 357result . enabled = slot14_enabled ; 358result . opcode = slot14_opcode ; 359result . float0 = slot14_float0 ; 360result . float1 = slot14_float1 ; 361result . float2 = slot14_float2 ; 362result . float3 = slot14_float3 ; 363result . vector0 = slot14_vector0 ; 364result . vector1 = slot14_vector1 ; 365result . vector2 = slot14_vector2 ; 366result . vector3 = slot14_vector3 ; 367break ; 368case 15 : 369result . enabled = slot15_enabled ; 370result . opcode = slot15_opcode ; 371result . float0 = slot15_float0 ; 372result . float1 = slot15_float1 ; 373result . float2 = slot15_float2 ; 374result . float3 = slot15_float3 ; 375result . vector0 = slot15_vector0 ; 376result . vector1 = slot15_vector1 ; 377result . vector2 = slot15_vector2 ; 378result . vector3 = slot15_vector3 ; 379break ; 380default : throw new System . IndexOutOfRangeException (); 381} 382return result ; 383} 384public void Write ( int index , FoldOperator value ) 385{ 386switch ( index ) 387{ 388case 0 : 389slot0_enabled = value . enabled ; 390slot0_opcode = value . opcode ; 391slot0_float0 = value . float0 ; 392slot0_float1 = value . float1 ; 393slot0_float2 = value . float2 ; 394slot0_float3 = value . float3 ; 395slot0_vector0 = value . vector0 ; 396slot0_vector1 = value . vector1 ; 397slot0_vector2 = value . vector2 ; 398slot0_vector3 = value . vector3 ; 399break ; 400case 1 : 401slot1_enabled = value . enabled ; 402slot1_opcode = value . opcode ; 403slot1_float0 = value . float0 ; 404slot1_float1 = value . float1 ; 405slot1_float2 = value . float2 ; 406slot1_float3 = value . float3 ; 407slot1_vector0 = value . vector0 ; 408slot1_vector1 = value . vector1 ; 409slot1_vector2 = value . vector2 ; 410slot1_vector3 = value . vector3 ; 411break ; 412case 2 : 413slot2_enabled = value . enabled ; 414slot2_opcode = value . opcode ; 415slot2_float0 = value . float0 ; 416slot2_float1 = value . float1 ; 417slot2_float2 = value . float2 ; 418slot2_float3 = value . float3 ; 419slot2_vector0 = value . vector0 ; 420slot2_vector1 = value . vector1 ; 421slot2_vector2 = value . vector2 ; 422slot2_vector3 = value . vector3 ; 423break ; 424case 3 : 425slot3_enabled = value . enabled ; 426slot3_opcode = value . opcode ; 427slot3_float0 = value . float0 ; 428slot3_float1 = value . float1 ; 429slot3_float2 = value . float2 ; 430slot3_float3 = value . float3 ; 431slot3_vector0 = value . vector0 ; 432slot3_vector1 = value . vector1 ; 433slot3_vector2 = value . vector2 ; 434slot3_vector3 = value . vector3 ; 435break ; 436case 4 : 437slot4_enabled = value . enabled ; 438slot4_opcode = value . opcode ; 439slot4_float0 = value . float0 ; 440slot4_float1 = value . float1 ; 441slot4_float2 = value . float2 ; 442slot4_float3 = value . float3 ; 443slot4_vector0 = value . vector0 ; 444slot4_vector1 = value . vector1 ; 445slot4_vector2 = value . vector2 ; 446slot4_vector3 = value . vector3 ; 447break ; 448case 5 : 449slot5_enabled = value . enabled ; 450slot5_opcode = value . opcode ; 451slot5_float0 = value . float0 ; 452slot5_float1 = value . float1 ; 453slot5_float2 = value . float2 ; 454slot5_float3 = value . float3 ; 455slot5_vector0 = value . vector0 ; 456slot5_vector1 = value . vector1 ; 457slot5_vector2 = value . vector2 ; 458slot5_vector3 = value . vector3 ; 459break ; 460case 6 : 461slot6_enabled = value . enabled ; 462slot6_opcode = value . opcode ; 463slot6_float0 = value . float0 ; 464slot6_float1 = value . float1 ; 465slot6_float2 = value . float2 ; 466slot6_float3 = value . float3 ; 467slot6_vector0 = value . vector0 ; 468slot6_vector1 = value . vector1 ; 469slot6_vector2 = value . vector2 ; 470slot6_vector3 = value . vector3 ; 471break ; 472case 7 : 473slot7_enabled = value . enabled ; 474slot7_opcode = value . opcode ; 475slot7_float0 = value . float0 ; 476slot7_float1 = value . float1 ; 477slot7_float2 = value . float2 ; 478slot7_float3 = value . float3 ; 479slot7_vector0 = value . vector0 ; 480slot7_vector1 = value . vector1 ; 481slot7_vector2 = value . vector2 ; 482slot7_vector3 = value . vector3 ; 483break ; 484case 8 : 485slot8_enabled = value . enabled ; 486slot8_opcode = value . opcode ; 487slot8_float0 = value . float0 ; 488slot8_float1 = value . float1 ; 489slot8_float2 = value . float2 ; 490slot8_float3 = value . float3 ; 491slot8_vector0 = value . vector0 ; 492slot8_vector1 = value . vector1 ; 493slot8_vector2 = value . vector2 ; 494slot8_vector3 = value . vector3 ; 495break ; 496case 9 : 497slot9_enabled = value . enabled ; 498slot9_opcode = value . opcode ; 499slot9_float0 = value . float0 ; 500slot9_float1 = value . float1 ; 501slot9_float2 = value . float2 ; 502slot9_float3 = value . float3 ; 503slot9_vector0 = value . vector0 ; 504slot9_vector1 = value . vector1 ; 505slot9_vector2 = value . vector2 ; 506slot9_vector3 = value . vector3 ; 507break ; 508case 10 : 509slot10_enabled = value . enabled ; 510slot10_opcode = value . opcode ; 511slot10_float0 = value . float0 ; 512slot10_float1 = value . float1 ; 513slot10_float2 = value . float2 ; 514slot10_float3 = value . float3 ; 515slot10_vector0 = value . vector0 ; 516slot10_vector1 = value . vector1 ; 517slot10_vector2 = value . vector2 ; 518slot10_vector3 = value . vector3 ; 519break ; 520case 11 : 521slot11_enabled = value . enabled ; 522slot11_opcode = value . opcode ; 523slot11_float0 = value . float0 ; 524slot11_float1 = value . float1 ; 525slot11_float2 = value . float2 ; 526slot11_float3 = value . float3 ; 527slot11_vector0 = value . vector0 ; 528slot11_vector1 = value . vector1 ; 529slot11_vector2 = value . vector2 ; 530slot11_vector3 = value . vector3 ; 531break ; 532case 12 : 533slot12_enabled = value . enabled ; 534slot12_opcode = value . opcode ; 535slot12_float0 = value . float0 ; 536slot12_float1 = value . float1 ; 537slot12_float2 = value . float2 ; 538slot12_float3 = value . float3 ; 539slot12_vector0 = value . vector0 ; 540slot12_vector1 = value . vector1 ; 541slot12_vector2 = value . vector2 ; 542slot12_vector3 = value . vector3 ; 543break ; 544case 13 : 545slot13_enabled = value . enabled ; 546slot13_opcode = value . opcode ; 547slot13_float0 = value . float0 ; 548slot13_float1 = value . float1 ; 549slot13_float2 = value . float2 ; 550slot13_float3 = value . float3 ; 551slot13_vector0 = value . vector0 ; 552slot13_vector1 = value . vector1 ; 553slot13_vector2 = value . vector2 ; 554slot13_vector3 = value . vector3 ; 555break ; 556case 14 : 557slot14_enabled = value . enabled ; 558slot14_opcode = value . opcode ; 559slot14_float0 = value . float0 ; 560slot14_float1 = value . float1 ; 561slot14_float2 = value . float2 ; 562slot14_float3 = value . float3 ; 563slot14_vector0 = value . vector0 ; 564slot14_vector1 = value . vector1 ; 565slot14_vector2 = value . vector2 ; 566slot14_vector3 = value . vector3 ; 567break ; 568case 15 : 569slot15_enabled = value . enabled ; 570slot15_opcode = value . opcode ; 571slot15_float0 = value . float0 ; 572slot15_float1 = value . float1 ; 573slot15_float2 = value . float2 ; 574slot15_float3 = value . float3 ; 575slot15_vector0 = value . vector0 ; 576slot15_vector1 = value . vector1 ; 577slot15_vector2 = value . vector2 ; 578slot15_vector3 = value . vector3 ; 579break ; 580default : throw new System . IndexOutOfRangeException (); 581} 582} 583MaterialPropertyBlock original , block ; 584readonly FoldOperator scratch = new FoldOperator (); 585readonly System . Collections . Generic . List < Material > shared = new System . Collections . Generic . List < Material > (); 586void OnEnable () => Apply (); 587void LateUpdate () => Apply (); 588void OnDidApplyAnimationProperties () => Apply (); 589void OnDisable () => Restore (); 590void OnDestroy () => Restore (); 591public void Apply () 592{ 593if ( ! isActiveAndEnabled || ! owner || ! owner . isActiveAndEnabled || ! targetRenderer || ! material ) { Restore (); return ; } 594targetRenderer . GetSharedMaterials ( shared ); 595if ( materialIndex < 0 || materialIndex >= shared . Count || shared [ materialIndex ] != material ) { Restore (); return ; } 596if ( block == null ) block = new MaterialPropertyBlock (); 597if ( original == null ) 598{ 599original = new MaterialPropertyBlock (); 600targetRenderer . GetPropertyBlock ( original , materialIndex ); 601} 602targetRenderer . GetPropertyBlock ( block , materialIndex ); 603if ( block . isEmpty ) targetRenderer . GetPropertyBlock ( block ); 604for ( int i = 0 ; i < 16 ; i ++ ) Read ( i , scratch ). Write ( block , i ); 605targetRenderer . SetPropertyBlock ( block , materialIndex ); 606} 607public void Restore () 608{ 609if ( original == null ) return ; 610if ( targetRenderer ) 611{ 612targetRenderer . GetSharedMaterials ( shared ); 613if ( materialIndex >= 0 && materialIndex < shared . Count ) 614targetRenderer . SetPropertyBlock ( original . isEmpty ? null : original , materialIndex ); 615} 616original = null ; 617} 618} 619}