using ScriptableRenderPass to draw with per-object properties ?

I like that ScriptableRenderPass allow you to add effects to objects without having to modify their base shader.

Now I am looking for a way to make objects render an overlay, but in a different color for each object.

Inspired by the “Occluded Object Dither” from

Replicating the effect in the image below: I’d like to highlight each mesh in different color (in this case just different transparency/alpha for the light green dithered overlay on top of the plants)

I used to just build a CommandBuffer where I set Material.color before rendering each mesh, but Camera.AddCommandBuffer is deprecated in URP.

Is there a way to achieve something similar using the ScriptableRenderFeature / ScriptableRenderPass workflow in URP? A modified version of “RenderObjects” feature doesn’t allow you to get a property from each rendered object, does it? The call to context.DrawRenderers uses CullingResults, which doesn’t really allow you to get into specific properties of those renderers.

I was writing my own ScriptableRenderPass but I’m getting stuck trying to find an elegant way of making the connection between the rendering and some ‘custom’ properties on the rendered items…

@phil_lira , @Andre_Mcgrail Sorry to poke you directly, but I figured you must have some hunch about a decent approach for this.

I’ll copy Felipe’s reply from Twitter here, in case someone ends up in this thread with a similar question.

Regarding the solution mentioned above:

That would mean modifying the base shader of the objects. But I thought one of the goals of the ScriptableRenderFeatures was that you can add effects (outlines, highlights) on top of the scene without having to modify the base shader? What if my base shader is the standard URP Lit shader, how do I then add such an overlay?

Still hoping that @phil_lira or @Andre_Mcgrail might chime in again because this seems like a pretty common use case for the URP.

Hit the same wall as you. You could write a custom ScriptableRenderFeature with a custom ScriptableRenderPass where you have access to the ScriptableRenderPass’s execute method. In that execute method you could use the CommandBuffer.DrawRenderer to draw specific renderers with specific materials. However, CommandBuffer.DrawRenderer doesn’t have the ability to set the per-draw lighting data. So it would work as long as your material doesn’t care about lighting.

@noio

I agree, did you find a way to achieve the desired result ?

Nope. Not yet.

2 Likes

Just ended up using a custom shader with a MaterialPropertyBlock to set the glow amount.

Then I took out the MaterialPropertyBlock (because it breaks the URP Batcher)… Now I just have 10 different (cached) materials with different glow amounts… and I switch to the appropriate material.