Jump to content
  • Advertisement
Sign in to follow this  
barakus

Blending Issues....

This topic is 4836 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

After much editing and testing i thought i had finally perfected the blending in my program. I was wrong. First I render my 2D map, and then a sprite, which is then followed by a black semi transparent quad covering the whole screen, which acts sorta as a shadow, and lastly a sprite which is used as a light is rendered. I have to render things in that order or otherwise the lighting wont show properley. The problem is that if I render the sprite before the quad covering the whole screen, the quad refuses to show up. This only happens when the sprite has alpha in its original image. Any help would be extremely appreciated.

Share this post


Link to post
Share on other sites
Advertisement

You can try turning of the zwriting (D3DRS_ZWRITEENABLE) render state before drawing the sprite. Should solve this problem, but might cause other problems :)

Share this post


Link to post
Share on other sites
I tried it, didnt work :(.
I should also mention this only occurs when using the fixed function pipeline, when I use a simple shader that multiplies each colour( r,g,b,a) of the texture with the colour of the vertice it works fine.

Share this post


Link to post
Share on other sites
Transparent objects will need to be drawn in a certain order. There's no magic 3D trick to paint stuff. It works just like the real world. Drawing green then blue is different than blue then green [smile]

Just give your sprite's a depth value and sort them with qsort() or such?

By the way, I don't think the flag is D3DRS_ZWRITEENABLE, Foo buddy :P

> "The problem is that if I render the sprite before the quad covering the whole screen, the quad refuses to show up"

Definitely sounds like the z buffer messin with ya. But turn it off, not on.

Share this post


Link to post
Share on other sites
Nah guys its definitely not the z buffer, as I mentioned before when I use shaders to do it there are no problems at all, and i have turned it off and the same results apply.
I cannot change the order of rendering, as the one that doesnt show is meant to blend with the sprite. Its also worth mentioning that if the sprite doesnt have any alpha it works fine.
Could there be any other cause for all this?

Share this post


Link to post
Share on other sites
Quote:
Original post by Jiia
Transparent objects will need to be drawn in a certain order. There's no magic 3D trick to paint stuff. It works just like the real world. Drawing green then blue is different than blue then green [smile]

Just give your sprite's a depth value and sort them with qsort() or such?

By the way, I don't think the flag is D3DRS_ZWRITEENABLE, Foo buddy :P

> "The problem is that if I render the sprite before the quad covering the whole screen, the quad refuses to show up"

Definitely sounds like the z buffer messin with ya. But turn it off, not on.


You're right, sorry, it was the D3DRS_ZENABLE flag.

Quote:
Its also worth mentioning that if the sprite doesnt have any alpha it works fine.


Well what Jiia said basically. For transparent objects you have to draw in the back to front order or they simply show up wrong (or dont show up at all).

Could you tell us what is the approximate z-order of the stuff you are rendering? ie: is the light sprite usually in front of the quad, or vice versa, etc...

Share this post


Link to post
Share on other sites
Are you sure you're setting a matrix state for all objects? If you set the world matrix for the object, then you need to reset or set one for the quad. Maybe your shader is ignoring something to render the quad that the fixed pipeline is using, which throws it off?

I'm not sure what else could cause the problem.

Foo: Damn, man. I guessed your flag name was incorrect because of the enable part. I completely forgot about the whole (D3DRS_ZENABLE, false) bit. Weird how you really had it wrong though. Sorry about that.

Share this post


Link to post
Share on other sites
Nah it cant be that, as if I replace the image of that sprite with one that doesnt have any alpha information it will work fine.
Doesnt this all indicate that it is something with the blending?

Share this post


Link to post
Share on other sites
Can we see a screen shot? How big is the sprite compared to the quad? Are they the same size? If so, try reducing the size of one to see border effects. Are you setting a second texture or anything to render something? You also have to turn those off. Also make sure the primary texture is correct for the quad. If it's UV coords are really low, maybe it's using the top corner of the sprite alpha map? Hmm.. can't think of anything else.

Share this post


Link to post
Share on other sites
Maybe your alpha blending is using the destalpha to decide whether or not to draw the black quad.

When your image has no alpha, DX assumes 0 for alpha, (or 1, who knows :)) and then it draws the black over it. If you use an image with alpha, DX doesn't set a default value for the alpha, and so it doesn't let it draw the black quad since the dest alpha isn't 0 (or 1, or whatever).


Anywho, what are your blending states and alphablend op and all those things?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!