Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: palette swap via shaders glsl  (Read 1969 times)

0 Members and 1 Guest are viewing this topic.

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
palette swap via shaders glsl
« on: April 04, 2012, 01:21:15 am »
Hi. I'm tring to  do a palette swap using shaders. Its for expecific colors, so my script looks something like this:
Code: [Select]
effect
{
vec4 pixel = framebuffer(_in);
vec4 c1 = vec4(32/255.0, 160/255.0, 128/255.0, 1.0);
vec4 c2 = vec4(1.0, 1.0, 1.0, 1.0);//white
if (pixel == c1) pixel = c2;
_out = pixel;
}

The thing is is works for some colors and others not. I think is has to do with the conversion from rgb 255 to floats. Any ideas? Is there a way to output/cout from the script to console window?

Thank you.



Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: palette swap via shaders glsl
« Reply #1 on: April 04, 2012, 08:14:42 am »
Quote
The thing is is works for some colors and others not. I think is has to do with the conversion from rgb 255 to floats.
Probably. You should use fuzzy comparisons (between (x - epsilon) and (x + epsilon) instead of equals x).

Quote
Is there a way to output/cout from the script to console window?
There's no way, this shader runs on your graphics card, all it can output is pixels that will be shown on screen.
Laurent Gomila - SFML developer

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
Re: palette swap via shaders glsl
« Reply #2 on: April 04, 2012, 10:47:36 am »
 :-[ Ugh. The obvious. It's working now.
Why is the technical explanation of why some apps uses rbg and other floats?

Laurent your my hero.
Thanks. :)



Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: palette swap via shaders glsl
« Reply #3 on: April 04, 2012, 10:53:48 am »
Quote
Why is the technical explanation of why some apps uses rbg and other floats?
Are you talking about shaders, or about SFML (and other graphical apps)?

Color components are always processed as normalized floats by the GPU.
Laurent Gomila - SFML developer