Skip to content

Instantly share code, notes, and snippets.

@zeux zeux/shader.cpp Secret
Created Jun 2, 2014

What would you like to do?
Metal example shader from the documentation
#include <metal_stdlib>
using namespace metal;
struct VertexOutput {
float4 position [[position]];
float4 color;
float2 texcoord;
struct VertexInput {
float4 position;
float3 normal;
float2 texcoord;
constexpr constant uint MAX_LIGHTS = 4;
struct LightDesc {
uint num_lights;
float4 light_position[MAX_LIGHTS];
float4 light_color[MAX_LIGHTS];
float4 light_attenuation_factors[MAX_LIGHTS];
vertex VertexOutput
render_vertex(const global VertexInput* v_in [[ buffer(0) ]],
constant float4x4& mvp_matrix [[ buffer(1) ]],
constant LightDesc& light_desc [[ buffer(2) ]],
global float4* xform_pos_output [[ buffer(3) ]],
uint v_id [[ vertex_id ]] )
VertexOutput v_out;
v_out.position = v_in[v_id].position * mvp_matrix;
v_out.color = do_lighting(v_in[v_id].position,
v_out.texcoord = v_in[v_id].texcoord;
// output position to a buffer
xform_pos_output[v_id] = v_out.position;
return v_out;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.