Jump to content

  • Log In with Google      Sign In   
  • Create Account


DirectX - how to update transparency?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 savail   Members   -  Reputation: 330

Like
0Likes
Like

Posted 16 May 2013 - 06:27 AM

Hey,

I've got quite strange problem connected with transparency and hope that someone could help me here ^^. I wrote an map editor, which is used to load certain sprites with transparent background and place them on a stage. Everything's ok as long as I won't move those loaded sprites on the stage. Here's a screenshot showing how it should always look like:

good.jpg

It looks alright only if I place the black background before placing on it those magic balls tongue.png. Now If I remove the black background and put it once again (so after putting the balls) the result looks like it:

bad.jpg

The old balls have some kind of traces of previous white background(the stage's area is cleared on white in the loop) but new balls that I put on the black background behave correctly in the matter of transparency...

 

Why does this happen? Should I use some sort of function that updates the rendering area or sth? I would be very grateful for help!


Edited by savail, 16 May 2013 - 07:54 AM.


Sponsor:

#2 Jason Z   Crossbones+   -  Reputation: 4858

Like
0Likes
Like

Posted 16 May 2013 - 07:26 PM

Are you also clearing the depth buffer?  Or do you have it disabled completely?  Basically if you are clearing the color and depth buffers, then it shouldn't be an issue with blending.



#3 savail   Members   -  Reputation: 330

Like
0Likes
Like

Posted 17 May 2013 - 04:36 AM

Thanks for an answer! This is how looks my clearing like:

 

d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1, 0);
 

I suppose that everything's alright here. I found a solution to my problem anyway. The traces occured becouse of the wrong order of drawing. Before drawing I'm now sorting all my objects by their Z buffer and drawing the most remote images first and the closest at the end. The order was random earlier.

I'm a bit surprised that this problem turned out to be rather rare :P. I haven't seen anybody complaining about it but me. And I would like to ask if that's a good solution or the genuine problem might be somewhere else? Maybe my sorting is only like a work-around? Do you guys also sort all objects in ur game before drawing so that the remotest are drawn first?



#4 Jason Z   Crossbones+   -  Reputation: 4858

Like
1Likes
Like

Posted 17 May 2013 - 04:49 AM

That is typically only needed for objects which have transparency (or use blending in your case).

 

EDIT: There is actually an algorithm called "Order Independent Transparency", but it is a very heavyweight algorithm for doing simple sprite rendering.  Still, it might give some insight into the problem if you read up about on the topic.


Edited by Jason Z, 17 May 2013 - 04:51 AM.


#5 Evil Steve   Members   -  Reputation: 1959

Like
1Likes
Like

Posted 17 May 2013 - 04:52 AM

Generally you give each object a different Z value, and use the Z-buffer to do the culling for you. The Z-buffer is created (Well, usually) when you create the D3D device, if you set the EnableAutoDepthStencil member of the D3DPRESENT_PARAMETERS struct to TRUE, and set the AutoDepthStencilFormat member to a valid format.

That allows you to draw the objects in any order, and the Z-buffer keeps track of the depth of each pixel and correctly occludes pixels as required.

 

As Jason said however - for alpha'd objects, you still need to render them in back-to-front order for the blending to work correctly.


Steve Macpherson
Senior programmer, Firebrand Games


#6 savail   Members   -  Reputation: 330

Like
0Likes
Like

Posted 17 May 2013 - 04:56 AM

I guess I'm not using blending in this project. I'm just creating textures from files (.png images with transparent background) with D3DXCreateTextureFromFileEx with ColorKey parameter set to 0xFFFFFFFC.

hmm so another solution to this problem would be to use blending?

edit:

Ah ok, I just wanted to ensure that the sorting is a valid solution ^^. Thanks for help, I'll take a look on the article as well Jason, thanks.


Edited by savail, 17 May 2013 - 05:05 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS