Move shader files to Shaders group
This commit is contained in:
parent
cce59a45dc
commit
8e2a873edf
3 changed files with 10 additions and 2 deletions
61
Terrain2/Shaders/Shaders.metal
Normal file
61
Terrain2/Shaders/Shaders.metal
Normal file
|
@ -0,0 +1,61 @@
|
|||
//
|
||||
// Shaders.metal
|
||||
// Terrain2
|
||||
//
|
||||
// Created by Eryn Wells on 11/3/18.
|
||||
// Copyright © 2018 Eryn Wells. All rights reserved.
|
||||
//
|
||||
|
||||
// File for Metal kernel and shader functions
|
||||
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
// Including header shared between this Metal shader code and Swift/C code executing Metal API commands
|
||||
#import "ShaderTypes.h"
|
||||
|
||||
using namespace metal;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float3 position [[attribute(VertexAttributePosition)]];
|
||||
float2 texCoord [[attribute(VertexAttributeTexcoord)]];
|
||||
uint2 gridCoord [[attribute(VertexAttributeGridCoord)]];
|
||||
} Vertex;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float4 position [[position]];
|
||||
float2 texCoord;
|
||||
} ColorInOut;
|
||||
|
||||
vertex ColorInOut vertexShader(Vertex in [[stage_in]],
|
||||
texture2d<float> heights [[texture(0)]],
|
||||
constant Uniforms & uniforms [[buffer(BufferIndexUniforms)]])
|
||||
{
|
||||
constexpr sampler s(coord::normalized, address::clamp_to_zero, filter::linear);
|
||||
|
||||
ColorInOut out;
|
||||
|
||||
float4 height = heights.sample(s, in.texCoord);
|
||||
|
||||
// Replace the y coordinate with the height we read from the texture.
|
||||
float4 position(in.position.x, height.r, in.position.z, 1.0);
|
||||
out.position = uniforms.projectionMatrix * uniforms.modelViewMatrix * position;
|
||||
out.texCoord = in.texCoord;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
fragment float4 fragmentShader(ColorInOut in [[stage_in]],
|
||||
constant Uniforms & uniforms [[ buffer(BufferIndexUniforms) ]],
|
||||
texture2d<half> colorMap [[ texture(TextureIndexColor) ]])
|
||||
{
|
||||
constexpr sampler colorSampler(mip_filter::linear,
|
||||
mag_filter::linear,
|
||||
min_filter::linear);
|
||||
|
||||
half4 colorSample = colorMap.sample(colorSampler, in.texCoord.xy);
|
||||
|
||||
return float4(1.0);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue