#How do I use shadergraph when working with Graphics.DrawMeshInstancedIndirect

1 messages · Page 1 of 1 (latest)

kind spire
#

I don't know how to receive buffers in shader graph. I've sent the data containing the info the mesh via a compute buffer but I'm just lost

flint creek
#

you have to delcare the buffer with identical name to what you set in a custom node

kind spire
# flint creek you have to delcare the buffer with identical name to what you set in a custom n...

#include "../../../Resources/Common.hlsl"
StructuredBuffer<float4x4> instanceMatrixBuffer;

void GetInstanceTRS_float(float InstanceID, float3 ObjectPosition, out float3 WorldPosition, out float3 WorldRotation, out float3 WorldScale)
{
float4x4 WorldTransform = instanceMatrixBuffer[(uint) InstanceID];
TRS trs = DecomposeMatrix(WorldTransform);
WorldPosition = trs.translation;
WorldRotation = float3(0, 0, 0);
WorldScale = trs.scale;
}

This is my hlsl file that I use in the custom function

#

C#, to bind the buffer to the shader
detailMaterials.SetBuffer("instanceMatrixBuffer", matrixOutputBuffer);

flint creek
#

i don't see anything particularly off there

kind spire
#

I haven't done anything wrong here right?

keen sparrow
#

Not sure if Instance ID node works with Indrect... I think it's only for regular DrawMeshInstanced. I've always just used unity_InstanceID in the code.

But for that to work you need to use the "procedural" instancing path, which involves adding the PROCEDURAL_INSTANCING_ON keyword and instancing_options pragma like so :
https://www.cyanilux.com/faq/#sg-drawmeshinstancedindirect

(That uses two custom function nodes, but newer versions have a "Use Pragmas" option in the custom function node settings so with that could use just one)

kind spire
kind spire
#

@keen sparrow
"Both functions here don’t alter the input passed in, but it is required to be able to connect the node to the Master Stack". how do I actually alter the position?

keen sparrow
#

The Grass.hlsl file linked at the bottom shows an example where the function set with the instancing options pragma alters the model matrix (and inverse) used by the graph behind the scenes.

But if you prefer, you can alternatively leave that function blank and index the buffer with unity_InstanceID in the custom function body - passing out the translation and add to the object space Position.

kind spire
#

I'm just now realizing that instancing is in no way shape or form taking place. I've got this little snippet

void CustomColorCheck_float(out float3 Col)
{
#if UNITY_ANY_INSTANCING_ENABLED
    Col = float3(0,1,0);
#else
    Col = float3(1, 0, 0);
#endif
}

To change the color depending on whether or not instancing is taking place and while the mesh is being drawn (everything in a single place), it's color is red. If it were using instancing, the color would, theoretically, be green. I'll see what I'm doing wrong and try to fix this

kind spire
#

Nevermind. It wasn't working because I had put in your modifying matrices code in vertInstancingSetup. Commenting it out put my object where I expected it to be and gave me the green I was looking for. I guess I just have to now figure out how to apply the matrix data that I imported

kind spire
#

@keen sparrow is there anything I need to do to ensure my compute buffer is being sent to the material? I had assigned a few colors to test the buffer working but they come out white when the color I set is (0,1, something random)

keen sparrow