[Metaballs] Fragment shader, stubs for vertex and sample shaders
This commit is contained in:
parent
fc57f865f2
commit
99739a5d63
1 changed files with 39 additions and 0 deletions
|
@ -21,3 +21,42 @@ sampleFieldKernel(const device Ball* metaballs [[buffer(0)]],
|
|||
{
|
||||
// TODO: Compute a sample for this pixel given the field data, and write it to the out texture.
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
float2 position;
|
||||
float2 textureCoordinate;
|
||||
} VertexIn;
|
||||
|
||||
// From HelloCompute sample code project.
|
||||
// Vertex shader outputs and per-fragmeht inputs. Includes clip-space position and vertex outputs interpolated by rasterizer and fed to each fragment genterated by clip-space primitives.
|
||||
typedef struct {
|
||||
// The [[position]] attribute qualifier of this member indicates this value is the clip space position of the vertex when this structure is returned from the vertex shader.
|
||||
float4 position [[position]];
|
||||
|
||||
// Since this member does not have a special attribute qualifier, the rasterizer will interpolate its value with values of other vertices making up the triangle and pass that interpolated value to the fragment shader for each fragment in that triangle;
|
||||
float2 textureCoordinate;
|
||||
} RasterizerData;
|
||||
|
||||
//vertex RasterizerData
|
||||
//passthroughVertexShader(uint vertexID [[vertex_id]])
|
||||
//{
|
||||
// // TODO: Nothing really. Just pass on through to the fragment shader.
|
||||
//}
|
||||
|
||||
fragment float4
|
||||
sampleToColorShader(RasterizerData in [[stage_in]],
|
||||
constant float* samples [[buffer(0)]],
|
||||
constant float2* size [[buffer(1)]])
|
||||
{
|
||||
int index = in.textureCoordinate.y * size->y + in.textureCoordinate.x;
|
||||
float sample = samples[index];
|
||||
|
||||
float4 out;
|
||||
if (sample > 1.0) {
|
||||
out = float4(0.0, 1.0, 0.0, 0.0);
|
||||
}
|
||||
else {
|
||||
out = float4(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue