Dynamic Shadowmaps

Hello!

I’m trying to achieve a non-PBR effect in PolySpatial with RealityKit.

I’ve got an unlit material and I can get most of what I want out of the shader except for lighting.

I want to only use the lighting from Unity (i.e. no real-world lighting from RealityKit). For anything other than shadows, the PolySpatial-specific lighting node seems to do a good job.

I’ve made some headway by rendering a camera to a texture every frame and effectively hacking the camera to only output the main light shadow map using a custom render pass, but that approach leaves quite a lot to be desired!

Having to do an entire camera render in order to get access to the SRP context is a bit of a pain. I considered trying to just use a command buffer, but I think that would necessitate actually writing culling code. :sweat_smile:

IIUC only allowing string custom functions means that uniforms can’t be declared in subgraphs. This means we have to repeat a lot of our shading parameters in the top level shader graph for each shader. I don’t think we can do matrix arrays in shader graph either - which URP uses for shadow cascades.

Has anyone else tried anything quite this wild? :sweat_smile: Is dynamic shadow-mapping something PolySpatial would support eventually? (I think the use-case is as general as any non-PBR lit material.)

Ricky,

Yes, this is definitely on our road map for the lighting node. Most likely, it will be limited at first: for example, an option to include a single directional cascade for the “main” directional light.

We are using dynamic shadow maps in a very simplified form. We do a top down orthographic projection, so we don’t need a full matrix transform, but can do a simple multiply+add on the world space position.

We’re using a RenderPipeline override for the camera rendering the shadow map, it basically just renders all opaque objects with a shader that outputs the depth to a render texture. The camera render is triggered manually from script every frame.

We’re using PolySpatialShaderGlobals.SetVector to pass the vector variables. But there’s currently a bug with PolySpatialShaderGlobals.SetTexture, so we keep manual track of all materials in the scene, and set the shadow map texture directly on the material for now. Once PolySpatialShaderGlobals.SetTexture is working, you should have an easier time to get it working.

1 Like

Doing it with a material override is a good shout - it’s what I was considering trying after the issues doing a full cascading shadow map. Thanks for the info!