How can I tint the screen or whatever I'm about to draw?

Started by lainmaster, September 08, 2009, 19:26:53

Previous topic - Next topic

lainmaster

I know with glColor4f I can make things darker, or semi-transparent, but if I want to make them lighter? Or change the saturation?

Kai

Hi,

QuoteI know with glColor4f I can make things darker, or semi-transparent, but if I want to make them lighter? Or change the saturation?
Well, with glColor you specify the color in RGBA-space of everything you draw afterwards. The drawn geometry then receives the specified color (as well as texturing if enabled) and will be blended (if enabled) with what is already present in the color buffer.
I do not exactly know what you mean with "making things darker and lighter".
If by that you mean to transform the values of what is already in the color buffer, then use blending (draw a fullscreen grid of whatever color is appropriate (gray if you want to make things darker)). This is the simplest way but has very many limitations as to which functions can be applied on the source- and destination color.
If you desire more sophisticated "post-processing" effects, then you should go with custom fragment shaders.
You would then sample the values in the color-buffer (as a texture) and apply any function on them to produce the final color. (like a HLS <-> RGB transformation to change saturation)

lainmaster

So basicly there's no function that allows this? I have to call more than one function to create this effect? I forgot to mention, it's for a 2D game (if that changes anything)

Kai

QuoteSo basicly there's no function that allows this? I have to call more than one function to create this effect? I forgot to mention, it's for a 2D game (if that changes anything)
There is no OpenGL function/entry point like "glSaturateScreen(float saturation)" that allows this, although it would be a nice extension :-) (as if there are not enough extensions anyways).
You have to implement it on your own via blending or fragment shader.

lainmaster

What about something like glColor(2, 2, 2) where it usually accepts 1 as the max, where 1 is the original source color, but up to 2, where 2 is 255 of that color?

Say, if I have a green tree and paint it after glColor(0, 0, 0), I will only see a black shadow of that tree.  Now I want something like glColor(2, 2, 2) which would make the same but white (or glColor(1.5f, 1.5f, 1.5f) that would make it whiter than original but not completely white). No function in gl for that either? I know how to do it using blend, but I thought it might be slower that way, and that maybe gl came with a function for that already...

Kai

QuoteWhat about something like glColor(2, 2, 2) where it usually accepts 1 as the max, where 1 is the original source color, but up to 2, where 2 is 255 of that color?
Hm, I thought I knew what you are up to, but I'm completely puzzled now :-).
You mean glColor(2, 2, 2) would be:
- If used as the source color of a geometry, the resulting fragments will affect the destination color of the pixel in the color buffer as follows: dst' = RGB(2 * dst.r, 2 * dst.g, 2 * dst.b) ?
So you want to make the destination color lighter (not darker)?
With glColor this is not possible, as far as I know, because of the [0, 1]-clamping.
There is an extension that allows floating-point colors, but I don't know whether glColor would clamped anyways. I usually did these things with shaders.

Quoteif I have a green tree and paint it after glColor(0, 0, 0), I will only see a black shadow of that tree.  Now I want something like glColor(2, 2, 2) which would make the same but white (or glColor(1.5f, 1.5f, 1.5f) that would make it whiter than original but not completely white)
Hum... I'm sorry, but I think you have to explain more thoroughly what you want to do.

If you use glColor without blending, the drawn geometry will have exactly that color (without lighting, texturing, etc.) if blending is disabled.
If blending is enabled, it depends on the blending function.

lainmaster

QuoteWith glColor this is not possible, as far as I know, because of the [0, 1]-clamping.
Yes, that's what I said. That's why I said "something like", "something equivalent".

QuoteSo you want to make the destination color lighter (not darker)?
Exactly

I really have almost no knowledge at all of GL... don't know what "color of a geometry" or "resulting fragments" mean >_>

Note: it's not just the whole screen I wanna tint, I also wanna be able to apply it to

RPG Maker 2003, an application to create RPGs, had a tint function. Pretty much exactly what I wanna do. Here are some screenshots, hope they help understand =/

Normal color:



Tint at 150% (equivalent to 1.5f):



Tint at 200% (equivalent to 2f)



These are just examples, I want to be able to control RGB separatedly, too. Note that 200% is really pure white. So the function for 100% to 200% would be different than the one from 0 to 100%. The one from 0% to 100% would behave exactly like glColor, so for those cases, glColor suits me.

Anyhow, it seems this can't be done with just one function, so maybe it can be done with blend, and I'll have to learn about that (because I trully have almost no knowledge of GL)

You mean glColor(2, 2, 2) would be:
- If used as the source color of a geometry, the resulting fragments will affect the destination color of the pixel in the color buffer as follows: dst' = RGB(2 * dst.r, 2 * dst.g, 2 * dst.b) ?

Yes, that's what I want. Sort of, anyways.

After checking out glBlendFunc, I can't come up with anything that works fine without drawing the image more than once.

Fool Running

Try look at the second post here: http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=120353
I think its similar to what you want to do. Basically you just draw a big quad over the entire screen and change the color to produce an effect. It probably won't look perfect, but should give you a place to start.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

lainmaster

And if I only want to tint an specific image and not the whole screen, and that image has transparent areas? I'd have to create a mask, right? Won't that bring the FPS down?

Fool Running

It is possible you could also get the effect you need by drawing the image once normally and then again with a different color/blending mode on top of the first draw, but you might have to implement some pixel shaders that do what you need.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

lainmaster

I just read an article on shaders, looks too complicated for now. I get how the color/blending would work, more or less, but I really rather keep the FPS as high as possible, so my game has compatibility with old computers; graphics aren't 100% relevant to my MMO RPG. (Al least the first version, I'll have to add that in the future, but it's not a priority)

Thanks for all the patience and help =)

broumbroum