Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

2D glowing line effect?

Started by blueshogun96 Oct 24, 2009 at 3:24 AM 3 replies 3.5k views
Original Post
blueshogun96
blueshogun96
I'm working on a 2D game with glowing lines similar to what you'd see on a modern clone of Geometry Wars (like this). How do they normally do this effect? I already have my basic rendering code set up to render 2D geometry and it's working fine.

// Vertex structure
struct VERTEX
{
	D3DXVECTOR4 vecPosition;
	DWORD dwColour;

	static DWORD FVF;
};

DWORD VERTEX::FVF = ( D3DFVF_XYZRHW | D3DFVF_DIFFUSE );

...

lpD3DDevice->DrawPrimitiveUP(...);



I'm quite sure you'll need to use shaders for such an effect, so how would you write vertex shaders for 2D shapes? I'm using assembly shaders for my project (or at least I was), but I do have HLSL support too. This is my HLSL passthrough shader which I can't get to work for the above code. 3D is fine though.

float4x4 mtxWVP : register (c0);	// Put the WVP matrix into constant register c0-3
					// This constant is set with the Direct3D API
					// IDirect3DDevice9::SetVertexShaderConstantF

// Input vertex structure
struct VPIn
{
	float4 ObjectPosition	: POSITION;
	float4 Colour		: COLOR;	
};

// Output vertex structure
struct VPOut
{
	float4 ProjectedPosition : POSITION;
	float4 Colour		 : COLOR;
};


// Vertex shader program entry point
VPOut main( VPIn In )
{
	VPOut Out;
	Out.ProjectedPosition = mul( mtxWVP, In.ObjectPosition );	// Transform the vertex into
          								// projected space
	Out.Colour = In.Colour;			// Passthrough vertex colour
	
	return Out;				// Return transformed vertex
}



How would I change this to work for 2D rendering? Should I be using an orthographic projection instead to calculate the WVP matrix? Would the D3DFVF_XYZRHW flag be a problem? Or should I just use an dynamic vertex buffer instead? Any ideas? Thanks.
MJP
MJP
Probably the easiest way to do it would be a standard bloom/glow post-process. Render the scene to a render target texture, (optionally) downscale it to 1/4 or 1/16 size, threshold, apply a Gaussian blur, scale back to full size, then add it to the original scene texture and output it to the backbuffer. Not really trivial if you've never used shaders or render targets, but this is typically how these things are done.
leet bix
leet bix
If you're unsure of how to program these shaders, all of the above a typically used in an HDR section, so there's code that may help your understanding in this tutorial: http://www.gamedev.net/columns/hardcore/hdrrendering/
blueshogun96
blueshogun96
Quote:
Original post by leet bix
If you're unsure of how to program these shaders, all of the above a typically used in an HDR section, so there's code that may help your understanding in this tutorial: http://www.gamedev.net/columns/hardcore/hdrrendering/


Thanks for the link, but when I run the code on my laptop (which is all I have now), absolutely nothing renders. I guess the code is broken on my drivers (NVIDIA GeForce 8400GS M 128MB) with the latest forceware. I heard that this can be done in fixed pipeline mode, but I guess learning both is good too.
MJP
MJP
There's also the PostProcessing sample that comes in the D3D9 section of the SDK, as well as the HDRPipeline sample.

If you don't want to get into shaders, you might want to try something like this:

1. Render everything to a render target texture that's the same size as your back buffer
2. Use ID3DXSprite (or something similiar) to render the render target texture from step #1 to another render target texture whose dimensions are (width/2, height/2) or (width/4, height/4).
3. Render the first render target to the backbuffer, with no blending enabled
4. Render the second render target to the backbuffer with additive blending enabled, using the "Color" parameter of ID3DXSprite::Draw to control how strong the glow effect is.

I'm not sure how good this would look, but it's worth trying. Shaders are definitely "where it's at" in terms of graphics programming these days, so you will want to learn them at some point.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.