# Soft Particles with DirectX 9

This topic is 2904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I'm trying to do Soft Particles with DirectX9.

I'm using the NVIDIA paper as guidance:

As far as I know, the general idea is:

1. Render the scene without particles into a depth map.
2. Render the scene with particles. For each particle's pixel, check the depth of the scene to see if the particle should be opaque or semi-transparent.

I have a few questions:

1. Should I write "z" or "z/w"? The NVIDIA paper says "z", but if I write just "z", it seems like all of the pixels show up with the same value. Should the depth map make sense if I save it as a jpg? If I write "z/w", I see something that makes more sense (subtle changes in color due to different depths).

2. I'm using D3DFMT_R32F for my render target. I've seen other posts saying that I can get away with just writing the depth into the x component of the color in the pixel shader. But if I do this, my depth map is completely light blue. If I write depth into all xyzw, then I see something that makes sense.

3. If I go with writing "z/w" and get the difference with the particle's "z/w", I see "soft" particles.

So I'm calculating "saturate((Zscene - Zparticle) * scale)". I'm not sure what the scale value represents, but I've found that 20.0f works for me.

What is the normal way of using the calculated value afterwards? I'm multiplying the pixel's alpha by that value. But maybe it's meant to multiply the entire color...

4. My test application's resolution is 640x480. I'm making my depth map also 640x480. Is it standard practice to make it the same size as the screen resolution? This is what makes most sense to me, but I've also seen depth maps being used for shadow mapping and they aren't the same resolution as the screen.

5. I'm using the same projection to render depth as to render the scene. Deciding on orthographic vs. perspective projections makes sense for shadow mapping, as it's based on different light types, but does it make sense to consider a different projection for a depth map intended for soft particles?

I'll try to post my code and screenshots to ask for a more formal critique.

##### Share on other sites
Haven't done this myself so please don't crucify me :D

1. Write Z (i.e. before you divide it by W). Z will range from the camera near clip plane z (I think...) to the camera far clip plane z. Thus, you can't directly visualize this (color ranges from 0->1... any Z value over 1 gets clamped to 1). To visualize this divide Z by your far plane z.

2. Writing R should be enough if you're using R32F. Don't know what's happening with your shader...

Just for reference, the following works
struct PS2GPU{	float depth : SV_Target0; //SV_Target is d3d10. COLOR is D3D9        //...}//...//in the pixel shaderOUT.depth = //your value

3. scale denotes how 'soft' the particle is. Lower scale = more soft. (The 'scale' maps z difference to a color/alpha value... higher scale => more color/alpha).

4. Yes. You want 1 depth value per screen pixel (Don't know how MSAA/etc factor into this, so you will want to ask someone more knowledgeable :) )

5. No you want the same projection (same as 4. 1 depth per pixel)

##### Share on other sites
Thanks a lot for your help, jameszhao00!!

I understand the algorithm and effect much better now, thanks to you!

I got it to work (the scale value should be lower maybe, and I still have to change the basic linear falloff for the Contrast Power function).

Soft Particles OFF:

Soft Particles ON:

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5
khawk
11

• 9
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633679
• Total Posts
3013299
×