How to enable GPU instancing and disable SRPbatcher?

I’ve just installed Unity 6.0. I want to draw 2 cubes using GPU instancing (just to test things out).
I know that to enable GPU instancing I have to disable SRPBatcher. There is a manual how to do this:

but I have to be too dumb to understand it.

I decided to use Removing shader compatibility because I don’t know how to add a MaterialPropertyBlock to the renderer. since I just want to add 2 cubes and use the same material.

Manual says this:

To make a Unity shader incompatible with the SRP Batcher, you need to make changes to the shader source file:

  1. For hand-written shaders, open the shader source file. For Shader Graph shaders, copy the Shader Graph’s compiled shader source code into a new shader source file. Use the new shader source file in your application instead of the Shader Graph.
  2. Add a new material property declaration into the shader’s Properties block. Don’t declare the new material property in the UnityPerMaterial constant buffer.

So I added 2 cubes, created a new Standard Surface Shader and a new material that uses that shader.

s

There are already some things that I don’t get:

  1. Why cubes are purple? It means something is wrong with the shader, but it’s a default one (on a fresh, just-installed Unity build)
  2. SRP Batcher is already set not compatible, so GPU instancing should work fine

Yes I have GPU Instancing checkbox set on the material.

when I open Frame Debugger (and also RenderDoc) cubes are renderer with 2 separate draw calls.

Why?

Check your console. Are there any errors reported after you modified the shader? It could be something as simple as a syntax error. As for GPU instancing, it’s probably because the shader is currently broken. No working shader - no instancing.

1 Like

There are no errors. Before and after I modified the shader (meaning that the default shader also gives me the “purple” result). The console is empty.

Silly question but does the unmodified version of the shader work for URP? Also, can you post what modification you made to it so we can see if there is anything wrong? You don’t need to post the whole shader, just the property you added.

The unmodified version of the shader also does not work.
I added the property like this:

_BreakBatcher ("_BreakBatcher", Range(0,1)) = 0.0

so the whole property block is just this:

Properties
{
    _Color ("Color", Color) = (1,1,1,1)
    _MainTex ("Albedo (RGB)", 2D) = "white" {}
    _Glossiness ("Smoothness", Range(0,1)) = 0.5
    _Metallic ("Metallic", Range(0,1)) = 0.0
    _BreakBatcher ("_BreakBatcher", Range(0,1)) = 0.0
}

I haven’t touched anything else.

The console log is empty:

for the reference, this happens when I intentionally do a syntax error:

That’s where the error if from : Surface Shaders don’t work with HDRP.

If you want a shader that reacts to lighting in HDRP, it’s better to user shadergraph, writing lit shaders from scratch is not an easy task.

Using the Material Property Block approach would probably be easier.

1 Like

image

1 Like