#How to draw VFX Graph with ScriptableRenderPass?

1 messages · Page 1 of 1 (latest)

true rock
#

I have a custom render feature which for each mesh draws data to a texture and is after used in a fullscreen pass to output outlines.

For now I've used RenderGraph.AddRasterRenderPass which has been working good. But now I added VFX drawn meshes which should also be affected. In the frame debugger I can see that it is trying to draw the VFX instanced by call and amount, but nothing is drawn. I suspect this is because no buffers are assigned; attributeBuffer, buffer_a, buffer_b, graphValuesBuffer (which they are in the opaque draw call).

Now I'm trying to change it with AddUnsafePass, and use VFXManager.ProcessCameraCommand in the renderFunc, but it doesn't show up in the debugger. GPT says that it might be since it has already been drawn higher up in the stack thus there is nothing left in commandBuffer? I do want to draw it for both the render texture and my custom texture though.

Any help or hints would be greatly appreciated.

true rock
#

Bump

jovial bobcat
#

It might work in a pass normally if you call the required VFXManager calls.

true rock
# jovial bobcat It might work in a pass normally if you call the required VFXManager calls.

I've tried like so, but there is no Constant Buffers set when drawn.

        static void ExecutePass(PassData data, UnsafeGraphContext context)
        {
            var unsafeCommandBuffer = CommandBufferHelpers.GetNativeCommandBuffer(context.cmd);
            unsafeCommandBuffer.SetRenderTarget(data.renderTarget, data.depthTarget);
            unsafeCommandBuffer.ClearRenderTarget(false, true, Color.black);
            
            VFXManager.PrepareCamera(data.camera);
            var xr = new VFXCameraXRSettings { viewTotal = 1, viewCount = 1, viewOffset = 0 };
            VFXManager.ProcessCameraCommand(data.camera, unsafeCommandBuffer, xr, data.cullResult);
            context.cmd.ClearRenderTarget(true, true, Color.black);
            context.cmd.DrawRendererList(data.rendererList);
        }
jovial bobcat
true rock
jovial bobcat
#

I think you might be overthinking. It seems like VFXManager is supposed to add all the required commands to a command buffer. You just need to execute them correctly. I'll try something a bit later on my pc.

true rock
jovial bobcat
#

There's no guarantee it's the same command buffer used for the first draw.
It's largely an assumption since we can't see too deep into the engine, but it's likely that these command buffers are just interfaces for the command lists used by the graphics api. Unity might be creating and discarding many of these for various passes or systems.

jovial bobcat
#

Hmmm... Didn't work. I feel like it might not be possible at all. It seems like a lot of the VFX related stuff is on the C++ side. Like, you don't even have a concept of materials and renderers in it. It generates the shader code and various required commands from the graph itself.

#

What you could do is render the same particles twice with your adjustment(or a custom VFX shader) to provide outlines for them.

true rock
#

Seems like default VFX is drawn from DrawObjectPass.cs, but haven't figured out if there's any setting there that set the buffers. Even if I comment this code out, the buffers don't get set for my pass.

true rock
true rock
#

Getting closer to the issue. I wrote a new simple pass that just draws to the default render target, and it gets the buffers set correctly - even if after my outline pass.

jovial bobcat
#

Yeah, I was playing around a bit as well(mainly using github copilot😅)
I got it rendering normally from code and was able to use a replacement material/shader in the second draw, however it seems to render outside the custom pass. Seems like the vfx system is creating its own render pass.

true rock
#

Wild guess is that the VFX graph generates a custom shader, combining supplied shader graph and particle draw output. Thus when overriding it with one that doesn't take particle output into account it doesn't work.

jovial bobcat
#

Ther are many issues, but here's a very rough proof of concept.

jovial bobcat
#

So unless you hijack the generated shaders or write your own with sligh modifications, it's not gonna work very well.

#

It's probably one of the cases where a custom render pass is not a great idea