Advertisement

Techniques for optimising/cheating shadowmapping for single dynamic object in a baked environment?

Started by October 29, 2018 08:45 AM
5 comments, last by markypooch 6 years, 3 months ago

Hi there!

I was wondering if there existed any cheats/shortcuts/optimisations we could perform if we know beforehand that there will only be a single non-skinned mesh that will be casting shadows in our scene. Our scene is entirely baked, and the only non-static element is this mesh. 

I was wondering if there was some way to 'precompute'/'bake' down the shadow information for this mesh so that we can use that to cast shadows on to the objects in the scene. 

One idea I had was similar to the octaherdron imposter technique, but instead of baking down color, you bake down what the shadows would look like from various angles, and all the baked surfaces in your game sample the appropriate shadow texture based on the position and rotation of that dynamic mesh. Seems simple in theory but there are a few implementation details which I haven't been able to wrap my head around. I figured I would ask here and pick the brains of all the guru's incase I am reinvent some wheel here! :)

Why not simply render all the static stuff first into a normal shadow-map (during loading or first frame) and at the beginning of the frame copy this texture into a 'working' copy depth render target and render the only dynamic mesh on top of it. Use the 'working' copy as a normal shadow-map. Copy the initial, render one mesh, use. Repeat.

Copying 4096x4096 R32 on PS4 Pro takes around 0.5 ms, rendering that one mesh will take nothing, applying the shadowmap isn't expensive. No need for any baking and custom cooking tech. Depends if this GPU cost is OK for you.

EDIT: Another option would be not copying but rendering the dynamic mesh into a SEPARATE depth render target every frame and applying BOTH shadow-maps. Depends whether the application is cheaper than the copy.

Sorry for not replying directly to your more complicated suggestion :)

Advertisement

I am targeting mobile devices. I want to entirely avoid kicking of a render operation for a single object just to render its shadows. I don't have much control over the rendering pipeline (Using Unity) so it ends up doing a lot of extra stuff (culling etc) which seem to take a substantial amount of time on mobile. I would be removing shadow pass entirely if there existed some baking/custom cooking tech. It would also mean I can do some nicer filtering ('soft shadows') on the baked result without incurring additional performance cost at run time.

 

edit: 

Also, I should add that the static stuff is already rendered into a shadow map. I am using Lightmapping built into unity, so if we ignore the single dynamic object then the scene already looks lit/shadowed correctly because of the lightmapping. I just need my one dynamic object to cast its shadows onto this lightmapped scene as cheaply as possible. I do not require a generalised solution, I have a very specific use case (single shadow caster which is a simple non skinned mesh) so that should be prime for some sort of shortcut/optimisation.

If the light source is constant and directional, and the mesh doesn't deform, why not just render the pre-computed shadow as a texture decal? The target geometry would need uv coordinates aligned to the plane of the light direction. You could generate the uv on the fly as a distance to plane in shader or precompute for the vertices. Technically the below is incorrect because the wall has blocked the shadow below the yellow line but if you only have one light source its in shadow anyway. If you have a different light like a light bulb in the level below this system wont work. I guess it comes down to how accurate/fussy you will be:

image.thumb.png.dce547fcf5841189512f61f2d74baa1a.png

PS: If the mesh rotates like say its a car, I'd have 4 or 8 shadow decals and lerp between them.

 

 

7 hours ago, Prodigga said:

I am targeting mobile devices

I remember this article on gamedev. You might wish to consider his approach where the author explained why he choose shadow volumes instead.

The key here will be to check if all the SV calculations will be more cheap than rendering (even partly) a scene twice. And I believe so since the silhouette edges could be pre-computed from what you wrote.

You can lower the bar even more, and just bake the shadow directly into the texture, not as a dynamic decal, but as a uniform part of the final texture. Depending how/where you are doing your modeling, not sure how well this work for other light sources (as opposed to directional), but I don't foresee an issue with pointlights. Arealights (dynamic lights in a scene in general) wouldn't really mesh well with this, especially if you shine a dynamic area light on a "occluded" portion of a texture, and the shadow remains would give a very tacky look.  The benefit here obviously is no code is involved, and all the work can be done offline

It goes without saying the biggest caveat here is meshes must remain static (As opposed to TeeTreeTims solution), or some other method be deployed if you wish to keep the illusion.

A quick example I found on youtube that looks good: 

966765134_ScreenShot2018-10-30at4_49_07PM.png.7466a2b56f89510ac88df32a5d67eba2.png497788332_ScreenShot2018-10-30at4_49_14PM.png.70a86eeaccec3d01933dbd86ffdad511.png

 

 

 

 

This topic is closed to new replies.

Advertisement