Sign in to follow this  
barakus

Blending Issues....

Recommended Posts

barakus    205
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
IFooBar    906

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
barakus    205
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
Jiia    592
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
barakus    205
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
IFooBar    906
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
Jiia    592
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
barakus    205
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
Jiia    592
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
sirob    1181
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
barakus    205
the sprite is 40x64(though its animated), while the quad is 256x224(Which is the size of the screen as set in the projection matrix). The quad isnt textured, its just a 256x224 black quad that should be half transparent(0.5f alpha).
I''ll try to get some pictures up of with shaders(how it should look) and how it looks without.

Share this post


Link to post
Share on other sites
IFooBar    906
Also, this does seem to a problem with blending, since it only dosent render when you have an alphaed sprite. This may be too obvious but are yoiu sure you are not setting up a wrong threshold value and comparison function if using alpha testing, and if using alpha blending, what are you src and dest states?

Share this post


Link to post
Share on other sites
barakus    205
Ok here is the link to the images (sorry dont know any HTML)
the one called "shaders"(http://www.villagephotos.com/viewpubimage.asp?id_=12222934&selected=)
is the working one(the darkness comes from the transparent black quad) and "no shaders" (http://www.villagephotos.com/viewpubimage.asp?id_=12222935&selected=)
is the one that doesnt work. the sprite thats causing the problems is the human character( Trevor Belmont from Castlevania)

EDIT: sorry sirob i didnt see your post. To draw the sprite with alpha(the one thats causing the problems) I use
SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
and to draw the shiny point(which doesnt really matter because its not interfering with the quad, it works with this one and not the other one) I use
SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE);
SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );

Share this post


Link to post
Share on other sites
Jiia    592
The thing I don't get is how a vertex shader could have any effect on something related to textures, other than the uv coordinates and vertex color. Or are you using a pixel shader? If so, I guess a whole lot of things could be happening differently.

If it's just a vertex shader, it must be related to color or texture coordinates. Are you sure you're setting SetTexture(NULL) for the quad?

Yep. I think I'm out of ideas.

Share this post


Link to post
Share on other sites
sirob    1181
Quote:

which is then followed by a black semi transparent quad covering the whole screen


Is this what's not rendering? What are the src and dest settings for this quad?

(EDIT)Also,
SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE); and
SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE ); Seem like a pretty bad blending choice. It's really just modulating, you don't really need alphablending for that.

Share this post


Link to post
Share on other sites
barakus    205
Yes! I wasnt setting the texture to null! It works now!
Thank you guys so much for your help I had completely run out of ideas.

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