PDA

View Full Version : modifying pixels



Hylke Donker
08-02-2005, 03:38 AM
Hello,
How can I change the values of the pixels, after all transformations, tests and other operations?
What I mean is, how can I (in example) change the value of all pixels(in example +0.5 on red) before they're drawn to the screen.
So that I can change the brightness of my program.
Any idea how I can do that?
Thanx Hylke

jide
08-02-2005, 04:14 AM
The more generic way to do that is with using shaders.
But for brightness, I guess the best thing is to use the window manager API (ie WIN32 API or X11) so that you won't need to change color values. Also, changing color and so isn't the best way to change brightness because you'll have to change light values too, and if a light already cast bright white light, then you won't be able to enbright it more.

Hope that helps.

Hylke Donker
08-02-2005, 04:22 AM
Originally posted by jide:
The more generic way to do that is with using shaders.
But for brightness, I guess the best thing is to use the window manager API (ie WIN32 API or X11) so that you won't need to change color values.
[quote] Also, changing color and so isn't the best way to change brightness because you'll have to change light values too, and if a light already cast bright white light, then you won't be able to enbright it more.

Hope that helps.I don't think that really matters.
Because you can't make a thing whiter than fully white.
But how do I do that with shaders?
And what exactly are they?

jide
08-02-2005, 04:34 AM
This can matter. If your window manager has a very low brightness, full white could look like dark grey. But I'm not an expert with that (never tried that in fact).

As for shaders, I've never used them. But I start knowing them a bit :)

Shaders are programmable pipelines on recent graphic boards (since geforce 3 I guess). They replace the default fixed pipeline all cards have before.
So for each vertex or each fragment you can program new ways to compute them. You can then apply a shader to change each color that enter it with a new formula (let's say: output_color = input_color + .5) so that all your colors will be added to 0.5. As you can see, this is not a real good model for brightness, as colors that were already more than 0.5 will be truncated to 1.0 so you will loose the color harmony.

You can also use shaders for making per pixel lighting that looks somewhat best for brightness even if, as colors, full white light won't light more.

But I'm sure shaders won't apply well for brightness. You really need a windowing API.

Hope that helps.

Aeluned
08-02-2005, 04:35 AM
Shaders are (generally) small programs that run on the vertex or fragment processor.

Google GLSL, glslang, or OpenGL shading language for more info. There are many shader languages, but since this is an OpenGL forum I've mentioned gl-slang.

In your example above, if you wanted to modify the red channel of each fragment (a fragment can be thought of as a pixel but isn't exacly that) by +0.5 you would have something like:

void main()
{
gl_FragColor.r += 0.5;
}

Hylke Donker
08-02-2005, 05:54 AM
Would it be a good idea to buy the:
OpenGL Shading Language
?
I already understand most of my OpenGL red book.

Aeluned
08-02-2005, 09:15 AM
The Book?
Absolutely; it's a handy reference if you're interested in getting into shader programs.

Hylke Donker
08-03-2005, 12:21 AM
Ok, thanx for your information.
Now I've just gotta wait untill I have enough money to buy the book and ship it to the netherlands :-)
Hylke