[all] It works!
This commit is contained in:
parent
dfa603012f
commit
8dcd0910f1
4 changed files with 73 additions and 66 deletions
|
@ -24,12 +24,8 @@ typedef struct {
|
|||
float2 textureCoordinate;
|
||||
} RasterizerData;
|
||||
|
||||
typedef struct {
|
||||
int2 size;
|
||||
int numberOfBalls;
|
||||
} Parameters;
|
||||
|
||||
typedef half3 Ball;
|
||||
typedef int3 Parameters;
|
||||
typedef float3 Ball;
|
||||
|
||||
vertex RasterizerData
|
||||
passthroughVertexShader(uint vid [[vertex_id]],
|
||||
|
@ -42,20 +38,21 @@ passthroughVertexShader(uint vid [[vertex_id]],
|
|||
return out;
|
||||
}
|
||||
|
||||
float sampleAtPoint(float2, constant Ball*, uint);
|
||||
float sampleAtPoint(float2, constant Ball*, int);
|
||||
|
||||
fragment float4
|
||||
sampleToColorShader(RasterizerData in [[stage_in]],
|
||||
constant Parameters& parameters [[buffer(0)]],
|
||||
constant Ball* balls [[buffer(1)]])
|
||||
{
|
||||
const float sample = sampleAtPoint(in.textureCoordinate, balls, parameters.numberOfBalls);
|
||||
const uint numberOfBalls = parameters.z;
|
||||
const float sample = sampleAtPoint(in.position.xy, balls, numberOfBalls);
|
||||
|
||||
float4 out;
|
||||
if (sample > 1.0) {
|
||||
out = float4(0.0, 1.0, 0.0, 0.0);
|
||||
out = float4(0.0, 1.0, 0.0, 1.0);
|
||||
} else {
|
||||
out = float4(0.0, 0.0, 0.0, 0.0);
|
||||
out = float4(0.2, 0.2, 0.2, 1.0);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -63,11 +60,11 @@ sampleToColorShader(RasterizerData in [[stage_in]],
|
|||
float
|
||||
sampleAtPoint(float2 point,
|
||||
constant Ball* balls,
|
||||
uint count)
|
||||
int count)
|
||||
{
|
||||
float sample = 0.0;
|
||||
for (uint i = 0; i < count; i++) {
|
||||
constant Ball& ball = balls[i];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Ball ball = balls[i];
|
||||
float r2 = ball.z * ball.z; // Radius stored in z coordinate.
|
||||
float xDiff = point.x - ball.x;
|
||||
float yDiff = point.y - ball.y;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue