Skip to content

Instantly share code, notes, and snippets.

@edom18
Last active November 26, 2016 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edom18/275cbefd53a7d5d311fb to your computer and use it in GitHub Desktop.
Save edom18/275cbefd53a7d5d311fb to your computer and use it in GitHub Desktop.
[Metal] iOS Metalのちょっとしたメモ ref: http://qiita.com/edo_m18/items/5e03f7fa317b922b5a42
float4x4 mat = float4x4(float4( 1, 2, 3, 4),
float4( 5, 6, 7, 8),
float4( 9, 10, 11, 12),
float4(13, 14, 15, 16));
static const float mat[4][4] = {
{ 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9, 10, 11, 12},
{13, 14, 15, 16},
};
fragment half4 frag(VertexOut input [[stage_in]]) {
half4 color = half4(input.color);
// なにがしかの条件を判定する
if (anyCondition) {
discard_fragment();
}
return color;
}
struct VertexOut {
float4 position [[position]];
};
struct Uniforms {
float2 resolution;
};
fragment half4 frag(VertexOut input [[stage_in]],
constant Uniforms &uniforms [[buffer(0)]]) {
float2 position = (input.position.xy * 2.0 - uniforms.resolution) / min(uniforms.resolution.x, uniforms.resolution.y);
// ...
}
fragment half4 frag(VertexOut input [[stage_in]], constant Uniforms &uniforms [[buufer(0)]]) {
float2 resolution = float2(uniforms.resolution[0], uniforms.resolution[1]);
float2 position = (input.position.xy * 2.0 - resolution) / min(resolution.x, resolution.y);
return half4(position.x, position.y, 0.0, 1.0);
}
#ifdef GL_ES
precision mediump float;
#endif
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
void main( void ) {
vec2 position = ( gl_FragCoord.xy * 2.0 - resolution ) / min(resolution.x, resolution.y);
gl_FragColor = vec4(position, 0.0, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment