Doom3world

The world is yours! Doom 3 - Quake 4 - ET:QW - Prey - Rage
It is currently Mon May 20, 2013 5:31 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Rendering transparent textures like add perfectly
PostPosted: Tue Feb 22, 2011 6:49 am 
Offline
picked up 200 ammo

Joined: Thu Jan 28, 2010 1:17 am
Posts: 220
Hello all. After looking at the explicit OpenGL blend functions at modwiki and experimenting with them, I found 2 useful blend methods that may come in handy. And just to make sure, I did a search but I didn't find anything particle related.

Most of you probably know the two main blend methods for particles, blend (gl_src_alpha, gl_one_minus_src_alpha) and add (gl_one, gl_one) as they are really the only two. For the blend method blend to work properly, you need a transparent texture with an alpha channel, and for add to work you need a texture with a black background.

However, with the explicit blend method gl_src_alpha, gl_one (add_alpha), you can use a transparent texture and render it exactly the way add does, by adding color value over what it is being rendered over.

The first advantage with this method is that you can already use an existing texture with a transparent background without having to create another version with a black background, so you can make extra use of that texture while saving space and reducing clutter in the particle folder. The other advantage is that while it renders additionally, it responds to alpha masking, so you can fade it in or out either by color value or by alpha (or both).

The one main problem I had with the blend method add was that if you wanted it to fade in and out properly and smoothly, the fade color had to be set to 0 0 0 0 (with alpha being irrelevant), so it was strictly fading to or from any given vertex color given (or entity color). With this method, you can have a particle spawn for example as green and fade out as red, or whatever color you wish while fading it in and out perfectly via the alpha channel. So like, 1 1 1 1 to 1 1 1 0.

So far, it does everything add does and more without any odd effects. I say that because there were other methods I found that worked but had issues so they shouldn't really be used, although there is another working method...

If you want another blend method to use, here is something else you may like. gl_one, gl_one_minus_src_color (add_hue?), which renders like add but looks somewhat opaque still, and the color is lightly saturated, creating a washed out look. You could say it gives it a hue instead of a color really unless you pick a color that is heavily saturated. It requires a texture with a black background, and does not respond to alpha masking, so it is basically like another version of add. Try it if you are curious. It works best with a cloudy texture, such as textures/particles/dustcloud.

All this was done trying to find a way to have an inverse of add and somehow subtract color value, just for the sake of curiosity. I was not successful haha.

So yea, if gl_src_alpha, gl_one is what I think it is capable of, the blend add method is actually inferior when applied to particles. Use that instead and don't make two versions of one texture for the sake of add, unless you want to use gl_one, gl_one_minus_src_color, the you will need it. Add is still perfectly fine for other textures like for models and such, just in defense of my critique, though this method may work just as well.

I hope this was insightful and helpful, and not a repeat of something ya'll already knew. Take care!

_________________
Doom 3 editor noob. Doom 3 - Day 75 [HD]
Particle editor/editing | Phrozo Weapons Mod


Top
 Profile E-mail  
 
 Post subject: Re: Rendering transparent textures like add perfectly
PostPosted: Tue Mar 22, 2011 3:46 am 
Offline
picked up a pistol
User avatar

Joined: Fri Feb 18, 2011 12:16 am
Posts: 70
Location: Deltona, FL
:D

_________________
Download My HellFireBallGun Mod!
Download My Tutorial Pack
Go To My Website it has Doom 3 Tutorials and Resources! D3 Resources&TutsWebsite is down! I have had no computer so I wasn't on it and they got rid of it!


Top
 Profile E-mail  
 
 Post subject: Re: Rendering transparent textures like add perfectly
PostPosted: Tue Mar 22, 2011 4:44 am 
Offline
picked up the chaingun

Joined: Wed Mar 05, 2008 6:43 pm
Posts: 191
Oooh, I just was dinking around with this stuff the other day. #1 is actually the concept of premultiplied alpha and is actually pretty expressive. Another interesting one is mod2x, i.e. src_color, dst_color. This is a slightly more flexible version of the modulate blend mode that lets you brighten things slightly, but you need to reformulate your source image to compensate, using a value of 0.5 to denote transparent regions instead of 1.0 or 0. HL2 uses this for decals and it's how they can have the 'shine' on the metal bullet hole.

EDIT: De-munged my link.


Top
 Profile E-mail  
 
 Post subject: Re: Rendering transparent textures like add perfectly
PostPosted: Wed Mar 23, 2011 3:23 am 
Offline
picked up 75 health

Joined: Sun Mar 21, 2010 3:49 pm
Posts: 85
I spent some time playing with this a while back.

In order for me to get a fully opaque but 'full' alpha ramp* I found the best way was to use a 32bit TGA with alpha, before saving it I'd enable a level adjustment mask to drop the rgba in half, i.e the image would be dim and the alpha would be a max of 127. In the material file I could then add the texture onto itself to get a 'full' version. This is obviously somewhat lossy, but I find it quite acceptable. At the end of it, you're left with half the precission but you can have a full alpha ramp instead of the 50% that 'translucent' gives you or the fullbright blends.

Code:
    {
        blend  diffusemap
        map add(textures/trees/leaf1, textures/trees/leaf1)
        alphaTest 0.9 // Use this to limit the fringe noise and details to avoid aliased speckles
    }
    {
        IgnoreAlphaTest
        blend  GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
        map add(textures/trees/leaf1, textures/trees/leaf1)
        rgb 0.1 //or whatever your ambient light seems to be, could use a param to make it easier.
    }


The following horrid images show the result, I cant find the 'finished' versions of the textures, but I think they still show the general idea, The alpha tested areas react nicely to light, the edge blends just stop it looking horribly aliased. But yeah, these are really terrible shots :)

Tree - Alpha test
Tree - Alpha test+blend

Vine - Alpha test
Vine - Alpha test+blend // the blend overlay should have been lighter v0v


Top
 Profile E-mail  
 
 Post subject: Re: Rendering transparent textures like add perfectly
PostPosted: Wed Mar 23, 2011 11:14 am 
Offline
fired 300 rounds
User avatar

Joined: Sun Jul 13, 2008 1:24 pm
Posts: 392
A few notes:

1) Thats not lit. Its just "darker". That means that this is a totally per scene implementation that wont ever work in "all scenes" unless the map you use it on is pitch black all over anyway.

2) It wont be changed by dlights. Its NOT lit. So you can't fire near it or anything.

3) tIt wont be changed by multiple lights in the same scene.

4) Possibly, it wont even work with fog, which will be a huge issue. Either way, as you can see the drawing order issues make it digusting to look at for the most part.

5) Heavily fill rate bound, works much worse than alpha testing, even if the edges are softer. Simply add in alpha to coverage, best you will ever manage with this lighting for a while.

6) No normals... Because its not lit. Making the whole thing a bit pointless.

Now, don't get me wrong, its a nice "hack" but thats all it is, a hack that doesn't work in 99% of the cases unless its set up for that particular area. You could possibly tweak the surface as an inlined entity in the bsp using seperate RGB commands, but again, its not real time... Its a hack. So the fact its not lit, doubled with the fact its got some really ugly drawing order issues (which of course it will) means that its pretty much next to useless for anybody to seriously use on any kind of visual level.

Just add A2C, and be done with it.

_________________
Lead Designer, Team Blur Games
Visit The [TBG] User Forums


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group