Im trying to make a full screen colorcorrection shader (camera shader).
For that i want to be able to adjust parameters directly on my camera, and then pass them onto the shader when needed.
I have made a little test. I have added a parameter called “Gamma” that i want to move from the C# code onto the shader. However im not sure how i can do it.
So in my C# file that i attach to the camera i add:
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[ExecuteInEditMode]
[AddComponentMenu("MyShaders/CustomColor")]
public class CustomColor : ImageEffectBase
{
public Color gamma = Color.white; // This is the value i want to pass
void OnRenderImage (RenderTexture source, RenderTexture destination)
{
Graphics.Blit (source, destination, material);
}
}
}
And then i have the shader:
Shader "Hidden/CustomColor" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Gamma ("Gamma", Color) = (1.0,1.0,1.0,1.0)
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform float _Gamma; //The color i want to get!
fixed3 frag (v2f_img i) : SV_Target
{
fixed3 original = tex2D(_MainTex, i.uv);
float lift = 0.0;
//float gamma = 0.5;
float gain = 1.0;
//LiftGammaGain
fixed3 LGG = pow( gain*(original.rgb + lift*(1-original.rgb)) ,(1/_Gamma)); //sudo code, won't work yet
output = LGG;
return output;
}
ENDCG
}
}
Fallback off
}