Skip to main content
GameDev.net gamedev.net
🔒 Locked

Particle system, shadows + problem with drawing distance

Started by martinperry Nov 21, 2009 at 12:35 PM 9 replies 4k views
Original Post
martinperry
martinperry
Hi... I have created particle system, which works pretty fine. But I have problem with shadows. I use PSSM (or CSM) and I thought, that with alfa blending i will have in shadow map alfa blended particle. Instead of that, i got in shadow map whole triangle (my partices are made from triangles) And second problem. If I am too close to particles (in my opinion, if i render first shadowed cascade), I see (instead of sky from skybox or scene) color from device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.Blue, 1, 0); This is caused by skybox, because skydome is out of view distance. SkyDome is transformed by world matrix Matrix worldMatrix = Matrix.Translation(0, -0.2f, 0) * Matrix.Scaling(100, 100, 100) * Matrix.Translation(this.camera.Position); If I change Scaling I cannot see device background color, but than i can see no terrain :( So how should I render it all-together (particles, skydome and shadows) ? I render scene this way. ShadowMap { Scene Particles } Shadow - using shadow map { SkyDome Particles Scene } Water reflection - using shadowed scene (i have shadows in my reflection) { SkyDome Particles Scene } Apply Water texture
szecs
szecs
You can't do shadow-mapping particles like that.
You see, at shadow map generating pass, you write to the depth buffer and copy that. The depth buffer has no idea of blending.
You can only shadow alpha tested things like that, since if alpha < some_value, the depth buffer isn't affected.
But that won't solve your problem. Try googling particle shadows, I think you can't solve that without shaders.

I will try doing this, when I learn GLSL.
1.render opaque objects to SM1 depth map2.render transparent objects to SM2 depth map; and AM alpha map3.fragment shader:If SM1 casts shadow:    shadow_intensity = 1else if SM2 casts shadow:    shadow_intensity = AMelse    shadow_intensity = 0

I don't know if it handles particle-receiving-particle_shadows properly.
EDIT: No, because you have to align to the light view, than the camera view, so the lower half will be always shadowed, and the upper not shadowed.
However, particles still can receive shadows from the opaque objects.
/EDIT

As for CSM and skydome:
I would exclude the skydome from the CSM thing, and simply draw that first.
BTW: do you draw the further cascade first? You should.
So:
1.Skydome2:furthest cascade3.next furthest cascade...
martinperry
martinperry
Drawing from furthest slice of CSM didnt solve the problem (problem is in fisrt pass, further are ok) and added problem with overlapping (if i render further first and then next furthest, its drawen over and i see "ugly" effects)

As for shadows. I google it, but solutions i found expect DX10, or using depth-stencil (which is far away from shadow-maps) and it could kill my framerate (so far shadow mapping cost me about 150 FPS - I use 1024x1024 a three cascades)
szecs
szecs
The way I implemented CSM:
I alter the projection matrices of the cascades:
image
So drawing everything in every pass. It's maybe not too powerful, but it can be combined with frustum culling. See My demo in my signature. I use 5 cascades. It not demonstrates csm too well, but as you can see there are no artifacts.

If you use blending, then you should draw the particles after the scene.

BTW how did you do soft shadows? What engine you are using?
martinperry
martinperry
I use only shadow maps. I use PSSM code from NVidia page. The entire negine is my work (with a lot of help from riemers tutorials).

I draw particles as last. Together with sky-dome (skydome - particles -> texts to screen -> present scene)

martinperry
martinperry
If I change renderer to render from furthest slices, i got weird result:



1) Car is not complete
2) particles look like if they were emitting from point somewhere in distance (not in position where camera is, on the screen)
3) I see cracks between cascaded
4) You can look throw hills (same problem as car)
martinperry
martinperry
I solved that problem below. When I changed drawing order, i forget to swap near and far... dummy error.

Now i solved particles and scene without water... But if i add water to this


Under water is everything almost ok.. but if i am out of water particles emit from wrong pos.

I render scene as you said:
skydome->far_cascade(scene->particles)->next_cascade(scene->particles)
->mear_cascade(scene->particles)->text

and i modified this to
water refraction map -> water reflection map -> skydome -> shadowmap for far cascade -> far_cascade + scene->particles + water -> shadowmap for next cascade -> next_cascade + scene->particles + water -> shadowmap for near cascade -> near_cascade + scene->particles + water ->text
szecs
szecs
Transparent objects always have to be rendered last (at each pass). (The water in that case is not transparent (I think), since you use refracting)
Transparent objects should't write the depth buffer, so the water is always drawn above them.

water refraction map -> water reflection map -> skydome -> shadowmap for far cascade -> far_cascade + scene-> water>particles -> shadowmap for next cascade -> next_cascade + scene-> water>particles -> shadowmap for near cascade -> near_cascade + scene-> water>particles ->text
martinperry
martinperry
Thank you very much... that solved my particle problem.

-----

Now little off-topic qusetion. Is there some simple way, how to render water with shadows (shadowed water reflection), without killing my fps ?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.