问题
Hello I am using compute shader for updating heights of terrain. I store data in 1D array. I would like to access individual elements of array in compute shader. Is it possible?
#type compute
#version 430
//Size of compute shader local work group - x=32, y=32, z=1(default)
layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in;
layout(std430, binding = 0) buffer
buffer_InPos
{
vec4 InPos[];
};
layout(std430, binding = 1) buffer
buffer_InNormal
{
vec4 InNormal[];
};
uniform vec2 u_BrushPosition;
uniform float u_Radius;
uniform float u_Strength;
bool IsInRadius(vec4 pos)
{
if ((pos.x - u_BrushPosition.x) * (pos.x - u_BrushPosition.x) +
(pos.z - u_BrushPosition.y) * (pos.z - u_BrushPosition.y) <= u_Radius * u_Radius)
return true;
else return false;
}
void main(void)
{
uint index = gl_GlobalInvocationID.x + gl_GlobalInvocationID.y * gl_NumWorkGroups.x * gl_WorkGroupSize.y;
vec4 pos = InPos[index];
vec4 normal = InNormal[index];
if (IsInRadius(pos))
{
pos.y += u_Strength;
}
InPos[index] = pos;
}
I am just learning about compute shaders.
来源:https://stackoverflow.com/questions/59795868/how-to-index-array-in-compute-shader