Jump to content

True Saturation, Brightness, Contrast


TylerH
 Share

Recommended Posts

Who can deny it? The current saturation, brightness, and contrast post effects just are lacking. They seem to basically play with the brightness, period. So I searched online, and found an existing S.B.C. function written in GLSL.

 

I went ahead and replaced the setup in postfilter.frag to utilize this function, and I now get much better results when using the Saturation, Brightness, and Contrast sliders. They just seem to give me the right "feel" of appearance for the values. Brightness of 2.0 looks twice as bright, not twice as gray/washed out, etc.

 

Below is a drop in replacement for postfilter.frag:

 

varying vec4 fragcolor;
varying vec4 fragcoord;


//==========================================
//Textures
//==========================================
uniform sampler2D texture0; //color
uniform sampler2D texture1; //depth
uniform sampler2D texture2; //normal
uniform sampler2D texture3; //blurred bloom buffer
uniform sampler2D texture4; //unblurred bloom buffer
uniform sampler2D texture5; //caustics frame 1
uniform sampler2D texture6; //blurred DOF texture
uniform sampler2D texture7; //wobble texture / caustics frame 2
uniform sampler2D texture10; //noise texture for effects
uniform sampler2D texture11; //ssao texture


uniform float contrast = 1.0;
uniform float brightness = 1.0;
uniform float saturation = 1.0;

//==========================================
//Automatic uniforms
//==========================================
uniform float apptime;
uniform vec2 buffersize;
uniform vec2 camerarange;
uniform float camerazoom;


include "depthtozposition.frag"


//==========================================
//HDR uniforms
//==========================================

uniform float hdrexposure;

//==========================================
// Fog variables
//==========================================

uniform vec4 fogcolor = vec4(1.0);
uniform vec2 fogrange = vec2(0.1,1000.0);


//==========================================
// DOF variables
//==========================================

uniform vec2 dofnearrange;
uniform vec2 doffarrange;
uniform float dofstrength=1.0;


//==========================================
// Caustics variables
//==========================================
uniform vec4 causticsmappingaxes[4];
uniform float causticsframeinterpolation;
uniform vec4 causticscolor;


//==========================================
// Volumetric light scattering variables
//==========================================

#ifdef LW_GODRAYS
uniform vec3 screenlightpos;
uniform vec3 lightvector;
uniform vec4 raycolor = vec4(1.0);
//uniform float exposure = 0.35;
#define exposure 1.0
#define RAYSAMPLES 64
#define MAXRAYLENGTH 1.0
#endif


//==========================================
// Motion blur variables
//==========================================

uniform vec2 motionblurvector;
uniform float motionblurstrength = 1.0;
uniform float motionblurdistance;


//==========================================
// SSAO Functions
//==========================================

#ifdef LW_SSAO

float ao=0;
#define aointensitybias -0.55

#define ssaostrength 1.0

float readDepth( in vec2 coord ) {
	//#ifndef __GLSL_CG_DATA_TYPES
	//	coord.y = 1.0 - coord.y;
	//#endif
	return (2.0 * camerarange.x) / (camerarange.y + camerarange.x - texture2D( texture1, coord ).x * (camerarange.y - camerarange.x)) * camerarange.y;	
}

float compareDepths( in float depth1, in float depth2 ) {
	float aoCap = 1.0;
	float aoMultiplier=10.0;
	float depthTolerance=0.000;
	float aorange = 100.0;///(camerarange.y-camerarange.x);// units in space the AO effect extends to (this gets divided by the camera far range
	float diff = ( clamp(1.0-(depth1-depth2) / aorange,0.0,1.0) );
	float ao = min(aoCap,max(0.0,depth1-depth2-depthTolerance)) * diff;
	ao *= aoMultiplier;
	ao=clamp(ao,0.0,1.0);
	return ao;
}

#endif

vec3 ContrastSaturationBrightness(vec3 color, float brt, float sat, float con)
{
// Increase or decrease theese values to adjust r, g and b color channels seperately
const float AvgLumR = 0.5;
const float AvgLumG = 0.5;
const float AvgLumB = 0.5;

const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);

vec3 AvgLumin = vec3(AvgLumR, AvgLumG, AvgLumB);
vec3 brtColor = color * brt;
vec3 intensity = vec3(dot(brtColor, LumCoeff));
vec3 satColor = mix(intensity, brtColor, sat);
vec3 conColor = mix(AvgLumin, satColor, con);
return conColor;
}


//==========================================
// Main
//==========================================

