im trying to render a large amount of meshes using graphics.rendermeshindirect
each mesh has its own objecttoworld matrix and color, i am storing them in compute buffers as the amount can be of any size. i tried following this tutorial and modifying it for arrays, but the result is this..
here is how i am setting the buffers.
and ofcourse, the shader code
Shader "MyShader"
{
Properties{}
SubShader
{
Pass
{
Tags
{
"RenderType"="Opaque"
"RenderPipeline" = "UniversalRenderPipeline"
}
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
StructuredBuffer<float4x4> Objects;
StructuredBuffer<float4> Colors;
float4 color_buffer[8];
struct attributes
{
float3 normal : NORMAL;
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR;
};
struct varyings
{
float4 vertex : SV_POSITION;
float4 color : COLOR0;
};
varyings vert(attributes v, const uint instance_id : SV_InstanceID)
{
const float4 pos = mul(Objects[instance_id], v.vertex);
varyings o;
o.vertex = mul(UNITY_MATRIX_VP, pos);
o.color = Colors[instance_id];
return o;
}
half4 frag(varyings i) : SV_Target
{
return i.color;
}
ENDHLSL
}
}
}

