Metal example shader from the documentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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_in[v_id].normal, | |
light_desc); | |
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