As I said I found out how to rotate. My shader works perfect. But now I need to modify the contrast. I found a shader which modifies image properties but it is fragment/vertex type. My rotation shader is surface type. I was unable to mix them and then I read they are not compatibles. Does anyone have an idea how to convert one in to the other type or how to make them work at the same time? I want to rotate and I want to modify the contrast.
Or maybe is there a simple way to change the contrast from the first shader??
Shader "Custom/NewShader" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_RotationSpeed ("Rotation Speed", Float) = 2.0
_RotationDegrees ("Rotation Degrees", Float) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert vertex:vert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
float _RotationDegrees;
void vert (inout appdata_full v) {
v.texcoord.xy -=0.5;
float s = sin ( _RotationDegrees);
float c = cos ( _RotationDegrees);
float2x2 rotationMatrix = float2x2( c, -s, s, c);
rotationMatrix *=0.5;
rotationMatrix +=0.5;
rotationMatrix = rotationMatrix * 2-1;
v.texcoord.xy = mul ( v.texcoord.xy, rotationMatrix );
v.texcoord.xy += 0.5;
}
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Shader "Custom/Effects" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_SaturationAmount ("Saturation Amount", Range(0.0, 1.0)) = 1.0
_BrightnessAmount ("Brightness Amount", Range(0.0, 1.0)) = 1.0
_ContrastAmount ("Contrast Amount", Range(0.0,1.0)) = 1.0
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform float _SaturationAmount;
uniform float _BrightnessAmount;
uniform float _ContrastAmount;
float3 ContrastSaturationBrightness( float3 color, float brt, float sat, float con)
{
//RGB Color Channels
float AvgLumR = 0.5;
float AvgLumG = 0.5;
float AvgLumB = 0.5;
//Luminace Coefficients for brightness of image
float3 LuminaceCoeff = float3(0.2125,0.7154,0.0721);
//Brigntess calculations
float3 AvgLumin = float3(AvgLumR,AvgLumG,AvgLumB);
float3 brtColor = color * brt;
float intensityf = dot(brtColor, LuminaceCoeff);
float3 intensity = float3(intensityf, intensityf, intensityf);
//Saturation calculation
float3 satColor = lerp(intensity, brtColor, sat);
//Contrast calculations
float3 conColor = lerp(AvgLumin, satColor, con);
return conColor;
}
float4 frag (v2f_img i) : COLOR
{
float4 renderTex = tex2D(_MainTex, i.uv);
renderTex.rgb = ContrastSaturationBrightness(renderTex.rgb, _BrightnessAmount, _SaturationAmount, _ContrastAmount);
return renderTex;
}
ENDCG
}
}
FallBack "Diffuse"
}
