- Home /
Using CommandBuffer how to draw Directional Light shadows in native plugin?
Hi there.
Here is task: draw an object from a native plugin with shadows.
What is done: I got a prototype of a working shadows for a Point Light. All rendering is done by a native plugin
What is required: Do the same, but using Directional Light
Two lights are rendering into "shadow map" differently: Point Light renders into CubeMap. Directional light (seems) renders into 2D map
In case of Point Light and CubeMap, you have to select each side of a CubeMap and make a render. T.e. six passes in total.
// Current render target at the time of the Light rendering is the shadow map
RenderTargetIdentifier rt = new RenderTargetIdentifier (BuiltinRenderTextureType.CurrentActive);
// Selects one side ...
this.buffer__.SetRenderTarget (rt, 0, CubemapFace.PositiveX);
this.buffer__.IssuePluginEvent (RenderFunc, 0);
// Selects second side ...
this.buffer__.SetRenderTarget (rt, 0, CubemapFace.PositiveY);
this.buffer__.IssuePluginEvent (RenderFunc, 0);
// More sides here...
// ...
// Ads command buffer to the light
this.light__.AddCommandBuffer (this.event__, this.buffer__);
But In case of Directional light it splits 2D map into four pieces (look like mipmaps), and renders on every piece separately. You can clean see this technique by Frame Debugger in the Unity
Question is how can I do the same in the native plugin? It seems like Unity API does not have such control.
I'd love to know this too. I'm trying to render shadows for my procedural mesh ( fur / hair ) using command buffers and adding them to lights with LightEvent.AfterShadow$$anonymous$$ap. It renders into the last target, but I have no way of knowing what the cascade offsets and stuff is so I can manually reset them and the same for point lights and their shadow cube map faces, also the view matrix needs to be reset for each face, among other things. What Unity needs for me is a LightEvent.AfterShadow$$anonymous$$ap_Cascade event for directional lights and a LightEvent.AfterShadow$$anonymous$$ap_CubeFace for a point lights so that all the proper states and shader constants are still setup.
Did you have to set the view matrices manually for each cube face?
Hi Scottie
Your reply is a comment not an answer. You may need to change this. But yes, technically to render a point light shadows you have to make six passes and setup matrices accordingly.
Your answer
Follow this Question
Related Questions
How to use CommandBuffer with RenderPipelineManager to draw a material to fullscreen? 0 Answers
Question about batching and SRP 2 Answers
URP Scene Mentions Built In Renderer 0 Answers
How do you use the "state" with a Rendering CommandBuffer? 0 Answers
Universal Render Pipeline Post processing breaks transparent camera background? 1 Answer