Jump to content
  • Advertisement
Sign in to follow this  
Kurt-olsson

Alpha on primitives when rendering mesh

This topic is 2126 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

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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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... =(

Share this post


Link to post
Share on other sites
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! Edited by kauna

Share this post


Link to post
Share on other sites
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... =(

Share this post


Link to post
Share on other sites
d3ddev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);

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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. =)

Share this post


Link to post
Share on other sites
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!

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!