Pages 1
Universal Fighting Engine Forum We are no longer using the forum to answer questions due to bot attacks. Please use our discord instead: https://discord.gg/hGMZhF7 |
You are not logged in. Please login or register.
Universal Fighting Engine Forum → 2D Gameplay → color palettes?????
There's multiple ways you can possibly do 2D color palettes, and discussing it with MMind we didn't want to pigeon-hole the users into a specific method. Additionally, there's some Third Party assets on the Unity Store that could work but are paid so we didn't want to include them in the project as well.
I was working on a color palette tutorial at one point but it got sidelined. So here is the jist of how I've done it.
First of all, I hooked it up with using this Color Palette shader add-on. At the time of this post it's $5 on the store.
Setting up that shader to work best with UFE you have to make sure the character you're using it for has all their sprites in a sprite sheet with somewhere on the sprite sheet a 1 pixel tall row of all the colors on the sprite sheet to use as a palette. The reason it should be done this way is because I found that using individual sprite files causes performance issues in Unity as it's trying to constantly load the sprite files into memory during animations. Something I realized after I did the 2D Fighter tutorial video.
From there, with custom component code I added to the character prefab, and adding two static int properties created in my overarching game system for storing which palette was selected on the Character Select prefab: p1PaletteSelected and p2PaletteSelected. Utitlizing the event system with the custom code and the shader set up, the palette swaps worked perfectly and could even be swapped on the fly if so choosing due to the above mentioned shader asset and using a spritesheet.
With that shader (and a Ghosting Add-on for $5 with some minor code modification on it) you'll also be able to do things such as Ex Flash flickering and super shadows like in 3S for example.
I'll probably be writing up a more detailed explanation sometime soon. It definitely is on my todo list.
There's multiple ways you can possibly do 2D color palettes, and discussing it with MMind we didn't want to pigeon-hole the users into a specific method. Additionally, there's some Third Party assets on the Unity Store that could work but are paid so we didn't want to include them in the project as well.
I was working on a color palette tutorial at one point but it got sidelined. So here is the jist of how I've done it.
First of all, I hooked it up with using this Color Palette shader add-on. At the time of this post it's $5 on the store.
Setting up that shader to work best with UFE you have to make sure the character you're using it for has all their sprites in a sprite sheet with somewhere on the sprite sheet a 1 pixel tall row of all the colors on the sprite sheet to use as a palette. The reason it should be done this way is because I found that using individual sprite files causes performance issues in Unity as it's trying to constantly load the sprite files into memory during animations. Something I realized after I did the 2D Fighter tutorial video.
From there, with custom component code I added to the character prefab, and adding two static int properties created in my overarching game system for storing which palette was selected on the Character Select prefab: p1PaletteSelected and p2PaletteSelected. Utitlizing the event system with the custom code and the shader set up, the palette swaps worked perfectly and could even be swapped on the fly if so choosing due to the above mentioned shader asset and using a spritesheet.
With that shader (and a Ghosting Add-on for $5 with some minor code modification on it) you'll also be able to do things such as Ex Flash flickering and super shadows like in 3S for example.
I'll probably be writing up a more detailed explanation sometime soon. It definitely is on my todo list.
Thank you, fuck yea. cant wait
There's multiple ways you can possibly do 2D color palettes, and discussing it with MMind we didn't want to pigeon-hole the users into a specific method. Additionally, there's some Third Party assets on the Unity Store that could work but are paid so we didn't want to include them in the project as well.
I was working on a color palette tutorial at one point but it got sidelined. So here is the jist of how I've done it.
First of all, I hooked it up with using this Color Palette shader add-on. At the time of this post it's $5 on the store.
Setting up that shader to work best with UFE you have to make sure the character you're using it for has all their sprites in a sprite sheet with somewhere on the sprite sheet a 1 pixel tall row of all the colors on the sprite sheet to use as a palette. The reason it should be done this way is because I found that using individual sprite files causes performance issues in Unity as it's trying to constantly load the sprite files into memory during animations. Something I realized after I did the 2D Fighter tutorial video.
From there, with custom component code I added to the character prefab, and adding two static int properties created in my overarching game system for storing which palette was selected on the Character Select prefab: p1PaletteSelected and p2PaletteSelected. Utitlizing the event system with the custom code and the shader set up, the palette swaps worked perfectly and could even be swapped on the fly if so choosing due to the above mentioned shader asset and using a spritesheet.
With that shader (and a Ghosting Add-on for $5 with some minor code modification on it) you'll also be able to do things such as Ex Flash flickering and super shadows like in 3S for example.
I'll probably be writing up a more detailed explanation sometime soon. It definitely is on my todo list.
Having hard time with this, I'm I allowed to use all 256 bit colors for pallet swap, to keep all the colors?
The shader I used didn't seem to have any color limitations on it. What are you having a hard time with?
In order to keep all the colors in sprite sheet, the swatches came out to be 256 colors, when I made a Photoshop I 'm thinking that might be to many swatches. to put in the right hand corner. I'm not understanding the idea of placing palettes in the corner of sprite sheet, and the plugin only focuses on the palettes instead of all the other actual sprites. Does it require the at least one sprite sheet, instead of me simply taking the sprite sheet to photoshop, creating a swatch table, taking a snapshot of colors in boxes, pasting it in layer, exporting as png, and using that instead? My sprites are 4k, so it seems to be alot of information to load
I was looking at this though, although it's a bit expensive. Have you tried this asset. https://assetstore.unity.com/packages/t … ette-32189
Seems like you can import .ase from photoshop as well. Have you tested this plugin? Thanks for reply.
Hey Storm,
From what I remember when I worked on it, I was having issues with using the add-on's "Just tell me what colors to look out for" method, and just found it easiest to do the single row of all the colors in each column. Sadly it didn't seem to support multi-row palettes as it would have made it easier I'm sure. In the above example from Third Strike, Makoto has 79 unique colors so my color palette file was 79x1 in size. Where the entire sprite sheet was 4096x3562 in size.
In that case I used a separate 79x1 png file to control the palette coloring for the suggested plugin instead of using the sprite 4096 spritesheet itself.
Also, no, I haven't looked at the asset you linked, but I expect you might be able to use it just as well. I was just sharing how I got mine to work without having to modify the UFE code at all.
Here you can see the custom scripts I added to the Makoto prefab. With these I was able to code using the event system advanced code methods listed in the Wiki to determine if specific palettes should be switched up for each player, including code that uses the ghost trail add-on to create the EX move and Super effect Third Strike offers.
And here's all the code for my AlternatePalettes.cs script which you can see in action here:
using ActionCode2D.Renderers;
using System;
using System.Collections.Generic;
using System.Linq;
using UFE3D;
using UnityEngine;
public class AlternatePalettes : MonoBehaviour
{
public List<Texture2D> palettes = new List<Texture2D>();
public List<SpriteRenderer> exGhosts;
public List<SpriteRenderer> ghosts;
public List<MoveInfo> exMoves;
public List<MoveInfo> superMoves;
public int currentPalette;
public int startPalette;
public int superPalette;
public Texture2D exPalette;
public Texture2D grayscalePalette;
private ControlsScript cScript;
private SpriteRenderer spriteRenderer;
private SpriteGhostTrailRenderer ghostRenderer;
private Color exColor = new Color(1f, 0.868932f, 0);
private Color superColor = new Color(0.45f, 0.53f, 1);
void Start() {
cScript = gameObject.GetComponentInParent<ControlsScript>();
spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
ghostRenderer = gameObject.GetComponent<SpriteGhostTrailRenderer>();
ghostRenderer.GetContainer().name = $"Player {cScript.playerNum} Ghosts";
ghosts = ghostRenderer.GetRenderers().ToList();
foreach(SpriteRenderer ghost in ghosts) {
ghost.enabled = false;
Renderer[] charRenders = ghost.GetComponents<Renderer>();
foreach (Renderer charRender in charRenders) {
charRender.material.SetTexture("_PaletteTex", palettes[0]);
charRender.material.SetTexture("_SwapTex", grayscalePalette);
}
}
//TODO: Add code to set palette of ghosts to an all white ghost for better coloring.
currentPalette = startPalette;
SetPalette(palettes[currentPalette]);
if (palettes.Count > 1) {
if (cScript.playerNum == 2 && UFE.p1ControlsScript.character.name == UFE.GetPlayer2ControlsScript().character.name) {
AlternatePalettes p1Palette = UFE.p1ControlsScript.gameObject.GetComponentsInChildren<AlternatePalettes>()[0];
if (p1Palette.currentPalette == currentPalette) {
currentPalette = p1Palette.currentPalette + 1;
if (currentPalette == palettes.Count) {
currentPalette = 0;
}
startPalette = currentPalette;
SetPalette(palettes[currentPalette]);
}
}
}
}
private void Update() {
if (UFE.p1ControlsScript != null && UFE.p2ControlsScript != null && cScript.currentMove != null) {
CheckIfMoveIsEx();
CheckIfMoveIsSuper();
} else if (startPalette != currentPalette) {
currentPalette = startPalette;
SetPalette(palettes[currentPalette]);
} else {
HideAllGhosts();
}
}
public void HideAllGhosts() {
foreach (SpriteRenderer ghost in ghosts) {
ghost.enabled = false;
ghost.sortingOrder = -1;
}
}
public void CheckIfMoveIsEx() {
foreach (MoveInfo move in exMoves) {
if (cScript.currentMove.moveName == move.moveName) {
EnableExGhosting(ghostRenderer.GetIndex());
break;
}
}
}
public void CheckIfMoveIsSuper() {
foreach (MoveInfo move in superMoves) {
if (cScript.currentMove.moveName == move.moveName) {
EnableSuperGhosting();
break;
}
}
}
public void EnableSuperGhosting() {
for(int i = 0; i < ghosts.Count; i++) {
ghosts[i].color = superColor;
ghosts[(ghostRenderer.GetIndex() + i) % ghosts.Count].sortingOrder = spriteRenderer.sortingOrder - (i + 1);
if (cScript.currentMove.currentFrame >= ghosts.Count) {
ghosts[i].enabled = true;
} else if (cScript.currentMove.currentFrame >= 0) {
ghosts[ghostRenderer.GetIndex() % ghosts.Count].enabled = true;
}
}
// TODO: There's some sort of super palette.. have to figure out and create that one too.
}
public void EnableExGhosting(int index) {
HideAllGhosts();
// Render 3rd and 6th oldest ghosts on the same frame every 6th frame of the move
int third = (index + 5) % ghostRenderer.ghosts;
int sixth = (index + 9) % ghostRenderer.ghosts;
ghosts[third].color = exColor;
ghosts[sixth].color = ghosts[third].color;
ghosts[third].enabled = cScript.currentMove.currentFrame % 2 == 0;
ghosts[sixth].enabled = ghosts[third].enabled;
ghosts[third].sortingOrder = spriteRenderer.sortingOrder - 1;
ghosts[sixth].sortingOrder = ghosts[third].sortingOrder - 1;
// Change to pale palette every 3rd frame after the 6th frame.
if (UFE.p1ControlsScript.currentMove.currentFrame > 3 && (UFE.p1ControlsScript.currentMove.currentFrame + 2) % 3 == 0) {
currentPalette = -1;
SetPalette(exPalette);
} else if (startPalette != currentPalette) {
currentPalette = startPalette;
SetPalette(palettes[currentPalette]);
}
}
public void SetPalette(Texture2D texture) {
Renderer[] charRenders = gameObject.GetComponents<Renderer>();
foreach (Renderer charRender in charRenders) {
charRender.material.SetTexture("_SwapTex", texture);
}
}
}
Thanks dude, that is interesting indeed. Looking at the code, I'm guess the palette swap is working in combination to the 3rd party plugin you posted earlier? I hate the fact that my characters require 256 colors to keep all there details, else that 5 dollar plugin would be a piece of cake. lol
I found this plugin https://github.com/jknightdoeswork/swatchr, but I get this error.
"The type or namespace name 'DynamicMethod' could not be found" when imported. If I find out something else, I'll post something up. Might have to wait for sale for that 30 plugin. thats to much right now, lol
If you dont mind how did you generate your pallet from image?
I had the full sprite sheet and i took each color and made a pixel list.
Specifically. I'd take the sprite sheet, put a new layer up, set Magic Wand tool to work on all layers and have 0 threshold, so it only selects colors of that same exact color. Then I'd color pick that color and mark it down in the corner of the sprite sheet. On the new layer I'd Paint Bucket Fill non-contiguously in the selected areas a solid predefined "green screen" color like rgb(255,0,255) or rgb(0,255,0) whichever worked best for the artwork as contrast. THen move on until I had selected every color variant pixel. By the time the whole sprite sheet looked silhouetted i'd have the full row of pixel variants.
When you say "require 256 colors" you mean if you were to make a palette sheet it'd be 256x1 image, and that all 256 variant colors are being used through the entire sheet?
256 variant colors are being used, but i found another solution. It's a plugin allinoneshader https://assetstore.unity.com/packages/v … 1607638387 has a feature to swap 1 color with another color using the color picker. Only downside to it you can only change 1 color. Something similar would be a good feature for ufe to have.
Yeah, I just guess I'm not understanding fully why you wouldn't be able to swap colors out regardless of the max number of colors you have.
quick question of you dont mind I got 7 errors after copying and pasting that pallet code above.
please help.
quick question of you dont mind I got 7 errors after copying and pasting that pallet code above.
please help.
ah, modify the SpriteGhostTrailRenderer.cs, I believe that would be your issue. I did have to modify his code a little where i added these three methods.
#region Custom Methods
public SpriteRenderer[] GetRenderers() {
return _ghostRenderers;
}
public Transform GetContainer() {
return _ghostContainer;
}
public int GetIndex() {
return _ghostIndex;
}
#endregion
For Ghosts, I believe I just made what was an existing private int variable public, but this was the end result:
[Range(1,10)] public int ghosts = 4;
If that doesn't work, then PM me what his default SpriteGhostTrailRenderer.cs file is and I can tell you what needs to be changed.
Thanks, will let you know what happen. Good looking out
Universal Fighting Engine Forum → 2D Gameplay → color palettes?????
Powered by PunBB, supported by Informer Technologies, Inc.