Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Hidden/PalettedImageShader"
- {
- Properties
- {
- _MainTex ("Texture", 2D) = "white" {}
- }
- SubShader
- {
- // No culling or depth
- Cull Off ZWrite Off ZTest Always
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma target 2.0
- #include "UnityCG.cginc"
- struct appdata
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- };
- struct v2f
- {
- float2 uv : TEXCOORD0;
- float4 vertex : SV_POSITION;
- };
- v2f vert (appdata v)
- {
- v2f o;
- o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
- o.uv = v.uv;
- return o;
- }
- float4 _ColorPalette[256];
- sampler2D _MainTex;
- fixed4 frag (v2f i) : SV_Target
- {
- fixed4 col = tex2D(_MainTex, i.uv);
- // the idea here was that _ColorPalette is treated as 16 different palettes, each with 16 colors
- // that's more reflective of the SNES than the NES/Famicom but ofc it's not hard to modify for other systems.
- // so then col.r stores a value from 0-15 (mapped to the 0-1 range) which is index of color within a palette,
- // and col.g stores a value from 0-15 (again, mapped to the 0-1 range) which is index of palette to use.
- int entryidx = int(col.r * 15);
- int paletteidx = int(col.g * 15);
- int idx = entryidx + (paletteidx * 16);
- // this is turned into an index into the color palette. I'm actually not strictly sure whether this is faster than a texture lookup or not, but it's probably worth a try since there don't seem to be any other options for this sort of thing.
- return _ColorPalette[idx];
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement