Black & White (sepia filter) GLSL

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
devsh
Competition winner
Posts: 2049
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Black & White (sepia filter) GLSL

Post by devsh »

sorry for making it such a small post

but I was making a quick black and white filter and it came to me that the average method that most people would use (R+G+B)/3 is a bit too dark. So I came up with this;

fragment shader

Code: Select all

uniform sampler2D tex;

void main() {
   vec4 FragColor = texture2D(tex, gl_TexCoord);
   gl_FragColor = max(FragColor.r,max(FragColor.g,FragColor.b));
}
P.S. I will make a Deffered Shading and Shadowing snippet but I have to make it bug free first (problems with unbind Multiple Render Targets)
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Why not do the normal dot(FragColor, vec3(.3, .59, .11)) to get the intensity? If you want a sepia filter, you'd use the result to do a texture lookup onto a sepia tone texture.

Travis
jpoag
Posts: 25
Joined: Mon Aug 10, 2009 1:00 am

Post by jpoag »

Sepia:

Code: Select all

NewR = R*.393 + G*.769 + B*.189;
NewG = R*.349 + G*.686 + B*.168;
NewB = R*.272 + G*.534 + B*.131;
or presumably

Code: Select all

gl_FragColor.r = dot(FragColor, vec3(.393, .769, .189))
gl_FragColor.g = dot(FragColor, vec3(.349, .686, .168))
gl_FragColor.b = dot(FragColor, vec3(.272, .534, .131))
-James
Post Reply