void main( void ) {

//==========================================
//General variables
//==========================================	

vec2 texcoord = gl_FragCoord.xy/buffersize;
vec4 color;
float depth;
float lineardepth;
vec3 normal;
vec4 cnormal;
vec4 outputcolor;	
vec2 pixelsize = 1.0/buffersize;
float irisadjustment=1.0;
float bloomstrength = 1.0;
float bloomirisadjustment=2.0;	

#ifdef LW_WOBBLE
	Include "wobble.frag"
#endif

color = texture2D( texture0, texcoord ) * fragcolor;
depth = texture2D( texture1, texcoord ).x;
cnormal=texture2D( texture2, texcoord );
normal = cnormal.xyz * 2.0 - 1.0;
lineardepth = DepthToZPosition( depth );

outputcolor = color;
float pixelbrightness = outputcolor.r * 0.3 + outputcolor.g * 0.59 + outputcolor.b * 0.11;


//==========================================
// Now include the effects we want
//==========================================

#ifdef LW_HDR
	include "hdr.frag"
#endif

#ifdef LW_CAUSTICS
	include "caustics.frag"
#endif

#ifdef LW_MOTIONBLUR
	include "MotionBlur.frag"
#endif

#ifdef LW_BRIGHTEN
	outputcolor = max( outputcolor, texture2D(texture4,texcoord).w * texture2D(texture5,texcoord) );
#endif

#ifdef LW_NEARDOF
	Include "neardof.frag"
#endif

#ifdef LW_FARDOF
	Include "fardof.frag"
#endif

#ifdef LW_GODRAYS
	Include "godrays.frag"
#endif

#ifdef LW_SSAO
	float gray = outputcolor.r * 0.3 + outputcolor.g * 0.59 + outputcolor.b * 0.11;	
	vec4 ssaocolor = texture2D(texture11,texcoord);
	ao = ssaocolor.x;
	outputcolor.rgb = mix(outputcolor.rgb*ao,outputcolor.rgb,gray+aointensitybias);
	//outputcolor.x = outputcolor.rgb*0.5;
	//outputcolor.x += ssaocolor.x * 0.75;
	//outputcolor.y += ssaocolor.y * 0.75;
	//outputcolor.z += ssaocolor.z * 0.75;
	//outputcolor = vec4(ao);
	//outputcolor=ssaocolor;
#endif

#ifdef LW_DISTANCEFOG
	Include "fog.frag"
#endif

#ifdef LW_BLOOM
	Include "bloom.frag"
#endif

#ifdef LW_GAUSSIAN
	Include "gaussian.frag"
#endif

//#ifdef LW_BRIGHTNESS
//Include "brightness.frag"
//#endif
//#ifdef LW_CONTRAST
//Include "contrast.frag"
//#endif
//#ifdef LW_SATURATION
//Include "saturation.frag"
//#endif
outputcolor.rgb = ContrastSaturationBrightness(outputcolor.rgb,brightness,saturation,contrast);


//==========================================
// Set the fragment color to the output variable
//==========================================

gl_FragColor = outputcolor;
gl_FragDepth = depth;
}

  • Upvote 1

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

I didn't 'down-rate' you (don't ever really check those things nor think they mean much), but come on:

 

Below is a drop in replacement for postfilter.frag

 

you can't take the time to do that, why should he?...or move on and save your comments for yourself. :)

 

(doing the above quote would have taken less time than me commenting now :lol: )

  • Upvote 1

Vista Ultimate SP1 64bit | Q6600 2.40 GHZ | 8GB RAM | 320MB Nvidia 8800GTS

Link to comment
Share on other sites

ergo, not exactly what you said at first, is it?

 

 

anyhow, not trying to demonize you....just get tired of seeing people put stuff up for

free and of their own sweat and then have those that reap the rewards barely manage to

either put forth some of their own effort to try it, or at the very least say a bit of 'thanks'...

 

apologies for derailing, TylerH. :)

  • Upvote 1

Vista Ultimate SP1 64bit | Q6600 2.40 GHZ | 8GB RAM | 320MB Nvidia 8800GTS

Link to comment
Share on other sites

Why do people not like you? I like you. :)

Heh thanks. Should sig it, although I already have 2 good ones. It'll be the next one ;)

 

ergo, not exactly what you said at first, is it?

anyhow, not trying to demonize you....just get tired of seeing people put stuff up for

free and of their own sweat and then have those that reap the rewards barely manage to

either put forth some of their own effort to try it, or at the very least say a bit of 'thanks'...

 

apologies for derailing, TylerH. :(

 

You're right, sorry. Thanks for taking some of your time Tyler, although I see no difference at all.

  • Downvote 1
Link to comment
Share on other sites

I will do some comparison shots in a moment here, assuming I don't get sidetracked.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

I will do some comparison shots in a moment here, assuming I don't get sidetracked.

 

 

 

Did you get sidetracked? :)

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

  • 1 month later...

Yeah, I got sidetracked by life, for approximately 2-3 months.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...