Game Development Community

Transparencies on interiors and trees

by Giorgio Zanetti ( JoZ ) · in Torque Game Engine Advanced · 05/31/2007 (7:24 am) · 12 replies

Hi there...
I'm trying (with no result ) to have on an interiors a window with transparencies and have the trees outside showing trough...

I can get to have the windows of course, but the trees outside only show if the behind the full transparent part of the window, if there is a part of the window with partial transp. the trees don't show trough it... or for better saying... only show the part of the trees textured with material without transp. so the leaves part don't render...

lh5.google.com/image/gz77it/Rl7d189TmMI/AAAAAAAAAHA/mLix8I1FTMc/s800/screenshot_006-00001.jpg
here the material definitions...

WINDOW material:

new Material(_Window)
{
baseTex[0] = "_Window";
emissive[0] = true;
translucent = true;
translucentBlendOp = LerpAlpha;
translucentZWrite = true;
alphaTest = true; // default value would be true
alphaRef = 100; // anything below this number is not visible and is not written to zbuffer
};

new Material(_border)
{
baseTex[0] = "_border";
};


TREE Material:

new Material(trunk)
{
baseTex[0] = "trunk";
};
new Material(leaves)
{
baseTex[0] = "leaves";
translucent = true;
translucentBlendOp = LerpAlpha;
translucentZWrite = true;
alphaRef = 155; // anything below this number is not visible and is not written to zbuffer
};


Anyone know how to get this working?

JoZ

#1
06/11/2007 (3:26 pm)
Remove the emissive, that should solve it. (just from assumption as emissive should be of type glow which is rendered before translucent so the tree leaves get rendered after the window and thus can not show through it)

Problem is the rendering order.

You can experiment with it yourself in renderInstance/renderInstMgr.h, enum RenderBinTypes
#2
06/12/2007 (12:05 pm)
I've seen lots of people throw that emissive flag in their Materials and I'm not sure why. The docs say it is to be used for Materials that "appear to emit light". I suppose if you have a glowing window it would make sense...
#3
06/12/2007 (1:30 pm)
The emissive flag should really be called the "dontApplyLightingOrShading" flag. You usually use it on objects that should be full bright and unaffected by lighting... think the texture on a lit lightbulb.
#4
06/12/2007 (2:34 pm)
That's what I thought, thanks for the info Tom. I always thought it suspicious when people were saying "I set emissive to true to get it to work."
#5
06/12/2007 (3:15 pm)
Ok guys, tried and without the emissive flag now it appear completely transparent...
It doesn't care about the alpha channel! :(
And at some point (I cannot say how...) I've got the texture to be rendered full transparent on one side and full opaque on the other with no care of the alpha channel

Further that I tried changing the texture to see if there is some problem in the texture (no thinking that anyway...) ... And now? I set the basetex referencing to another texture but hte "no material" texture appear, the only way is to rename the original texture and rename the second one with the name of the first...
It seems like it takes the basetex reference in some sort of cache... Of course I've quit TGEA and relaunched but no result, now I wanna trying rebooting the pc...

I'm thinking that there is some serious bug with the implementation made by GG...

Anyone at GG would give some feedback please???

Tnx, JoZ.
#6
06/12/2007 (3:41 pm)
Well i tried every which way but loose on the sharp tree testing alphas and i cannot get the blended alpha to work without the halo,in fact,it look by far best with the emissive,however now the whole tree flashes.
i even maxed out the alpha with contrast in photoshop and resaved as super png,no difference,and tbh,we shouldnt have to scratch nice blending alphas,the tgea is meant to be advanced is it not? so why can we not have such a simple thing as correct alphas.

the only way i can see this working is to totally remake models and apply a "heirarchy" to the alpha channel textures before export to dts,but would thi s work????
even if one tree might work ok,dumping lots of foliage in there will undoubtably cause clipping especially if you place trees on alpha foliage replications.
#7
06/12/2007 (4:07 pm)
Ok, rebooted and no result...

Tried reverting back to the material definitions as posted here on 31 may but no result, still getting the "no material" texture...
Looking at the console this is what I see:

...
material unmapped: _WINDOW
...

I really don't know why, all was ok before...

This is my material definition:

//*****************************************************************************
// materials
//*****************************************************************************

new Material(_WINDOW)
{
baseTex[0] = "_Win";
emissive[0] = true;
translucent = true;
translucentBlendOp = LerpAlpha;
translucentZWrite = true;
alphaTest = true; // default value would be true
alphaRef = 100; // anything below this number is not visible and is not written to zbuffer
};

The file _Win exist for sure...
#8
06/12/2007 (7:17 pm)
@Joz - Your issue is that interiors always render before transparent objects. If you want a window that sorts properly in your DIF... make the window itself out of a DTS and and stick it in the hole.

@Jojimbo - Every game engine that uses alpha blending has sorting issues.... developers are just smart and find ways around them or to minimize the effect. The halos your seeing are normal when triangles are not sorted back to front and have zwriting enabled. Check GTA 3... a game that has sold over 13 million copies... has halos around tree leaf textures.

The trick with trees is not to use alpha blending. Use alpha test. SpeedTree, which has arguably the best looking trees out there, does not use alpha blending at all. Poof... your sorting issues have gone away!
#9
06/13/2007 (12:45 am)
I work with Joz for the same project and now we see this :

if I use translucentZWrite = true; I don't see smoke :

nbn.djhellclub.com/images/screenshoots/translucent_002.jpg
if I comment out translucentZWrite = true; I see smoke :

nbn.djhellclub.com/images/screenshoots/translucent_001.jpg
nbn.djhellclub.com/images/screenshoots/translucent_000.jpg
While the presence on glass is possibile if I use alphaRef = 40; up this I don't see glass !!!

nbn.djhellclub.com/images/screenshoots/translucent_004.jpg
What do you think about this situation ???
#10
06/13/2007 (12:49 am)
Kk tom,i do realize this is not just a tgea thing,its industry ,however recents tests on normal maps really give trees a nice effect ;) think ill go in that direction
however why is it these blends work perfectly in tge and not in tgea?

note: just commented out "translucentZWrite = true;" as Andrea did,and the blending works perfectly???
#11
06/13/2007 (9:17 am)
@Jojimbo - The blends do not work perfectly in TGE either.

You need to understand a fundamental issue in 3d rendering... things close to the camera that write to the zbuffer, keep things that are distant from the camera and rendered after it to not render. This is true regardless if it is transparent or not.

The "translucentZWrite" turns on writing to the zbuffer for a translucent object... in this case your window. You cannot see things rendered *after* the window is rendered because the zbuffer keeps them from rendering.

In your case you want translucentZWrite off or go with the DTS for windows concept, so that the DTS can be properly sorted against other translucent objects.
#12
06/13/2007 (9:36 am)
@Andrea - alphaRef is used for alpha testing. What it means is "don't draw pixels with an alpha value less than 40". Your glass has an alpha transparency level of 39.

Which brings up another technique to try... stipple alpha.

www.sgi.com/products/software/opengl/examples/glut/examples/images/screendoor.jpg
Create the window texture to have a checkerboard of alpha below 40 and above 40. Then set your alphaRef to 40. What will happen is every other pixel will be transparent. If the pattern is repeated tightly enough it looks semi-transparent when it is not.

Quake 2 used this as a fallback when using the software renderer. Newer tech like iD's next engine and Bootstrap's engine use stipple alpha in a second pass then blend the results into the final frame for perfect no-sort alpha transparency. But this is a rather advanced technique that only people well versed in TGEA and shader development should aim for.