0
\$\begingroup\$

So I'm making a 1-bit color game, and would like to have an option in the menu to change what those two colors are so the player can adjust it to their liking. What is the simplest and/or best method to go about this? This would apply to the entire screen, not individual sprites/meshes, as I want to preserve the 1-bit color look.

Most of my assets are sprites, with a few flat meshes that are rendered without anti-aliasing so that they blend in with the sprites. They're all exported with the two standard colors I'm using (a yellow-ish off-white and a dark grey-ish-blue), but I can go back and re-export them in black and white if that is necessary for the suggested method.

My eventual plan is to support the basic black and white, a few monochrome monitor color schemes, and some color combinations that you'd see on 8-bit computers (C64, Apple, etc.).

\$\endgroup\$
2
\$\begingroup\$

There are many ways to achieve this.

  • Have a list of all materials, all materials have the same 2-color mapping shader + alpha test, update all materials with the same two colors whenever they change.

  • Draw everything in black-and-white into a render texture then draw the entire texture on screen while mapping black to one color and white to the other color using a 2-color mapping shader & material. You only need to change that single material.

  • Use SpriteRenderer.color to recolor a white-or-transparent sprites using the vertex color. The camera's clear color is the other color. This only allows you to create 1-color sprites.

\$\endgroup\$
  • \$\begingroup\$ Thanks for replying. I'm pretty much a beginner at shaders; is a 2 color mapping shader similar (or the same) as a color ramp fragment shader? I did one of those before, but wasn't sure if that would really apply here. The third probably won't work, as some of my sprites need to have both colors in order to have a border effect around. \$\endgroup\$ – ExplosiveBarrels Oct 28 '17 at 3:56
  • \$\begingroup\$ The second bullet point is done best with a post processing effect script on your Camera. \$\endgroup\$ – Philipp Oct 28 '17 at 8:55
  • \$\begingroup\$ So this is how far I've gotten. I've added the following script to my camera: using System.Collections; using System.Collections.Generic; using UnityEngine; public class ColorChange : MonoBehaviour { public Material thisMaterial; private Camera thisCamera; private void OnRenderImage(RenderTexture source, RenderTexture destination) { Graphics.Blit(source, destination, thisMaterial); } } And then made a simple material with a shader on it. No errors, but no change. The shader uses an IF to compare the color and swap. \$\endgroup\$ – ExplosiveBarrels Oct 28 '17 at 21:16
  • \$\begingroup\$ So now the script is... sort of working? UI is unaffected, and not sure why. The rest of the screen just renders out black, so likely my shader is wrong, which is quite possible as I have very little clue what I'm doing. I've asked a question on the Shader Forge forums on how to do this, still awaiting an answer. \$\endgroup\$ – ExplosiveBarrels Oct 28 '17 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.