Situation
I have a shader for images with "wonky" colors - the reason the colors are so messy is because it's a sneaky way to encode data into the RGB color channels eg the red channel is terrain data the blue channel is water data and the green channel is lighting data (highlights & shadows).
I have color bars for each set of data eg I take the value for the red channel and find it's position on the color bar and that is the proper color to return for the pixel.
Red Channel Data from original image
Color bar for Red Channel Data
So that this point, as I'm looking at every pixel via my fragment shader, red values of 1
will pull from the color bar to the furthest right side (lighter colors) while values of 0
will pull from the color bar on the furthest left side (darker colors).
I have a basic fragment shader setup where I can get the respective color values from the image (main texture) and can read out the rgb values of each frag. I also have my color bar pulled into the shader via sampler2D
but I'm not sure how to sample a color from the color bar based only the red value from the main tex's red value.
Question
Knowing the 0-1 value of red at every pixel on my mian texture, how can I return the associated color from the color bar?
extra
basics of my shader
Properties{
_ColorBar("Color Bar", 2D) = "" {}
}
SubShader{
// Cull off // for doublesized texture @jkr todo: disable for prod
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
ZWrite Off
// ZTest Off
Blend SrcAlpha OneMinusSrcAlpha
// Cull front
// LOD 100
Pass {
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
...
sampler2D _MainTex; // maintex is set programatically at runtime
sampler2D _ColorBar; // set via the unity inspector
float4 frag(v2f f) : COLOR
{
fixed4 col = tex2D(_MainTex, f.uv);
return col;
}
ENDHLSL
}
}
FallBack "VertexLit"
Inspector View