Streaking glow with a DX8 Pixel Shader

Discussion in 'Game Development (Technical)' started by Battleline, May 14, 2005.

  1. Battleline

    Original Member

    Joined:
    Feb 15, 2005
    Messages:
    194
    Likes Received:
    0
    I am attempting to create a streaking glow effect using ps1.1 in DirectX 8. I have created a glow effect using a gaussian blur on a second "glow" surface that I blend with my main back surface.

    Here's my current glow effect.

    If I don't clear my glow surface every frame, I get a streaking effect like this.

    This creates an interesting streaking effect. The only problem with it, is that eventually the glowing takes up the entire screen and you have a completely white screen. What I would like to do is every frame cut the brightness of each pixel in half. That way, there is a streak effect that doesn't eventually fill the entire screen with white.

    I created a pixel shader and rendered the glow texture to itself in an attempt to do this.

    Here is the pixel shader code:
    Code:
    ps.1.1
    def c0, 0.4, 0.4, 0.4, 0.4
    tex t0
    mul r0, t0, c0
    
    I then render a screen size quad back to the same glow texture, having set both the render target and the texture to the glow texture.

    Here's the code:
    Code:
    	g_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
    	g_pDevice->SetRenderTarget( g_pGlowSurface, NULL ); 
    	g_pDevice->SetTexture( 0, g_pGlowSurfaceTexture );
    	g_pDevice->SetPixelShader( g_ResourceManager->m_dwReduceShaderPS );
    	g_pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,0,2);
    
    Howevever, I don't get the reduced color that I was looking for.

    Here's a few screen shots to show you what happens

    Screen Shot 1.

    Screen Shot 2.
    As you can see, the screen still fills with a white color... however, the color is at least somewhat transparent. Does anyone know what I'm doing wrong?

    Thanks
     
  2. soniCron

    Indie Author

    Joined:
    May 4, 2005
    Messages:
    3,664
    Likes Received:
    0
    I am not at all familiar with either pixel shaders or DirectX, but I am quite proficient at digital signal processing, so here's what I suggest:

    What's happening right now is that you're actually doing the same thing as you were in the beginning, but you're only doing it half intensity. You will want to subtract color from the glow. I don't know exactly what to tell you to do, but you will want to write black over the glow texture with partial alpha. That's why you're getting the same thing, but washed out. Now translate what I said to accurate pixel shading, and that should yield better results! ;)
     
  3. Battleline

    Original Member

    Joined:
    Feb 15, 2005
    Messages:
    194
    Likes Received:
    0
    I agree with you as to what appears to be happening. I'm just not sure why. From what I can tell, every time a new frame is rendered, the glow intensity from the previous renderings should be cut in half. The effect of that should be a streak that doesn't continue indefinately... but instead it seems to be rendering the glow with reduced intensity.
     
  4. soniCron

    Indie Author

    Joined:
    May 4, 2005
    Messages:
    3,664
    Likes Received:
    0
    See if maybe you're displaying your half-bright texture before applying the next glow effect.
     
  5. mkovacic

    Original Member Indie Author

    Joined:
    Jul 28, 2004
    Messages:
    127
    Likes Received:
    0
    You can't render to a texture you're reading from, you'll get undefined behaviour. You'll need to double buffer between two textures.

    Try it that way, and if it still doesn't work, post your setup (together with any blending states), and we'll take a look.
     
  6. Battleline

    Original Member

    Joined:
    Feb 15, 2005
    Messages:
    194
    Likes Received:
    0
    Hmmm.... I was afraid of that. I think I'll hold off on the streaking for a little bit because I'm having some other problems with my glowing effect. It seems like when I switch to rendering to another surface, I get strange transparency problems... it kinda looks like my ZBUFFER gets messed up. I'll probably start another thread for that though... assuming I can't fix it in the next few hours.

    Thanks
     
  7. Mark Sheeky

    Indie Author

    Joined:
    Aug 7, 2004
    Messages:
    448
    Likes Received:
    0
    I don't know if this helps but I think I know how to do the effect you want without using pixel shaders. Normally in DX8 you would render transparency using:

    lpDDdevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

    For the glow effect you use:

    lpDDdevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_DESTALPHA);

    Mark
     
  8. Battleline

    Original Member

    Joined:
    Feb 15, 2005
    Messages:
    194
    Likes Received:
    0
    Well, it's not the glow that's the problem, it's getting the glow to create a "streaking" effect. I know in general what needs to be done, I'm just not sure of the specifics.

    Right now, however, I'm moving to a different problem. When I switch render targets, my models no longer seem to have their faces rendered properly. Faces that should be obscured by faces in front of them are being rendered. I'm not sure what I should do to prevent this from happening.

    I'm going to post this issue to another thread because I can't figure out what I need to do.

    Here's a screen shot.
     
  9. mkovacic

    Original Member Indie Author

    Joined:
    Jul 28, 2004
    Messages:
    127
    Likes Received:
    0
    Looks like a z-buffer issue. Make sure you have all z-buffering states set correctly (the screenshot looks like the z-testing is disabled or set up incorrectly). Are you passing a valid z-buffer to the SetRenderTarget()?
     
  10. Battleline

    Original Member

    Joined:
    Feb 15, 2005
    Messages:
    194
    Likes Received:
    0
    Thanks for getting back to me. I am working the z-buffer issue in a different thread. I will come back to this thread when I get back to working on my streaking effect.

    Thanks
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer