ShadowRenderPass question

I was adding shadows to my scene and noticed that the vertex and triangle count goes through the roof when I do.  I have a scene with about 12 trees that use shared meshes and displayed vertex count is at about 300,000 and triangles at 100,000.  When I add a shadow pass and add these trees as occluders, the vertex count goes to about 1.8 million and triangle count to 800,000.  I took a look at ShadowRenderPass code and didn't see anything that would be duplicating a bunch of vertices.  It is using stencil buffer technique for shadows right?  Actually, glad I looked at it because before I thought it was doing some fancy shader technique using render to texture.  I am using the modulative method for shadow lighting as it is faster and couldn't get additive to look right as skybox also gets shadowed funny even though it is not an occluder.  Any ideas as to why the geometry count goes up so much with shadows?

that got to be some amazingly detailed trees! :slight_smile:

stencil shadows works by extruding the meshes to create shadow volumes that act on the stencil buffer. so you create triangles for that…i'm guessing your trees are such that they produce way bigger extruded meshes.

you can extrude meshes without adding polys for performance and memory by just stretching the mesh, but that looks ugly many cases.

have a look at the MeshShadows class for the shadow volume generation…

Silly me!  Of course it has to generate additional geometry to render the shadow volumes.  From the code, I see that it creates 4 verticies for every edge that is facing the light in the mesh, where two verticies are from the original mesh and 2 are projected to create a volume.  This could potentially create more than 2x as many verticies as original, especially if many of the indicies of the original mesh reference more than one vertex.  I guess in my case, many of the verticies are indexed, causing the vertex explosion in the shadow volume.  Forgive my ignorance, but is all this vertex duplication really necessary? :?

for very complex geometry, especially those with complex topology which makes for many edges having to be extruded, some version of shadowmaps is really the way to go… another way to go is using simpler versions of your geometry and use those as the occluder geometry instead.

Thanks for the quick reply.  I'm currently using jme 1.0.  Is there any shadow mapping with render to texture implementation in jme 2.0 or plans for it in 2.0?  If not, I saw a good example of this in "Introduction to 3D Game Programming with DirectX 9.0C" by Frank Luna, but of course this would have to be ported to opengl, but I'm sure there's some opengl versions laying around on the net somewhere, but I don't have time right now to look at them and try to write an implementation for jme.

Obviously, those trees I'm using now are just for testing as they are way too poorly optimized  :slight_smile: and will move to sets of quads for the leaves with transparent leaf textures applied to them.  Then, I could use a low-poly mesh rep for those trees to use as the occluder.  I'm assuming it's okay for something to be in occluder set but not in regular scene graph that is attached as root node in the render pass?