BASIC

Author Topic: Shaders - Sepia, BLack & White  (Read 6406 times)

Offline kaotiklabs

  • Dr. Type
  • ****
  • Posts: 313
  • Spain is diferent
    • View Profile
Shaders - Sepia, BLack & White
« on: 2012-Apr-25 »
Ive been playing a bit with shaders and 2D tints and managed to compile 2 of them.

I post it here in case it could be useful for anyone or even me in the future.

for sepia tint just use this

Code: GLBasic [Select]
uniform sampler2D image;

void main() {
        vec3 texel = texture2D(image, gl_TexCoord[0].xy).rgb;
        gl_FragColor = vec4(texel.x,texel.y,texel.z, 1.0);

        gl_FragColor.r = dot(texel, vec3(.393, .769, .189));
        gl_FragColor.g = dot(texel, vec3(.349, .686, .168));
        gl_FragColor.b = dot(texel, vec3(.272, .534, .131));  
}

For a Black & white filter this one

Code: GLBasic [Select]
uniform sampler2D image;

void main() {
        vec3 texel = texture2D(image, gl_TexCoord[0].xy).rgb;
        gl_FragColor = vec4(texel.x,texel.y,texel.z, 1.0);

        gl_FragColor = max(texel.r,max(texel.g,texel.b));
}
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3366
  • Integrated Brain
    • View Profile
Re: Shaders - Sepia, BLack & White
« Reply #1 on: 2012-Apr-25 »
kaotics how use your code...

in 3d it´s whit X_Shader command but in 2D, how implement your code... I think it´s very interesting...

Offline kaotiklabs

  • Dr. Type
  • ****
  • Posts: 313
  • Spain is diferent
    • View Profile
Re: Shaders - Sepia, BLack & White
« Reply #2 on: 2012-Apr-25 »
well, is the same.

loadshader
setshader

this shaders are aplied to the texture images.
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3366
  • Integrated Brain
    • View Profile
Re: Shaders - Sepia, BLack & White
« Reply #3 on: 2012-Apr-25 »
Ok, thanks about your game in youtube... where I can take a look... I only watch the video whit hyper-Speed of the creation of the game... but i can´t found the gameplay video... :noggin:

Offline kaotiklabs

  • Dr. Type
  • ****
  • Posts: 313
  • Spain is diferent
    • View Profile
Re: Shaders - Sepia, BLack & White
« Reply #4 on: 2012-Apr-25 »
Still not gameplay video, problems syncing the audio with fraps.

Eitherway, you can download it here!
http://www.ludumdare.com/compo/ludum-dare-23/?action=preview&uid=2883
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Offline r0ber7

  • Prof. Inline
  • *****
  • Posts: 528
    • View Profile
Re: Shaders - Sepia, BLack & White
« Reply #5 on: 2012-Apr-26 »
Interesting. I've considered a day & night cycle for my game. Do you think this could be accomplished with a similar approach? Also, is this code cross-platform? (I think it is, since it looks like they're just GL functions, but just to be sure).

Offline kaotiklabs

  • Dr. Type
  • ****
  • Posts: 313
  • Spain is diferent
    • View Profile
Re: Shaders - Sepia, BLack & White
« Reply #6 on: 2012-Apr-26 »
Im not a GL guru, so dont trust me too much but I believe is crossplatform because all the above layer is always opengl.

Theres a way to pass a variable to the shader so I believe that a day/night cycle kinda shader should be possible.

Let me know if any of you goes further as is a subject that really interest me too. :P
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
Re: Shaders - Sepia, BLack & White
« Reply #7 on: 2012-Apr-26 »
From what I have read on the net & various OGL books I have Shaders where introduced as an extension to OGL 1.4 & built into the core from OGL 2.0 onwards. Obviously that relates to desktop machines like Windows/Mac/Linux & I have not found any solid info yet regarding mobile devices.

This site says http://www.ozone3d.net/tutorials/glsl_intro.php
Quote
All the nVidia Geforce FX 5200 cards and higher or ATI Radeon 9600 cards and higher tolerate GLSL
, albeit it is a 2005 site but does give you a rough minimum of desktop hardware required. I have read & also witnessed some problems with Intel onboard gfx with regards to their OGL driver but cannot say which chipsets are effected or if they use a common driver like Nvidia or ATI.

I think it may just be a case of trying it on the devices that GLB supports & see what happens like all the different generation of iPhones/iPods, Cannoo, Palm etc. Android on the other hand may be a problem as unlike the former which has a known hardware base Android varies a lot.

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Shaders - Sepia, BLack & White
« Reply #8 on: 2012-Apr-26 »
Won't work. Mobile GL is eithet 1.1 w/o shaders or 2.0 where everything is a shader.