Overlaying Multiple Opacity Textures

Started by
3 comments, last by Quinnie 17 years, 7 months ago
Hey, I'm making a terrain engine and i'm adding some low poly tree's to it wich i want to have branches wich are actually a plain with a texture on it. I have created a tree mesh object that has multiple Textures with opacity (some parts is 100% visible some parts are 0% visible). The problem is when 2 or more of these Textures overlay the opacity isnt handled correctly anymore. I'm aware this may sound a bit vague if you guys need a screenshot to clarify things please ask for it and I will add one to this post. My Blending Options: g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA); g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA); g_pd3dDevice->SetRenderState(D3DRS_BLENDOP,D3DBLENDOP_ADD); g_pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1); g_pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE); g_pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_DIFFUSE); // Render The Tree (Custom Function) if (FAILED (RenderMesh(SS_MESHOBJECT_GAME_OBJECT_TREE))) return E_FAIL; Thanks in advance, all help would be appreciated.
Advertisement
I may or may not understand you correctly. You should really give a better description than "opacity isn't handled correctly".

I have a guess of what it might be, though. Usually, when you're rendering with alpha blending enabled, you should render from back to front, doing the sorting yourself. This is because the results of alpha blending depend on the order you render things in, if you have more than one semi-transparent object visible at the same time.

If your objects are either totally transparent or totally opaque at each individual pixel (I.E. a tree with no antialiasing), you could just disable Z-write and render in any old order.

Think of this: first, you render a partially transparent tree close to the camera, then you render the one behind it. When you render the first tree, it writes to the z-buffer at every pixel, just like normal. Then, when you render the rear tree, the parts that are behind the close tree don't get rendered because there's a closer z value in the z-buffer, even if that corresponds to a portion of the first tree that's transparent.

I don't know if you're having one of these two problems, but try turning of z-writes when rendering trees first, and if that doesn't totally solve the problem, sort the trees and draw them back to front. If both of those don't work, you might have to post a screenshot. [grin]
Yes I think you do understand me correctly. I know that my description was a bit vague.

I think I need some sort of algorithim to calculate wich tree is the closest and also inside a tree wich branch is the closest.

Probably theres already some information about this on gamedev so I will search the forums.

Or I should indeed turn of z-write that should solve the problem since I'm only using Full Opacity or Full Transparency. Would it be possible to turn of z-write only for the tree rendering or would it effect the entire surrounding terrain?

Thanks For Your Reply...
Quote:Original post by Quinnie
Or I should indeed turn of z-write that should solve the problem since I'm only using Full Opacity or Full Transparency. Would it be possible to turn of z-write only for the tree rendering or would it effect the entire surrounding terrain?


If you're only using either Full Transparency, or Full Opacity, you shouldn't be using Alphablending, you should be using Alphatesting. Other than being quite a bit faster, Alphatesting also has the benifit of selectively writing to the Z-buffer depending on the result of the test.

In your case, if you disable alphablending, you can leave Z-writes (and Z-tests) on, and not need to do any sorting in your scene.

Hope this helps.

Sirob Yes.» - status: Work-O-Rama.
Thanks to gamedev and especially all of the reply's in this thread I managed to solve this problem in like 3 lines of codes using alpha testing. Also my knowledge about the z-buffering is a bit clearer now.

Again thank you for your help,

Quinnie

This topic is closed to new replies.

Advertisement