Sign in to follow this  

Blending w/ Bumpmapping

This topic is 4862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites

This topic is 4862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this