}
4.7.4
Imageblocks and Function Constants
Use of
[[function_constant(name)]]
is unsupported with data members of an imageblock
struct that is either passed as inputs to or returned as output from a fragment or kernel function.
4.8 Programmable Blending
The fragment function can be used to perform per-fragment or per-sample programmable
blending. The color attachment index identified by the
[[color(m)]]
attribute can be specified
as an argument to a fragment function.
Below is an OpenGL ES programmable blending example that describes how to paint grayscale
onto what is below.
The GLSL version is:
#extension GL_APPLE_shader_framebuffer_fetch :
require
void main()
{
//
RGB to grayscale
mediump float lum = dot(gl_LastFragData[0].rgb, vec3(0.30,0.59,0.11));
gl_FragColor = vec4(lum, lum, lum, 1.0);
}
The Metal version equivalent is:
fragment half4
paint_grayscale(half4 dst_color [[color(0)]])
{
// RGB to grayscale
half lum = dot(dst_color.rgb, half3(0.30h, 0.59h, 0.11h));
return half4(lum, lum, lum, 1.0h);
}
4.9 Graphics Function – Signature Matching
A graphics function signature is a list of parameters that are either input to or output from a
graphics function.
2017-9-12 | Copyright © 2017 Apple Inc. All Rights Reserved.
Page of
91
174