Advertisement
PsichiX

Contrast/Brightness Unity Shader

Feb 12th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/ContrastBrightness" {
  2.     Properties {
  3.         _MainTex ("Base (RGB)", 2D) = "white" {}
  4.         _Contrast ("Contrast", Float) = 0.8
  5.         _Brightness ("Brightness", Float) = 0.1
  6.     }
  7.     SubShader {
  8.         Pass {
  9.             CGPROGRAM
  10.            
  11.             #pragma vertex vMain
  12.             #pragma fragment fMain
  13.    
  14.             uniform sampler2D _MainTex;
  15.             uniform float _Contrast;
  16.             uniform float _Brightness;
  17.            
  18.             struct INPUT
  19.             {
  20.                 float4 position : POSITION;
  21.                 float2 coord : TEXCOORD0;
  22.             };
  23.            
  24.             struct OUTPUT
  25.             {
  26.                 float4 position : SV_POSITION;
  27.                 float2 coord : TEXCOORD0;
  28.             };
  29.    
  30.             OUTPUT vMain( INPUT input )
  31.             {
  32.                 OUTPUT output;
  33.                 output.position = mul( UNITY_MATRIX_MVP, input.position );
  34.                 output.coord = input.coord;
  35.                 return output;
  36.             }
  37.            
  38.             float4 fMain( OUTPUT input ) : COLOR
  39.             {
  40.                 float4 col = tex2D( _MainTex, input.coord );
  41.                 col.xyz = ( ( col.xyz - 0.5.xxx ) * _Contrast.xxx ) + 0.5.xxx;
  42.                 col.xyz += _Brightness.xxx;
  43.                 return col;
  44.             }
  45.            
  46.             ENDCG
  47.         }
  48.     }
  49.     FallBack "Diffuse"
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement