Jump to content
  • Advertisement
Sign in to follow this  
Bljashinsky

Blending problems between snow and trees

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

The terrain program I made is having blending problems with the snow particles and billboard trees. The snow is falling everywhere except in front of the trees or behind themwhere it is invisible. I'm rendering the trees first and then the snow, which I believe is correct, because when I change the rendering order the snow's background is removed and goes through the trees. Does anyone know what I need to change for the snow to fall by the trees like it does everywhere else? Thank for any help you can provide. If any of my code is required to solve this problem just ask and I'll post it.

Share this post


Link to post
Share on other sites
Advertisement
To me, it sounds like you need to do one of three things:

1) Sort all the snow flakes and trees together so you get back-to-front rendering (assuming they're all transparent)
2) Sort the snow flakes into groups between each tree.
3) If they're all opaque, turn on depth writing and reading for the trees and snow flakes.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thank you for your help. It's late so I'll have to try it tomorrow or Monday. The objects are all transparent so it seems like option 3 wouldn't work (Please correct me if I'm wrong because I'm still pretty new at this stuff). Here's part of the rendering code for each where I set the render states:

Trees:

// set render states before drawing trees
pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
pDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true);
//pDevice->SetRenderState(D3DRS_ALPHAREF, 0x08);
pDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);

// set ALPHABLENDENABLE and ALPHATESTENABLE to false
pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
pDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false);


Snow:

void PSystem::PreRender()
{
_device->SetRenderState(D3DRS_LIGHTING, false);
_device->SetRenderState(D3DRS_POINTSPRITEENABLE, true);
_device->SetRenderState(D3DRS_POINTSCALEENABLE, true);
_device->SetRenderState(D3DRS_POINTSIZE, d3d::FtoDw(_size));
_device->SetRenderState(D3DRS_POINTSIZE_MIN, d3d::FtoDw(0.0f));

// control the size of the particle relative to distance
_device->SetRenderState(D3DRS_POINTSCALE_A, d3d::FtoDw(0.0f));
_device->SetRenderState(D3DRS_POINTSCALE_B, d3d::FtoDw(0.0f));
_device->SetRenderState(D3DRS_POINTSCALE_C, d3d::FtoDw(0.5f));

// use alpha from texture
_device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
_device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

_device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
}

void PSystem::PostRender()
{
// switch back render states to the way they were before PreRender was called
_device->SetRenderState(D3DRS_LIGHTING, true);
_device->SetRenderState(D3DRS_POINTSPRITEENABLE, false);
_device->SetRenderState(D3DRS_POINTSCALEENABLE, false);
_device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sorry, forgot to log in. That was me.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I've been having problems sorry for posting without logging in. The last 2 were mine.

-Bljashinsky

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!