Vertex alpha 0.0 - 4.0 ?

Hi gurus

Is it possibe to mulitply alpha values with a constant (4)?
The range 0.0 to 1.0 is too small.

In the end alpha values must be clamped 0.0-1.0 (of course).

A vertex program? a fragment shader?

A vertex program or a fragment program, maybe something else. It depends…
A bit more information?

Is the range between 1.0 and 0.0 to small? Are you using floats or doubles or what? By increasing 0.00001 to 0.0 you’ll get a decent ( :slight_smile: ) range of numbers between 0.0 and 1.0.
Perhaps I dind’t get the question. :wink:

Where in the fragment pipe do you want to multiply?

With register combiners, you can scale input values; this can be used to expand given data.

With ARB_fragment_program, multiplication is trivial.

You can use a look-up texture, that takes a value in the range [0,1] and returns whatever you want; for example you could have a Luminance texture where the range [0,0.25] maps to [0,1] and [0.25,1] maps to 1.

You can also pass in data in almost arbitrary ranges as texture coordinates, depending on what you want to do with it.

I want the formula:

If I have two verteces, one with diffuse alpha=1.0 and the other diffuse alpha=0.0.
I want the final alpha to span 0.0-1.0 range almost from one vertex to the other.

All the methods I suggested will achieve that. Including the ramp look-up.

Thank you very much

This “look-up texture” How does it work?

About the other two methods is it possibe to get some examples ? (I am not an advanced programmer)

(I have some old work at “”)

Baron3D, I’m still not quite sure what y ou mean by “The range 0.0 to 1.0 is too small.”

As for look-up texture, people are talking about dependent texture fetches (I think). Essentially it’s the fragment program equivalent of foo[bar[x]] where foo and bar are textures.

In a triangle I have two verteces, one with diffuse alpha=1.0 and the other diffuse alpha=0.0
If I use a texture with alpha values 0.25 to 1.0 :
At the first vert. ALL alpha values should be clamped to 1.0
At the second vert. ALL alpha values should be clamped to 0.0
In between the two verteces alpha values should be in range 0.0 to 1.0

I’m trying to do a more realistic transission between different textures in my landscape.
Using some sort of “texture splatting”

Baron3D, looking at page 403 of the red book (table 9-4), It looks like a base internal format of GL_RGBA with modulate texture function, if you set the vertices in question to (1,1,1,4a), where a is the alpha you want, you’d get a resultant color of C_t, the texture color, and a resultant alpha of 4a*A_t, which is what you describe above. It would then be clamped.

Does that sound right?


Yes it does.

Look at:

Click to:

What I realy want, is some way to make the transissions more soft.
To make “Image_path.jpg” I use alphatest.


maybe you can also use a completely different approach for your splatting (that’s how I do it):
Instead of storing the alpha in the vertices, use a GL_ALPHA texture that maps to the terrain. If you make your texture smaller (and thus have to strech it more to get it to cover the entire terrain), your transitions get wider.
The Alpha-Texture approach also helps if you are doing some kind of LOD for your terrain because with vertex-alpha you will reduce your number of “hooks” for the alpha and this will result in changes of color, when the lod changes.

Just my 2 cents


Baron3D, thanks for the screenshot, that’s very helpful.

Is this right?: You have a path texture that has an alpha channel corresponding to it’s heightfield. Then you modulate that using alpha values at the vertices?
If that’s the case, it’s not a suprise you get the harsh edges.

If so, you might try exponentiating the alpha channel, rather than depending on clamping. Basicily come up with a function to alter the alpha so that it doesn’t suddenily hit zero since that’s what is creating the harsh edges.

>Is this right?: You have a path texture that has an alpha channel corresponding to it’s heightfield.
>Then you modulate that using alpha values at the vertices?

Yes, I could’n express myslelf better.

>If so, you might try exponentiating the alpha channel

I know what an exponent is, but what do you mean with “exponentiating the alpha channel”?

Must I use a fragmentshader or vertexprogram?
I am using an old gf2.

I could have been more clear. I was thinking of a fragment program, though. I was thinking that alpha^n for n>1 would make a steep dropoff, but not so steep as to create a harsh edge. An exponent may not be the right function, trial and error would be a good approach.

If your target card can’t do fragment proograms, then it’s harder. Do you just have one big path texture that you want to cut out arbitrary walkways from, or could you make a path out of edges and middles, in which case you could do the blending in photoshop.

The path texure is a tiled texture.
I’m rewriting my old endgine converting from dx6 to ogl.
The landscape is 10x10 miles.
So one big path texture is impossible.

Well, I’m planning to by a cheap 5900XT card before summer.
And about target card, soon every card could do fragment programs.

Now the math is:
if(Texutre_alpha * Diffuse_alpha > 0.5) draw_pixel

What about: (per pixel)
alpha = (Texture_alpha * Diffuse_alpha - 0.5) * 8
Maybe with different constants.

I was thinking per pixel doing
alpha = pow((Texture_alpha * Diffuse_alpha), 3)
You could add constants here or there to that, but that would create a sharp cutoff without any really harsh edges.

However, I think you migt get a better effect (with more effort) by having an “edge of path” texture, and a “path” texture, and carefully combining them so they line up. Then you could draw the grass-path transition, which would look much nicer. It would take effort and thought to make it lilne up nicely, though.


… why oh why look at complicated solutions ?


At the first glance this looked realy good.

Am I missing something ?
Absolutley NO reaction.
Just these two lines ?
I use them before glBegin … gl End

I solved it, Tanks for all help.

Texture_alpha is a heightmap (with some noise) in the range 0.15 to 0.65.
Where 0.15 is heigh level and 0.65 is low.

Vertex_alpha is 0.0 and 1.0

And here is the code:

And here are the result. Comments?