Color * Texture

Started by
13 comments, last by ufinii 18 years, 4 months ago
Standard blending is (1-t)*c1+t*c2 with 0<=t<=1. Here you are blending with two colors, i.e. black and white. So if you are between 0 and 1 t is your blend value, c1 is black and c2 is your texture color. If you are between 1 and 2 then t is your blend value minus 1, c1 is your texture color and c2 is white.

Logically you have three points, i.e. (0,0), (1,c) and (2,1). So above is simply drawing a line connecting those points. The "brightness" is X and the pixel color is Y. You could also fit a quadradic to those three points. Then you don't get that discontinuity at (1,c), but three points define a quadradic. There is only one quadradic going through those three points as long as they are distinct. There is an infinite number of cubics going through those three points though. That gives you a degree of freedom to play with the shape of the curve.

How do you fit a polynomial to a set of points? One way is a LaGrange Interpolating Polynomial. Using the above you get (x*(x-1))-(x*(x-2))*c for a quadradic. With a cubic you throw in a variable for the 4th point. In practice you might want that to actually be a function of c. As an example you might want to say that at 0.5 it is always a certain percentage of c so your fourth point is (0.5,p*c).

You can also patch two curves together using bezier curves or splines, but that is most likely a little more complex than you need for simply setting the brightness of a pixel. Overall the whole thing is pretty much a waste because setting your texture environment mode to GL_BLEND and modifying the environment color and vertex colors can fade the entire image to black, white or any other color you please. You can download Nate Robbins Tutorials here and play with the texture tutorial to see the impact of changing those parameters.
Keys to success: Ability, ambition and opportunity.
Advertisement
Well... Since the game isn't really graphically complex i tried using additive blending

//drawSprite()

glDepthFunc(GL_LEQUAL);

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);

//drawSprite()

glDepthFunc(GL_LESS);
glDisable(GL_BLEND);


But it doesn't look smooth (I can notice the rectangle area around the sprites)... I'm doing something wrong?
http://fuffi.nj-h.com/
I tried with different blend functions but I'm still having that problem...


Looks like the alpha channel gets multiplied too but it's really strange since it doesn't change anything if I set for example:

glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

or

glColor4f(1.0f, 1.0f, 1.0f, 0.0f);

before the blending...
http://fuffi.nj-h.com/
Quote:Original post by ufinii
I tried with different blend functions but I'm still having that problem...


Looks like the alpha channel gets multiplied too but it's really strange since it doesn't change anything if I set for example:

glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

or

glColor4f(1.0f, 1.0f, 1.0f, 0.0f);

before the blending...

To use the the alpha of the source color, set the blending equation params to GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA.

/edit: But if you use this method, it will still look like there is one oddly bright quad over the other regular ones (as you've already noticed and mentioned in your previous post). You may try using several small quads and set their alpha according to their distance from the bright object. The one directly above has an alpha of, say 0.5, and ones a little farther away have lower values, 0.1 or 0.01, say.

For really good results, use a bloom or glow effect. You don't need a shader, just render your sprite to a texture, blur the texture and render a textured quad over the original (like you were doing previously) with additive blending.
Really thanks for suggestions :)

I will look for it
http://fuffi.nj-h.com/

This topic is closed to new replies.

Advertisement