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;
|
||||
}
|
||||
24
MetaballsKit/ShaderTypes.hh
Normal file
24
MetaballsKit/ShaderTypes.hh
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// ShaderTypes.h
|
||||
// Metaballs
|
||||
//
|
||||
// Created by Eryn Wells on 10/14/18.
|
||||
// Copyright © 2018 Eryn Wells. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef ShaderTypes_hh
|
||||
#define ShaderTypes_hh
|
||||
|
||||
#include <metal_stdlib>
|
||||
|
||||
struct Vertex {
|
||||
float2 position;
|
||||
float2 textureCoordinate;
|
||||
};
|
||||
|
||||
struct RenderParameters {
|
||||
/// Projection matrix.
|
||||
metal::float4x4 projection;
|
||||
};
|
||||
|
||||
#endif /* ShaderTypes_hh */
|
||||
|
|
@ -7,13 +7,9 @@
|
|||
//
|
||||
|
||||
#include <metal_stdlib>
|
||||
#include "ShaderTypes.hh"
|
||||
using namespace metal;
|
||||
|
||||
struct Vertex {
|
||||
float2 position;
|
||||
float2 textureCoordinate;
|
||||
};
|
||||
|
||||
// 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.
|
||||
struct RasterizerData {
|
||||
|
|
@ -43,10 +39,6 @@ struct Parameters {
|
|||
float3x3 colorTransform;
|
||||
};
|
||||
|
||||
struct RenderParameters {
|
||||
float4x4 projection;
|
||||
};
|
||||
|
||||
typedef float3 Ball;
|
||||
|
||||
#pragma mark - Vertex
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue