Game Development Community

[Beta 3 Bug] No shadows from mesh with LerpAlpha texture

by Jaimi McEntire · in Torque 3D Professional · 07/04/2009 (9:13 pm) · 10 replies

This causes trees with branches with materials that have LerpAlpha turned on (such as oak2.dts) to cast incorrect shadows (ie, the branches don't cast a shadow, but the trunk does). This ruins the great effect of the shadows. Unfortunately, the z-test trick that works good on some trees works terrible on others (like oak2).
Suggestion: Support LerpAlpha materials with shadows. If needed in shadow pass, could be possible to use ztest.

#1
07/05/2009 (5:23 am)
It was reported already, I think. Right now there's a bug: if you select lerpAlpha, the Z-write flag stops working and they won't cast shadows. Currently, you need to disable blending completely (transparent blend "none") if you want shadows.
#2
07/05/2009 (8:26 am)
@Manoel - thanks, I didn't see the previous bug report.
#3
07/05/2009 (8:58 am)
Pat Wilson (of GG) said that translucency is still being worked on and will look much better at release.
#4
07/05/2009 (1:11 pm)
Ah yes they will look better but they will still not cast shadows. I was referring to lighting only (shadows are different, even though that seems counter-intuitive).

With DX9 level of technology, it is not feasable to have more-than-one value per-pixel for depth. Why does this matter? Well when you are drawing a shadow map, you are drawing the geometry of the level, from the perspective of the light. You are then recording the depth (distance from the light) for each pixel in the shadow map. What do you do if it's a translucent pixel? Well you would need to have more values...the values of the object(s) behind it, and some sort of "translucency" variable which recorded the 'intensity' of the shadow cast by the translucent geometry.

So unfortunately this is not a bug, this is a limitation of shadow maps.
#5
07/05/2009 (1:13 pm)
@Pat - but would it not be possible to render the tree with lerpalpha for the scene, but then when you rerender it for the shadowpass use ztest? Or is there not a render pass for the shadowmaps?
I don't think we expect partial shadows, but for things like oak2.dts (a barren tree) which look terrible with alpha none and ztest.
#6
07/05/2009 (2:28 pm)
Jaimi,

For sure, and you can use alpha test to render the shadow, and then lerp-alpha to blend it (I'd set the alpha test value to slightly less than the edge, so that way you get a nice blured edge, not sharp)

I am not _exactly_ sure how to do what I just said in Torque as it stands in Beta 3, but the concept is solid, and possible. Torque3D uses these material hooks, and one of them is a shadow material hook. This allows the material used for shadow rendering to be different (in any way you chose) from the material used to render the diffuse pass.

Again, I don't think these are accessible to the scripting system, or materials right now, but it is possible with some code work, and I think it would be good functionality.
#7
07/05/2009 (2:47 pm)
@Jami

I have been thinking about doing that... if i can find some time i'll see if i can setup a test for it.

There will be artifacts... like tbe lerp parts that fall outside of the alpha test range will be lit by the background geometry... but depending on your usage it may be acceptable.
#8
07/05/2009 (3:42 pm)
Not really contributing just mentioning it ...

I've always found using Lerp messes the Z sorting up of my trees, branches at the far side show through the ones at the nearest side.

Trees in CoD always had an invisible shadow mesh for foliage as they didn't cast shadows, I'd stick a tree model in and then the tree_shadow model over it. Always wondered why they couldn't get it to just cast a shadow from the transparent texture, I think Pat's explained that though.
#9
07/06/2009 (2:17 am)
@Steve - Thats a neat trick really... using a special shadow only model for casting the shadows.

The only issue is that the transparent bits of the tree wouldn't pick up any self shadowing which is a large part of tree lighting.

Still... cool trick.
#10
07/06/2009 (9:09 am)
Wouldn't it be much simpler to simply check the translucent z-write and alpha-testing flags and ignore the blending when drawing shadows? Anyone doing alpha-branches already is advised to use z-writes and alpha test anyway, to minimize sorting errors. The effect is just smooth foliage edges due to the additional blending. I don't even think they would mess up with the scene at all, since they'd still not render to the prepass.