Grass gets more opaque farther

Jules Robichaud Gagnon

28-05-2008 02:10:17

Hello JohnJ,

I noticed our grass get more opaque when getting farther and it seems to be related to the baseblend. When looking to the vertex shader of the grass it seems it was intended this way. Is there an easy way to fix this or I have to modify the shader? I will look further into this tomorrow.

Our config file:

material = grass1
animationEnabled = true
colourmapchannel = 4 # r = 0 # g =1 # b = 2 # a = 3 # 4 full
density = 0.7
densitymap = ValtonValley.densitymap.png
densitymapchannel = 0 # r = 0 # g =1 # b = 2 # a = 3 # 4 full
densitymapfilter = 1 # 0 linear # 1 bilinear
fadetechnique = 2 #0 alpha #1 grow # 2 alphagrow
minheight = -1000
maxheight = 1000
maxsizewidth = 3.5
maxsizeheight = 3.5
minsizewidth = 1.5
minsizeheight = 1.5
rendertechnique = 1 #0 Quad #1 CrossQuad #2 Sprite
blendbase = true
swaydistribution = 0.5
swaylength = 0.3
swayspeed = 0.2


28-05-2008 16:38:36

It works fine for me, and the only reason I can think where it would become more opaque in the distance is when the "if (oColor.a > 1.0f)" doesn't work. Normally this is supposed to only enable the base fading where grass isn't being faded out, so the two separate alpha calculations won't conflict. It looks like the "if" is always testing true, which would overwrite the alpha fade-out behavior.

In a way this makes sense because if your card doesn't support floating point color values, or color values beyond 1.0 float or 0xFF byte, this might not work.

I tried changing the implementation to use clamp() instead of "if" to achieve the same thing, so try the SVN again and let me know if it works.

(or if you don't want to try the SVN again, just replace this:)
if (blend) vertexProgSource +=
//Blend the base of nearby grass into the terrain
" oColor.a = clamp(oColor.a, 0, 1) * 4.0f * ((dist / fadeRange) - 0.1f); \n"
" } \n";

Jules Robichaud Gagnon

28-05-2008 16:46:32

It was causing the problem on 8800 GT and 8800 GTS at least.


28-05-2008 16:56:01

Well that's strange. Those cards definitely wouldn't lack support of floating point vertex colors, although it might be due to increased strict enforcement of Vertex Shader 1.1 in 8-series cards.

Anyway, the new code should be compatible I hope.

Jules Robichaud Gagnon

28-05-2008 19:31:15

Here's a video of the problem:

I updated to the SVN version and the problem still remains.

Jules Robichaud Gagnon

28-05-2008 19:46:38

I patched the problem at putting the alpha in the texture directly instead of the shader. :lol:


29-05-2008 16:38:45

I'm not sure I understand. Does the problem still exist?

Jules Robichaud Gagnon

29-05-2008 16:53:56

I patched the problem at blending the base in the texture itself in photoshop and deactivating the "blend base".

The problem still exists if I activate the "blend base" flag.

I am compiling Ogre to the SVN version to have your samples to work. That way ill be able to recreate the problem in your samples.

Jules Robichaud Gagnon

29-05-2008 19:15:11

Try with this texture Example 4 -GrassLoader
Set the blendbase to true :



29-05-2008 20:41:06

Thanks, I'll try it out.


30-05-2008 05:22:33

What is the purpose of blend base anyway? Is it to provide 'seamless' transition from grass to ground? I think the real cure for this is to have grass color about the same with ground texture. It is hard to blend with base with just a shader, IMO.


30-05-2008 18:20:27

(Sorry it took so long for me to reply)

syedhs: It is actually not very useful, but it allows the base of the grass to fade out near the camera to help blending with the terrain when you have grass that doesn't match up well.

Anyway, I just tried adding the grass and enabling base blending, and I think I found the problem (but it seems so obvious [to me], maybe I'm missing the real problem). The reason grass near the camera disappears in my tests is because rather than fading out the bottom half of the grass image, the whole bottom half was "rejected" and disappeared because it's alpha levels were < 0.5 which caused alpha rejection to reject the pixels.

In other word, base blending does not work well with alpha-rejected textures (which I think I mentioned in the manual). The easiest fix is to disable alpha rejection and instead use alpha blended grass.

The main problem with base blending and alpha rejection is that the alpha-based pixel rejection seems to be pixel-based, rather than texture-based. There might be a way to combine smooth alpha fading with alpha-rejected textures with a shader, but I don't know how or if it's possible.

Jules Robichaud Gagnon

30-05-2008 19:09:52

Try without the alpha rejection, the problem still remains that farther we get, more opaque the grass gets.

If it is what intended, why would we want it to vary with the distance?


30-05-2008 20:08:04

The reason the base blending is set to effect close grass is that it might not look very good in the distance (like on the top of a hill).

Strange though that disabling alpha rejection doesn't solve the problem. I'll try to upload screenshots of mine (with and without alpha rejection).