Hi everyone,
I’m working on a custom Instanced Mesh Component for a grass system. I’m using a Compute Shader to calculate instance transforms and a Custom Vertex Factory to render them.
The Goal:
I initially had the grass rendering correctly, but it didn’t support Virtual Shadow Maps (VSM). I learned that to support VSM (and GPUScene), my Vertex Factory needs to support the PrimitiveIdStream (Attribute 13).
The Problem:
After modifying my Vertex Factory to include PrimitiveIdStream and updating the compilation environment, the grass instances are now rendering incorrectly (flying around / wrong transforms), as shown in the video.
I suspect the issue lies in a conflict between SV_InstanceID and UE5’s internal macros.
- To support GPUScene, I use:
VF_GPUSCENE_DECLARE_INPUT_BLOCK(13)
-
This macro internally declares
uint DrawInstanceId : SV_InstanceID;. -
However, I also need
SV_InstanceIDto index my local StructuredBuffer (Manual Vertex Fetch). -
If I try to manually declare
uint InstanceId : SV_InstanceID;alongside the macro, I get a shader compiler error (overlapping semantics). -
If I remove my manual declaration and use the
InstanceIdprovided by the macro, the transforms are incorrect (which leads to the artifacts in the video).
Question:
Has anyone successfully implemented a custom VF that uses both manual vertex fetch (from a local buffer) AND supports GPUScene/PrimitiveID?
How should I correctly access the SV_InstanceID (or equivalent) to index my local buffer when VF_GPUSCENE_DECLARE_INPUT_BLOCK is active? Do I need to apply a specific offset (like BatchElement.UserIndex) manually?
Any help or guidance would be greatly appreciated! I’ve been stuck on this for a few days.
Thanks!

