Hi guys. I have been trying to implement my own color balance that i will apply on camera, For that i used this formula:
**R** = 255 / ***Rw*** * R1
**G** = 255 / ***Gw*** * G1
**B** = 255 / ***Bw*** * B1
Where ***Rw Gw*** and ***Bw*** represents the value of a colour component believed to represent White and *R1 G1* and *B1* representing the original value of a colour component before implementing the colour balance formula.
I tried to implement it like this:
public class ColorBalance : MonoBehaviour
{
[Range(0,255)]
public int R = 0;
[Range(0, 255)]
public int G = 0;
[Range(0, 255)]
public int B = 0;
[Range(0, 255)]
public int Alpha = 255;
public Material material;
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
material.SetVector("_RGB", new Vector4(255f/R, 255f/G ,255f/ B, 255f/Alpha));
Graphics.Blit(source, destination, material);
}
}
Where material had shader like this:
Shader "PostProcessing/ColorBalance"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_RGB("_RGB", Float) = (0.01,0.01,0.01, 1)
}
SubShader
{
Cull Off ZWrite Off ZTest Always
Pass
{
Tags {"Queue" = "Transparent" "RenderType" = "Transparent" }
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform float4 _RGB;
sampler2D _MainTex;
half4 _MainTex_ST;
fixed4 frag (v2f_img i) : Color
{
fixed4 col = (1.0/ _RGB) * tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv, _MainTex_ST));
return col;
}
ENDCG
}
}
Fallback off
}
But the end result was not correct.
Original:
![alt text][1]
Red 255 from my method:
![alt text][2]
So what am i doing wrong? Is it correct way of doing it?
Please help.
[1]: /storage/temp/136835-pers.png
[2]: /storage/temp/136837-per2.png
↧