TranslucentZWrite issue
by Vincent BILLET · in Torque Game Engine Advanced · 05/04/2006 (9:21 am) · 23 replies
Multiple objects with TranslucentZwrite=true materials seems to disapear. I explain : I Try to put some grass objects with translucentZwrite materials. Far grass do not render. Grass in front of camera, render correctly, but where alpha = 0 in the texture, it render terrain, sky or water colors, instead of objects behind the transparent one.
Any Idea, perhaps Brian?
Any Idea, perhaps Brian?
#2
05/04/2006 (9:27 am)
Do you mean it comes from my objects?
#3
Here is a screen shot of what is happening :

Here is my material definition
Can somebody help?
05/22/2006 (6:35 am)
It seems it isn't alpha-blended problem (I tried all available options)Here is a screen shot of what is happening :

Here is my material definition
new Material(grass2) {
baseTex[0] = "grass2";
bumpTex[0] = "grass2b";
translucent[0] = true;
translucentBlendOp = LerpAlpha;
translucentZWrite = true;
//emissive = true;
};Can somebody help?
#4
If you want this case to work you'll have to sort the grass billboards back to front.
First... why do you need your grass to write into the depth buffer?
05/22/2006 (4:48 pm)
TranslucentZWrite just makes the translucent surfaces write depth information into the zbuffer. It does not impose any sorting. So i would expect issues like this when it is enabled for non-sorted grass billboards.If you want this case to work you'll have to sort the grass billboards back to front.
First... why do you need your grass to write into the depth buffer?
#5
05/22/2006 (4:58 pm)
Alpha blending/sorting is all screwed up (terribly ugly) in TSE currently, from my experiences and from what others say, by the way.
#6
05/22/2006 (10:01 pm)
Yeah I have to confirm C2 here. I've seen it with bullet tracers and muzzle flashes on DTS objects.
#7
@Tom : Any idea from where/how to sort depth buffer? I mean where can I sort the depth buffer? I have actually no idea from where to start.
Why do I need my grass to write into the depth buffer? Hmmm... because, my grass is set on the terrain as long as the player move. fxShapeReplicator can't handle a 8192x8192 (65 M shapes). So I wrote a new component (fxEnvReplicator) which create/destroy shapes as long as the player move. I hope this answer your "why" question.
So any indication such as "take a look in depth.cpp" would be very helpfull. Thanks for the answer.
@EveryBody : does TGE have the same issues?
05/23/2006 (12:19 am)
This issue is very important for vegetation rendering, I have the same issue with trees, bushes, and so on... When you run into a full vegetation filled terrain, it's blinking...@Tom : Any idea from where/how to sort depth buffer? I mean where can I sort the depth buffer? I have actually no idea from where to start.
Why do I need my grass to write into the depth buffer? Hmmm... because, my grass is set on the terrain as long as the player move. fxShapeReplicator can't handle a 8192x8192 (65 M shapes). So I wrote a new component (fxEnvReplicator) which create/destroy shapes as long as the player move. I hope this answer your "why" question.
So any indication such as "take a look in depth.cpp" would be very helpfull. Thanks for the answer.
@EveryBody : does TGE have the same issues?
#8
05/23/2006 (4:34 am)
We have the same issue in Air Ace with improper alpha sorting - one of the things we hoped was fixed in MS3. TGE doesnt have this issue.
#9
05/24/2006 (3:20 am)
I use MS3 and I still have this issue. So perhaps GG staff could answer this question.
#10
05/24/2006 (4:11 am)
Thomas said he hoped the issue would be fixed, not that it necessarily was.
#11
05/25/2006 (2:57 am)
It wasnt fixed in MS3 - if anyone fixes it, I'll personally buy a beer for you at IGC
#13
Does Anybody have an idea?
Edit : Or perhaps GG staff want to make a MS3.1 release to solve this horrible issue.
05/25/2006 (6:16 am)
Nice example C2. Still no answer from GG Staff. And still don't know where to seek to win a beer :p. I tried some stuff in materialinstance.cpp. sceneGraph.cpp. sceneState.cpp. with no success. Does Anybody have an idea?
Edit : Or perhaps GG staff want to make a MS3.1 release to solve this horrible issue.
#14
05/25/2006 (1:54 pm)
There are still quite a few optimizations going on, and I'll make sure to point Brian at this thread to get the issue analysed.
#15
05/25/2006 (2:08 pm)
Thanks - it would help with the beauty of TSE.
#16
OK, for the record, this type of grass rendering should not (theoretically) require z sorting with an alpha test on and zWrite enabled. From the screenshot though, it looks like you've got parts of the texture nearly black, but not quite black (color 0) and so those bits are writing to the zbuffer, but not the color buffer. You could go into MatInstance::setupPass() and crank up the GFX->setAlphaRef() to a higher value. It looks like mipmapping is also adding to (or totally is) the problem as the lower mips will blend pixels together raising the alpha values above the alphatest threshold. In fact, looking at you texture, that's almost certainly the problem. The leaves are just a few pixels apart and they'll just blend together once you get 1 or 2 mip levels out.
If the texture must be like it is, then z-sorting these translucent polys will pretty much solve the problem. The new batching system will do this for you. Hopefully you'll be able to test this within the next couple weeks. I'll have more info soon, it's been going very well.
05/25/2006 (5:20 pm)
Hey guys, sorry coming late to the party. I'm almost ready to check in the batching changes which should fix a lot of these problems. At the very least it will give you more control over alpha sorting so you can tune it for the needs of your game.OK, for the record, this type of grass rendering should not (theoretically) require z sorting with an alpha test on and zWrite enabled. From the screenshot though, it looks like you've got parts of the texture nearly black, but not quite black (color 0) and so those bits are writing to the zbuffer, but not the color buffer. You could go into MatInstance::setupPass() and crank up the GFX->setAlphaRef() to a higher value. It looks like mipmapping is also adding to (or totally is) the problem as the lower mips will blend pixels together raising the alpha values above the alphatest threshold. In fact, looking at you texture, that's almost certainly the problem. The leaves are just a few pixels apart and they'll just blend together once you get 1 or 2 mip levels out.
If the texture must be like it is, then z-sorting these translucent polys will pretty much solve the problem. The new batching system will do this for you. Hopefully you'll be able to test this within the next couple weeks. I'll have more info soon, it's been going very well.
#17
05/25/2006 (5:23 pm)
@C2 - the problem that you are showing should be taken care of with the new changes. If not, email me and we'll see if we can get that test case going here in the lab so it's properly fixed.
#18
05/25/2006 (5:40 pm)
I truly appreciate it.
#19
I made the following changes to make it work.
In material.h @ line 143 (just after translucentZWrite declaration) I add :
in material.cpp @ line 68 (just after translucentZWrite init) I add :
in material.cpp @ line 119 (just after translucentZWrite field declaration) I add :
in matInstance.cpp @ line 519 I replace GFX->setAlphaRef(1); with :
in customMaterial.cpp @ line 460 I replace GFX->setAlphaRef(1); with
And finaly I update my material definition (material.cs) like this :
And now it works very well. Thank you again.
Edit : I Hope the naming convention is good for you.
05/26/2006 (2:14 am)
Thank you Brian ! It works !I made the following changes to make it work.
In material.h @ line 143 (just after translucentZWrite declaration) I add :
U8 translucentAlphaRef;
in material.cpp @ line 68 (just after translucentZWrite init) I add :
translucentAlphaRef = 1;
in material.cpp @ line 119 (just after translucentZWrite field declaration) I add :
addField("translucentAlphaRef", TypeS32, Offset(translucentAlphaRef, Material));in matInstance.cpp @ line 519 I replace GFX->setAlphaRef(1); with :
GFX->setAlphaRef( mMaterial->translucentAlphaRef );
in customMaterial.cpp @ line 460 I replace GFX->setAlphaRef(1); with
GFX->setAlphaRef( translucentAlphaRef );
And finaly I update my material definition (material.cs) like this :
new Material(grass2) {
baseTex[0] = "grass2";
bumpTex[0] = "grass2b";
translucent[0] = true;
translucentBlendOp = LerpAlpha;
translucentZWrite = true;
[B]translucentAlphaRef = 240;[/B]
};And now it works very well. Thank you again.
Edit : I Hope the naming convention is good for you.
#20
05/26/2006 (6:47 pm)
For the record, Vincent Billet's changes do not solve muzzle flare/other alpha issues with the square artifacts appearing and such, only the grass rendering code her had trouble with.
Torque Owner William Todd Scott