• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
RobMaddison

Render targets with alpha

14 posts in this topic

Thought I'd start a new topic on this one. I'm having an issue rendering my screen layers.

My first layer, the game scene, is rendered to the back buffer, my next scene, the HUD (which currently is just a bunch of text quads), is rendered to a render target. I then blend the HUD render target onto the back buffer with a very simple full screen quad shader.

The problem is that my HUD render target doesn't appear to be fully transparent in the areas where I haven't drawn text. When I Clear the render target I clear it with 0,0,0,0 which I thought would give me a fully transparent surface. I then render my text quads to that target.

When I blend, the HUD layer just appears to cover the back buffer surface completely. If I adjust the alpha component in the output of the simple blend pixel shader to something like 0.5 then I get half brightness on the background and half brightness on the HUD layer.

Is there some special blend mode parameters I need to set for rendering alpha to rendertargets?

My blending is:

BlendOp=ADD;
SrcBlend=SRCALPHA;
DestBlend=INVSRCALPHA;
AlphaBlendEnable=TRUE;

This shader is very simple, renders to the back buffer and just takes a sample from the HUD layer.
0

Share this post


Link to post
Share on other sites

Are you drawing anything to your HUD other than text, or are you saying that the places where you have drawn absolutely *nothing* to your HUD rendertarget show up as opaque when you render the HUD to your back buffer?

0

Share this post


Link to post
Share on other sites
The HUD only has a couple of lines of text, the rest of the area (which is 99% of it) should be transparent but is coming through as opaque.

If I manually set the alpha in the blend shader pixel shader return value to 0.5 it works, but obviously the areas of the HUD that haven't been drawn on should be alpha 0.
0

Share this post


Link to post
Share on other sites
Do a single frame capture in pix, and check whether your HUD layer's alpha channel is really valid.

I assume your pixel shader is basically just 'return tex2d...'?

What texture formats are you using?
0

Share this post


Link to post
Share on other sites
I saved the texture from pix (dds) and the opacity was 255 (full)...

Yes, just a very simple tex2d

Texture format for the render target is A8R8G8B8.

So I guess it means my clear is not clearing it to transparent...?
0

Share this post


Link to post
Share on other sites

Are you clearing with D3DCOLOR_ARGB(0,0,0,0)?

 

Even D3DCOLOR_XRGB(0,0,0) should do (no warranty), just make sure its three zeros and not like 255.

Edited by The King2
1

Share this post


Link to post
Share on other sites

Betting it's clear color too.

Should I not be clearing colour?

Are you clearing with D3DCOLOR_ARGB(0,0,0,0)?

Even D3DCOLOR_XRGB(0,0,0) should do (no warranty), just make sure its three zeros and not like 255.

Yes, definitely clearing with 4 zeros. I can't quite remember whether it's XRGB or ARGB (I'll check) but it's definitely 4 zeros.
0

Share this post


Link to post
Share on other sites

Betting it's clear color too.

Should I not be clearing colour?

>Are you clearing with D3DCOLOR_ARGB(0,0,0,0)?

Even D3DCOLOR_XRGB(0,0,0) should do (no warranty), just make sure its three zeros and not like 255.

Yes, definitely clearing with 4 zeros. I can't quite remember whether it's XRGB or ARGB (I'll check) but it's definitely 4 zeros.

 

 

Not quite, I just suspect you're clearing it to an 'opaque' alpha value when you really want it to be cleared to a transparent one. You can try flipping the alpha to 1.0f/255u and seeing if that changes anything. Of course, all this is irrelevant if you're using an XRGB render target!

0

Share this post


Link to post
Share on other sites

Thats what my clear call is looking like:

 

m_lpDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 1.0f, 0);

What does yours look like? Did you make sure the texture is still bound to the device when clearing? Does this happen in release and debug mode? I remember having a very similar issue with alpha transparency, only in release mode, I try to find the thread (it's quite old), can't recall the solution anymore...

0

Share this post


Link to post
Share on other sites

Not quite, I just suspect you're clearing it to an 'opaque' alpha value when you really want it to be cleared to a transparent one. You can try flipping the alpha to 1.0f/255u and seeing if that changes anything. Of course, all this is irrelevant if you're using an XRGB render target!


Definitely using an XRGB render target - if I return an alpha of 0.5 in the shader ithe transparency works but everything is half bright as expected.

When I clear, I clear z and colour and use the equivalent of D3DCOLOR(0,0,0,0). Wouldn't that just resolve down to a DWORD of zero anyway? So even if I used FromXRGB(0,0,0), surely that would still resolve down to a DWORD of zero?
0

Share this post


Link to post
Share on other sites

Is the *HUD* render target being cleared and/or XRGB, or is the backbuffer?


Yes, the hud render target gets cleared in the 'normal' way, i.e. clear colour, clear z, with a colour of 0,0,0,0. Not sure what you mean by 'or is the backbuffer?'
0

Share this post


Link to post
Share on other sites

Yes, the hud render target gets cleared in the 'normal' way, i.e. clear
colour, clear z, with a colour of 0,0,0,0. Not sure what you mean by 'or
is the backbuffer?'

 

If you call Device->clear(X,...); the currently set rendertarget gets cleared, where the first parameter ist the stage you bound it to using SetRenderTarget(X, surface). So if you just call "clear" at the end of the render loop after you set the rendertarget back to backbuffer (SetRenderTarget(0,NULL)) only the backbuffer will get cleared. You need to call Clear expicitely when the texture is bound as a rendertarget. You need to clear the backbuffer like you probably do know in addition to that.

 

Plus, no need to "Clear z" for a backbuffer-sized rendertarget.

Edited by The King2
0

Share this post


Link to post
Share on other sites
Sorry guys, just fixed this, I had inadvertently created my render targets with XRGB - it's working with ARGB. I could have sworn I checked that - thanks a lot for all your responses.
0

Share this post


Link to post
Share on other sites

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  
Followers 0