Issue with particle alpha on top of a fully transparent RTT

Problems building or running the engine, queries about how to use features etc.
Post Reply
inzero
Kobold
Posts: 33
Joined: Sun Dec 19, 2010 9:55 am

Issue with particle alpha on top of a fully transparent RTT

Post by inzero »

Hey all, I've got a question about alpha blending with regards to RTT.

You see, I'm developing an app that is meant to be directly captured by live streaming software (OBS, XSplit, etc.) to overlay 3D characters and effects on top of a live stream broadcast with sites like Twitch. The main feature here is that the rendering is done on RTT with a background color of 0,0,0,0 (fully transparent), so individual objects in the world can be rendered on top of the user's broadcasts without covering everything up with a background.

It's been working great, but I've finally decided to work in some particle effects with blending. I've got a simple green blob particle effect using additive blending, but there's a problem - if the particles aren't being rendered in front of something else, the black boxes around them aren't being ignored in the blending like they should. If the effect is in front of something, it looks perfectly fine.

Here's an example video:
[youtube]rVOXbdUYdhk[/youtube]

As you can see, the particles look nice and smooth while in front of the mask, but they look ugly once they reach the background.

I'm creating my RTT in Mogre 1.7.1 like this:

Code: Select all

// RTT and viewport
rttTexPtr = TextureManager.Singleton.CreateManual(StringHelp.MakeUniqueString("RttTex"), ResourceGroupManager.AUTODETECT_RESOURCE_GROUP_NAME, Mogre.TextureType.TEX_TYPE_2D, 1280, 720, 0, PixelFormat.PF_A8B8G8R8, (int)Mogre.TextureUsage.TU_RENDERTARGET, null, false, 4);

rttTex = rttTexPtr.GetBuffer().GetRenderTarget();
mViewport = rttTex.AddViewport(mCamera);
mViewport.SetClearEveryFrame(true);
mViewport.BackgroundColour = new ColourValue(0.0f, 0.0f, 0.0f, 0.0f);
The material script for the particles:

Code: Select all

material Particles/Flare
{
	technique
	{
		pass
		{
			lighting off
			scene_blend add
			depth_write off

			texture_unit
			{
				texture flare.png
			}
		}
	}
}
And the particle system itself:

Code: Select all

particle_system Test
{
	material Particles/Flare
	particle_width 6
	particle_height 6
	cull_each false
	quota 100
	billboard_type point
	
	emitter Ellipsoid
	{
		angle 30
		emission_rate 15
		time_to_live_min 8
		time_to_live_max 10
		direction 0 1 0
		velocity 1.0
		colour 0 1 0
		width 5
		height 5
		depth 5
	}
	
	affector ColourFader
	{
		alpha -0.2
	}
}
It seems like a simple problem to solve, but I think I may be in a tricky situation here because of my fully transparent background requirement. I can't render on top of any kind of visible background, even if it's black, because I don't have blending options in the capture software for this type of situation.

One thing I tried was to use scene_blend alpha_blend in the material instead, using a transparent flare png. That solved the problem of looking strange while not in front of anything, but introduced a new problem where any objects behind the particles had their alpha set to the particles' alpha, thus cutting holes in them.

Any tips?
inzero
Kobold
Posts: 33
Joined: Sun Dec 19, 2010 9:55 am

Re: Issue with particle alpha on top of a fully transparent

Post by inzero »

Well I think I mostly solved my problem.

I tried using a texture with an alpha channel, and switched my scene blending to "src_alpha one".

The result:

[youtube]l1e8vUl7DEM[/youtube]

The particles are darker than I'd like when nothing is behind them, because they have nothing to mix with - which I'll have to deal with because there's no way for me to share the capture software's current texture with Ogre before rendering on top of it. It'll do for now!
Post Reply