My mesh (as a graphicsbuffer) has half2 vertices. so the stride is 4.
ensure this compute shader does all the conversion to/from float properly
#pragma kernel UpdatePositions
#pragma kernel Spawn
#define VERTEX_32BIT_STRIDE 3 // float3 position
#include ”../ShaderLibrary/RemapUtils.hlsl”
#include ”../ShaderLibrary/SamplingUtils.hlsl”
#include ”../ShaderLibrary/SpawnUtils.hlsl”
float DT;
float Step;
float Multiplier;
float3 Bounds_Min;
float3 Bounds_Max;
//uint Slice;
//uint Range;
int _VertexBufferStride;
int _VertexBufferPosAttributeOffset;
RWByteAddressBuffer _VertexBuffer;
Texture2D Vel_Tex;
SamplerState samplerVel_Tex;
int res2D;
float3 GetPos3D(uint i)
{
return asfloat(_VertexBuffer.Load3(i * _VertexBufferStride + _VertexBufferPosAttributeOffset));
}
min16float2 GetPos2D(uint i)
{
return min16float2( asfloat(_VertexBuffer.Load2(i * _VertexBufferStride + _VertexBufferPosAttributeOffset)));
}
void SetPos3D(uint i, float3 position)
{
// Buffer index is accessed by byte offset, so 4 for each 32bit value (float,int,uint…).
_VertexBuffer.Store3( i * _VertexBufferStride, asuint( position ) );
}
void SetPos2D(uint i, half2 position)
{
// Buffer index is accessed by byte offset, so 4 for each 32bit value (float,int,uint…).
_VertexBuffer.Store2( i * _VertexBufferStride, asuint( position ) );
}
float3 Random_Position3D(const uint id)
{
float2 pos = RandomPointInRectangle(id, Bounds_Min.xz, Bounds_Max.xz) ;
return float3(pos.x, 0, pos.y);
}
half2 Random_Position2D(const uint id)
{
float2 pos = RandomPointInRectangle(id, Bounds_Min.xz, Bounds_Max.xz) ;
return half2(pos.xy);
}
[numthreads(32, 32, 1)]
void UpdatePositions (uint2 id : SV_DispatchThreadID)
{
uint ID = id.x + res2D * id.y;
half2 raw2 = GetPos2D(ID);
// float3 raw = GetPos3D(ID);
float2 rm = remap(Bounds_Min.xz, Bounds_Max.xz, 0, 1, float2(raw2.x, raw2.y));
float2 newPos = rm + Multiplier * Integrate_RK4(Vel_Tex, samplerVel_Tex, rm, Step) * DT;
float2 rm2 = remap(0,1,Bounds_Min.xz, Bounds_Max.xz, newPos.xy);
half2 result = half2((half)rm2.x, (half)rm2.y);
}
[numthreads(32,32,1)]
void Spawn (uint2 id : SV_DispatchThreadID)
{
uint ID = id.x + res2D * id.y;
//SetPos3D(ID, Random_Position3D(ID));
SetPos2D(ID, Random_Position2D(ID));
}