Add shaders for marching squares
This commit is contained in:
parent
1699e3ae14
commit
b2f19dffbf
4 changed files with 80 additions and 9 deletions
45
MetaballsKit/MarchingSquares.metal
Normal file
45
MetaballsKit/MarchingSquares.metal
Normal file
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
// MarchingSquares.metal
|
||||
// Metaballs
|
||||
//
|
||||
// Created by Eryn Wells on 10/14/18.
|
||||
// Copyright © 2018 Eryn Wells. All rights reserved.
|
||||
//
|
||||
|
||||
#include <metal_stdlib>
|
||||
#include "ShaderTypes.hh"
|
||||
using namespace metal;
|
||||
|
||||
struct Rect {
|
||||
float4x4 transform;
|
||||
float4 color;
|
||||
};
|
||||
|
||||
struct RasterizerData {
|
||||
float4 position [[position]];
|
||||
float4 color;
|
||||
float2 textureCoordinate;
|
||||
};
|
||||
|
||||
vertex RasterizerData
|
||||
gridVertexShader(constant Vertex *vertexes [[buffer(0)]],
|
||||
constant Rect *rects [[buffer(1)]],
|
||||
constant RenderParameters &renderParameters [[buffer(2)]],
|
||||
uint vid [[vertex_id]],
|
||||
uint instid [[instance_id]])
|
||||
{
|
||||
Vertex v = vertexes[vid];
|
||||
|
||||
Rect rect = rects[instid];
|
||||
|
||||
RasterizerData out;
|
||||
out.position = renderParameters.projection * rect.transform * float4(v.position.xy, 0, 1);
|
||||
out.textureCoordinate = v.textureCoordinate;
|
||||
return out;
|
||||
}
|
||||
|
||||
fragment float4
|
||||
gridFragmentShader(RasterizerData in [[stage_in]])
|
||||
{
|
||||
return in.color;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue