AppendStructuredBuffer::GetDimensions

Started by
2 comments, last by ruben67 9 months, 2 weeks ago

I'm trying to move my marching cubes implementation to a compute shader in UE5.2. Basically I generate the vertex/triangle data in the shader and send it back to the CPU where I use the Runtime Mesh Component to render it. As a ‘warm up’ I'm experimenting with just generating a flat plane of quads:

#include "/Engine/Public/Platform.ush"

struct VertexData
{
	float3 Position;
	float3 Normal;
	float3 Tangent;
	float2 UV;
};

AppendStructuredBuffer<VertexData> OutputVertexData;
AppendStructuredBuffer<int> OutputTriangleData;

float QuadSize;
uint2 Dimensions;

[numthreads(THREADGROUPSIZE_X, THREADGROUPSIZE_Y, THREADGROUPSIZE_Z)]
void GenerateMeshData(uint3 ID : SV_DispatchThreadID)
{
	if (ID.x >= Dimensions.x || ID.y >= Dimensions.y)
	{
		return;
	}
	
	float3 BottomLeftPos = { ID.x * QuadSize, ID.y * QuadSize, 0 };
	float3 BottomRightPos = { (ID.x+1) * QuadSize, ID.y * QuadSize, 0 };
	float3 TopLeftPos = { ID.x * QuadSize, (ID.y+1) * QuadSize, 0 };
	float3 TopRightPos = { (ID.x+1) * QuadSize, (ID.y+1) * QuadSize, 0 };

	float3 QuadNormal = { 0, 0, 1 };
	float3 QuadTangent = { 1, 0, 0 };
	float2 UVPos = { 0, 0 };

	VertexData BottomLeft;
	BottomLeft.Position = BottomLeftPos;
	BottomLeft.Normal = QuadNormal;
	BottomLeft.Tangent = QuadTangent;
	BottomLeft.UV = UVPos;
	
	VertexData BottomRight;
	BottomRight.Position = BottomRightPos;
	BottomRight.Normal = QuadNormal;
	BottomRight.Tangent = QuadTangent;
	BottomRight.UV = UVPos;
	
	VertexData TopLeft;
	TopLeft.Position = TopLeftPos;
	TopLeft.Normal = QuadNormal;
	TopLeft.Tangent = QuadTangent;
	TopLeft.UV = UVPos;
	
	VertexData TopRight;
	TopRight.Position = TopRightPos;
	TopRight.Normal = QuadNormal;
	TopRight.Tangent = QuadTangent;
	TopRight.UV = UVPos;
	
	int BottomLeftIndex;
	int Stride;
	OutputVertexData.GetDimensions(BottomLeftIndex, Stride);

	// Append vertices to output 
	OutputVertexData.Append(BottomLeft);
	OutputVertexData.Append(BottomRight);
	OutputVertexData.Append(TopLeft);
	OutputVertexData.Append(TopRight);

	// Triangle 1
	OutputTriangleData.Append(BottomLeftIndex);	
	OutputTriangleData.Append(BottomLeftIndex+1);	
	OutputTriangleData.Append(BottomLeftIndex+2);

	// Triangle 2
	OutputTriangleData.Append(BottomLeftIndex);	
	OutputTriangleData.Append(BottomLeftIndex+2);	
	OutputTriangleData.Append(BottomLeftIndex+3);	
}

To find the vertex indices for the triangle buffer I'm trying to use AppendStructuredBuffer::GetDimensions(), but it gives me the following error when compiling:

/CustomComputeShaders/GenerateMeshDataCS.usf(60,19): error: no matching member function for call to 'GetDimensions'
	        OutputVertexData.GetDimensions(BottomLeftIndex, Stride);

Any ideas on why GetDimensions() doesn't exist, or suggestions on how I should approach this differently? I've read something about buffer counters but can't figure out how they work (least of all in UE because of complete lack of documentation).

Advertisement

GetDimensions uses „uint“ as out paramters. You are passing it „int“. unlike return-statement, there is no automatic conversion for out parameters and the types have to match exactly.

@Juliean Thank you!

This topic is closed to new replies.

Advertisement