Blending w/ Bumpmapping

Started by
3 comments, last by imajor 19 years, 8 months ago
So in the engine I'm working with, lit surfaces are currently additive (i.e. blend mode one one in ogl). Now imagine if you will a simple bumpmapped tree being lit by a single light source. The bark of the tree itself would be no problem, but the leafs would need to be transparent. Now using alpha testing would work fine, but make the edges very harsh and unpleasent looking. What I'm trying to do is find a solution where I could use normal blending (srcalpha, invsrcalpha) to allow for soft-edged alpha blending on lit, bumpmapped w/ specular surfaces. Unfortunetly since lights are additive, that proposition is not so straight forward. Does anyone have any hints or suggestions onto how this could be accomplished (a special blend mode perhaps or shader hacks, something like multiplying color times alpha)? Thanks!
"Artificial Intelligence: the art of making computers that behave like the ones in movies."www.CodeFortress.com
Advertisement
Quote:Original post by Dirge
Unfortunetly since lights are additive, that proposition is not so straight forward.

How about finding out how many lights it's being lit by (and thus how many times it'll be drawn) and setting the total transparency on each pass to 1/numLights? I don't know how physically accurate that is but it should look good enough.

Having said that I think you'd be better off with just alpha testing (no depth sorting needed then either).
For transparent surfaces set srcblend to srcalpha, and set destblend to one.
If it's just the edges of leaves that need smoothing then perhaps (i) alpha-testing(alpha==1) on, alpha blending off, depth test/writes on followed by (ii) alpha-blending(src/invsrc) on, alpha-test(alpha<1) on, depth test on, depth writes off. The smoothed edges might be in wrong z-order but perhaps not noticeable. On low-spec machines can just turn off part (ii) and set alpha-ref to 0.5 in part (i) like OrangyTang suggests. Perhaps using imajor's blend values for part (ii) if src/invsrc has z-ordering artefacts.
If you have to render a transparent surface in multipass, let assume that the final color of the surface is D and the partial results are A B and C. So for the first pass you get A, on the second pass you get B and finally you get C. So D=A+B+C. If you would be able to render in one pass, the final result in the rendertarget would be R*invsrcalpha+D*srcalpha. For the first pass use srcalha for srcblend and invsrcalpha for destblend, you get R*invsrcalpha+A*srcalpha. For the other passes use srcalpha for srcblend and use one for destblend, so finally you get R*invsrcalpha+A*srcalpha+B*srcalpha+C*srcalpha=R*invsrcalpha+(A+B+C)*srcalpha=R*invsrcalpha+D*srcalpha and this is what you want to get. (I guess)

This topic is closed to new replies.

Advertisement