From 99739a5d63379068de523388de9e6b9703cc4a2c Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 30 Jul 2017 20:40:10 -0700 Subject: [PATCH] [Metaballs] Fragment shader, stubs for vertex and sample shaders --- Metaballs/Shaders.metal | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Metaballs/Shaders.metal b/Metaballs/Shaders.metal index 8e3998b..f914070 100644 --- a/Metaballs/Shaders.metal +++ b/Metaballs/Shaders.metal @@ -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; +}