Blending problems between snow and trees

Started by
3 comments, last by GameDev.net 19 years, 7 months ago
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.
------------------------------------------------Please visit New World Video GamesPlease visit New World Video Game's Forums
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.

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);
}
Sorry, forgot to log in. That was me.
I've been having problems sorry for posting without logging in. The last 2 were mine.

-Bljashinsky

This topic is closed to new replies.

Advertisement