#Using Render Graph to render a mesh with a lit material doesn't render lighting.

1 messages · Page 1 of 1 (latest)

eternal ermine
#

Hi all, I've done a project in the past where I rendered thousands of meshes efficiently using Graphics.RenderMeshIndirect(). This worked great, but I thought that running my rendering behaviours in Update() isn't how URP is 'meant' to work. Unity's Render Graph system seems to provide a solution here, where meshes can be drawn in a way that nestles nicely within URP's frameworks.

The problem:
I can easily render a mesh with a material (left), but that material doesn't respond to any lights. It can take metallic/smoothness data to respond to the skybox, but it does not receive light or cast shadows.

The mesh on the left is rendered using my custom ScriptableRendererFeature, which contains a ScriptableRenderPass which calls DrawMesh(mesh, trs, material, 0, forwardLitShaderPass).

The mesh on the right is a simple GameObject with a Mesh Filter and Renderer. Both use the same material.

Unity's documentation does tell you not to expect lighting data out of DrawMesh(), but for the life of me I can't figure out how you're meant to include it yourself.

My Question:

  1. Is there a way to render this mesh with correct lighting? I feel like I'm missing something obvious. Drawing the mesh was so simple with Render Graph, I'm baffled that lighting doesn't work out of the box, or that Unity's documentation can't point me towards any docs or samples that can enable lighting, explain why lighting doesn't work, or offer an alternative.

  2. Is Render Graph even an appropriate tool for my situation? I want to render thousands of mesh instances that are built from a compute shader, exactly how I did so with RenderMeshIndirect(). I can see that Render Graph has a lot of these features I need, but if I can't draw one mesh directly I don't know how I'll go with drawing multiple indirectly.

More Info
Unity: 6000.3.10f1; OpenGL
URP: 17.3.0

Thanks for any help in advance!

vital widget
#

Lighting is a very involved process, often requiring several passes(for example in deferred rendering: gbuffer + shadows + lighting passes). Commands like Render Mesh usually inject the draws in the unity built-in passes, so you get proper lighting. Render graph api on the other hand provides the ability to create new custom passes. It does not allow you to inject into unity's existing passes AFAIK. So unless you have a custom lighting pipeline, render mesh indirect is probably what you should be using.
Render graph custom pass might work in forward rendering if you execute it at the right timing and with the correct lit shader. I'm not 100% sure about it. Might require testing.
In any case, I'd recommend looking at the frame debugger to understand where your object is rendered and where other lit objects are rendered to understand the context better.

vocal depot
# eternal ermine Hi all, I've done a project in the past where I rendered thousands of meshes eff...

I'm out of my depth with render graph, but this tutorial (part 1 and 3) seems to do nothing particularly special to get lighting working, but I'm not sure if the use case is the exact same as yours
The importable sample for RendererList has a lot of lighting related parameter stuff that might give some clues
But also you could consider VFX Graph for rendering a lot of meshes, it's unlikely to be missing many features for that task