Alpha on primitives when rendering mesh

Started by
10 comments, last by Kurt-olsson 11 years, 8 months ago
Hi!

i have a problem with Alpha in my triangles.
the alpha is working fine on my triangles, but as soon as i render my mesh the alpha disappears.
it seems to be when i use this line: d3ddev->SetTexture(0, texture ); the alpha is destroyed.

is it possible to mix alpha on primitives when rendering a mesh? Or do i have to get a texture on the triangles and set alpha on texture?

this is how i render my mesh:
[source lang="java"]for(DWORD i = 0; i < numMaterials; i++) // loop through each subset
{
d3ddev->SetMaterial(&FPSL1Material); // set the material for the subset
d3ddev->SetTexture(0, texture );
FPSL1->DrawSubset(i); // draw the subset
}[/source]

as soon as i add this code, my alpha is broken...
Advertisement
You should be able to mix alpha and texture color just fine, though you need to make sure that you're not outputting a color with no alpha in it. Also make sure that you have alpha render state enabled.
Perception is when one imagination clashes with another
the alpha is working with two quads perfect, but as soon as i add my mesh (drawing it) the alpha disappears and there is solid color on the quads... =(
Hi,

maybe SetMaterial messes your settings? You'll need to set your alpha blending on just before drawing the quads, every frame. Not just at the beginning of the program.

[edit] Maybe you have to also unbind the textures

Cheers!
Now the alpha is still working quad to quad when also drawing the mesh. (It had to do when loading materials into the mesh textures).

But the quads are not alpha against the mesh itself?

I have a big gamelevel that is a big mesh. I want my quads to have alpha against the mesh. Now the quads are completely black against the mesh if 1 in alpha value and of course this looks no good either no alpha... =(
d3ddev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);

when adding this line i get beautiful alpha on cubes but my mesh is totaly white...
Hello.

Draworder bug perhaps? What if you draw your quads after the mesh?

Also, when setting a state such as d3ddev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE); you'll need to set it back to the state used to draw other stuff on the scene.

Cheers!
When rendering with alpha, you need to draw any opaque geometry first, then draw the alpha geometry back to front. And it definitely seems like you have a render state bug somewhere, make sure that before each of your draws you enable any states that you need (alpha) and then draw. Then optionally disable any states you set prior to the draw.
Perception is when one imagination clashes with another
my problem i think is as you say.

now i only set my SetRenderState on Init only once.

i think i have to do like this:

void draw Primitives() {
Disable z buffer
SetRenderState(for alpha)
SetRenderState(for alpha)
SetRenderState(for alpha)
draw primitives
}

void draw mesh() {
enable Z buffer
SetRenderState(for mesh)
SetRenderState(for mesh)
SetRenderState(for mesh)
draw gamelevel
}


Problem is that there are alot of flags and i am not 100% sure which to use. =)
if (alpha) {
d3ddev->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
d3ddev->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
d3ddev->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
d3ddev->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
}

these are the correct states if using alpha, now it works!

This topic is closed to new replies.

Advertisement