Alpha saturation & disabling alpha sorting

Hello,

i implemented this : http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter01.html

rendering patches of grass using “noise dissolve” technique

if i do this :
grassMat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
grassMat.getAdditionalRenderState().setDepthTest(true);
grassMat.getAdditionalRenderState().setDepthWrite(false);
grassMat.getAdditionalRenderState().setAlphaTest(false);

then the colors add up and SATURATE to yellow

i tried may combination on the renderstate but i always get saturation localy or globaly

so i trim the color in the shader , but i should not have to do that

also i want to make sure the alpha z sorting is disabled but i dont know how to do that ?

[java]
vec4 noise=texture2D(m_NoiseMap, texCoord);
noise.x/=10;
vec4 col=texture2D(m_GrassMap, texCoord);
if(col.a>0)
{
col.xyz=/noise.x /col.xyz;
col.a=alpha
noise.x*col.a;
}
gl_FragColor = col;
[/java]

thx

You can’t disable alpha z sorting. I’m not even sure what that means. If you turn of depth write as you have then there is no sorting.

Your problem looks like a texture problem, to me… like there is no solid pixels at all.

If I read the article right you want to discard fragments below a certain alpha.

“instead of alpha blending to simulate translucency. We accomplish this by modulating the alpha channel of our grass texture with a noise texture. Then we use alpha test to eliminate pixels from rendering.”

I 'm just guessing here but shouldn’t you modulate the alpha with the noise first, and then either discard the fragment or write it with col.a = 1.0f

The good thing with this is since you don’t have any translucent pixels you don’t have to sort them to blend them correctly but can rely on depth write and the z-buffer.

That glow effect is quite cool though, almost ethereal :slight_smile:

<cite>@zarch said:</cite> That glow effect is quite cool though, almost ethereal :)

lol, yeah i guess if i wanted to do the same at first it would have taken me ages to figure it out and debug :slight_smile:

<cite>@pspeed said:</cite> You can't disable alpha z sorting. I'm not even sure what that means. If you turn of depth write as you have then there is no sorting.

Your problem looks like a texture problem, to me… like there is no solid pixels at all.

well you probably know that alpha textured objects need to be z sorted before rendering

discarding depth write and or test does not give the the desired effect :frowning:

so jmonkey must perform that test at some point

<cite>@jmaasing said:</cite> If I read the article right you want to discard fragments below a certain alpha.

“instead of alpha blending to simulate translucency. We accomplish this by modulating the alpha channel of our grass texture with a noise texture. Then we use alpha test to eliminate pixels from rendering.”

I 'm just guessing here but shouldn’t you modulate the alpha with the noise first, and then either discard the fragment or write it with col.a = 1.0f

The good thing with this is since you don’t have any translucent pixels you don’t have to sort them to blend them correctly but can rely on depth write and the z-buffer.

ill check my shader but alpha discards leads to ugly edges, so i have to manage this byt multiplication rather than with conditional branching

thx anyway :slight_smile:

i don’t understand why it saturates

i have done a really simple shader

[java]
vec4 col=texture2D(m_GrassMap, texCoord);
gl_FragColor = col;
[/java]

with these material settings

[java]
grassMat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
grassMat.getAdditionalRenderState().setDepthTest(true);
grassMat.getAdditionalRenderState().setDepthWrite(true);
grassMat.getAdditionalRenderState().setAlphaTest(false);
[/java]

and i don’t understand why it saturates, never saw that before, using simple BlendMode.Alpha (wich is not even additive)

[ also one can notice there is no z sorting when depth test is on (wich is what i want here) ]

it hink it is because i trimed the lighting shader too much,
removing ambientSum and stuff like that,
instead of simply using the unshaded shader

the only main difference is

“LightMode MultiPass”

  • so what does this actualy mean ? how does jme deal with multipass, how does it work ?

(just for curiosity)

  • also, does jme do zsorting of alpha textured object in the transparent bucket ?

maybe someone can answer these two

thx

Multipass means it draws the scene once for every light. How many lights do you have? Maybe you have more than one light and so you are getting the effect of additive blending because you aren’t doing the lighting calculations properly.

Z sorting has nothing to do with this. That only controls the order that the objects are drawn. The objects will still be drawn.

All objects (in every bucket) are z sorted.

Standard bucket is sorted front to back (to reduce overdraw)
Transparent buck is sorted back to front (to reduce transparency issues)

However it cannot sort objects that overlap. For example a lot of grass is done using a particle-like system with lots of quads inside one mesh. There is no way for jme to sort that prior to rendering - you would need to do the sorting yourself inside the particle-like system which would be a lot of calculations.

<cite>@pspeed said:</cite> Multipass means it draws the scene once for every light. How many lights do you have? Maybe you have more than one light and so you are getting the effect of additive blending because you aren't doing the lighting calculations properly.

Z sorting has nothing to do with this. That only controls the order that the objects are drawn. The objects will still be drawn.

yes, but i wanted to know about that concerning the mentioned article

<cite>@zarch said:</cite> All objects (in every bucket) are z sorted.

Standard bucket is sorted front to back (to reduce overdraw)
Transparent buck is sorted back to front (to reduce transparency issues)

However it cannot sort objects that overlap. For example a lot of grass is done using a particle-like system with lots of quads inside one mesh. There is no way for jme to sort that prior to rendering - you would need to do the sorting yourself inside the particle-like system which would be a lot of calculations.

i know but in that case, the mentioned method allows to skip the sorting pass
so mybe i need to create a render bucket that does not sort anything for the grass
but how do i do that ?

@curtisnewton said: i know but in that case, the mentioned method allows to skip the sorting pass so mybe i need to create a render bucket that does not sort anything for the grass but how do i do that ?

You can’t create custom buckets. You can set a custom comparator but I don’t know what the point would be. Sorting is not expensive enough to worry about and has nothing to do with your problem, really.

Also, anything you batch isn’t sorted within the batch. Sorting only happens per object. Your grass should be a handful of batches, really.

How many lights do you have in your scene?

<cite>@pspeed said:</cite> How many lights do you have in your scene?

it is solved, i just removed the multipass line
i did not know about the light facts

thx

<cite>@pspeed said:</cite> You can't create custom buckets. You can set a custom comparator but I don't know what the point would be. Sorting is not expensive enough to worry about and has nothing to do with your problem, really.

Also, anything you batch isn’t sorted within the batch. Sorting only happens per object. Your grass should be a handful of batches, really.

yes, indeed, stupid of me

thx anyway

here is the working result keeeewl

2 Likes

Nice :slight_smile: