Game Development Community

Cast Shadows from Alpha Map (i.e. Leaves)

by Jordan Parsons · in Torque 3D Professional · 08/06/2009 (4:46 pm) · 16 replies

Just curious as to what the best process would be to get shadows to be cast to the ground from an alpha map in T3D. I have my tree trunk and some flat planes being used to hold the alpha map to simulate leaves (nothing out of the ordinary), but every time I load my model into Torque, I don't see any shadows being cast down except for the tree trunk.

I have Milkshape3D and 3DS Max, so if you have a solution for either of these software solutions, it would be helpful.

#1
08/06/2009 (5:05 pm)
Try a seperate texture/material for translucent objects/textures.
the old translucent material link
#2
08/06/2009 (5:14 pm)
In B4, shadows are not supported when you have alpha blending turned on. You have to turn blending off, turn alpha testing on, and then adjust the alpha test value. I'm hoping this is addressed before they release V1.
#3
08/06/2009 (5:19 pm)
@Steve - Yeah, I have a separate texture for the translucency portion of my object. Still a no-go :( The leaves are showing perfectly, but there just aren't any shadows being cast for the leaves portion of my model.

@Jaimi - That explains it. It's unfortunate, but it does explain it. I'll play with the settings a bit when I get home. Thanks!
#4
08/06/2009 (5:22 pm)
I'm playing around with this. In theory, we should be able to have both alpha blending and alpha test w/zwrite by using two passes. I'm not sure if the material system directly supports this.

Note: the issue is that the alpha blended polygons don't write to the zbuffer, and that's needed for the shadows.


edit: Scratch that, you can't change the alpha blending value per pass.
#5
08/06/2009 (10:12 pm)
I'll give this out to the community for free. It's one of the trees that's not working properly with the shading...so if you can get it to work, it's yours. Well, it's yours if you can't either, but it'd be appreciated if you could get it to work and post it back up with whatever changes you made.

Have fun!

www.gpinteractive.com/free_models/irishTree_twisted1.zip
#6
08/06/2009 (11:05 pm)
I dont see what the problem is,

img38.imageshack.us/img38/8236/screenshot00700000.jpg
img38.imageshack.us/img38/1963/screenshot00700001.jpg
img34.imageshack.us/img34/2228/screenshot00700002.jpg

Here are the files back, in max format plus a dts plus the textures plus a materials.cs file
#7
08/07/2009 (12:37 am)
omg...must have been my settings...arg. Thanks deep.
#8
08/07/2009 (6:02 am)
Alpha blended objects cannot cast shadows. Only alpha tested ones can. This is the nature of shadowmapping, which is depth based, and it's well known that depth and blending never do well together.
#9
08/07/2009 (6:14 am)
What would be cool is if we could draw it in two passes - the first pass with LerpAlpha, and the second pass with alpha test. Of course it would be even cooler, if we could change this based on the LOD, so we can get rid of the LerpAlpha layer as it got farther away. Some trees work fine with just alpha test (as shown in the demo), but if you try to use AlphaTest only with some of them (like the dead tree with no leaves), it looks absolutely terrible.
#10
08/07/2009 (6:39 am)
@Jaimi: you don't need two passes. The safest way would having a material draw as alpha-blended during the render pass and draw as alpha-tested during the shadow pass. It could work.
#11
08/07/2009 (7:01 am)
Yeah, that's true.

edit: Though I would be happy with the "alpha test during shadow pass" change, I still would like the other idea better, because it solves a problem that arises from using LerpAlpha -- that is, the sky bleedthrough that can happen at the very edges of the alpha blended item giving it the "halo" effect.
#12
08/07/2009 (2:40 pm)
Jami,
What you are talking about is not possible with DX9 hardware.

You'll have to wait for DX10+ for depth peeling or a Larabee solution.
#13
08/07/2009 (3:03 pm)
@Pat: I think you're misunderstanding what I was saying - or maybe just overestimating my knowledge. Drawing a ztest pass with zwrite followed by a lerpalpha pass should be doable, it's how we did it in the old days on dx7/8 cards. I'm not sure what the difficulties would be in doing it all in one shader, I really need to get back up to speed.

Note: Whether this solves the issue or not, I have no clue. It should cast shadows and receive them, but it's possible that there would be other issues that arise - like the lerped parts possible glowing in the shade.
#14
08/07/2009 (3:06 pm)
I think as a specific solution it could work, but as a general solution, I think there would be a lot of visual artifacts around the edges, with the potential for there to be really ugly artifacts, where the blended texture was lerping with the back-buffer clear color.
#15
08/07/2009 (3:09 pm)
Oops. You were answering as I was revising. The solution was significantly better than "only" lerped data (it got rid of the glowing halos) but as noted above I'm not sure how it would react with the shadowing in advanced lighting. probably not well would be my guess.
#16
08/07/2009 (3:37 pm)
Yeah, and that is kind of the crux of it. I think there is potential in the solution, but a lot of materials things in Torque need to be the general-purpose solution, not the "coolest possible" solution.

I would like to stress, though, that this is possibly a cool and workable effect, and we have put a lot of work into making an extensible and flexible render system so that people can go doing non-stock modifications.