NOTE: Post-tessellation vertex function outputs are the same as a regular vertex
function.
4.3.4.4
Fragment Function Input Attributes
Table 12 lists the built-in attributes that can be specified for arguments of a fragment function
(and their corresponding data types).
NOTE: If the return type of a vertex function is not
void
, it must include the vertex
position. If the vertex return type is
float4
this always refers to the vertex position (and
the
[[position]]
attribute need not be specified). If the vertex return type is a struct, it
must include an element declared with the
[[position]]
attribute.
Table 12 Attributes for Fragment Function Input Arguments
Attribute
Corresponding Data
Types
Description
[[color(m)]]
floatn
,
halfn
,
intn
,
uintn
,
shortn
or
ushortn
m
must be known at
compile time
The input value read from a color
attachment. The index
m
indicates
which color attachment to read
from.
[[front_facing]]
bool
This value is
true
if the fragment
belongs to a front-facing primitive.
[[point_coord]]
float2
Two-dimensional coordinates
indicating where within a point
primitive the current fragment is
located. They range from 0.0 to 1.0
across the point.
[[position]]
float4
Describes the window relative
coordinate (x, y, z, 1/w) values for the
fragment.
[[sample_id]]
uint
The sample number of the sample
currently being processed.
[[sample_mask]]
uint
The set of samples covered by the
primitive generating the fragment
during multisample rasterization.
2017-9-12 | Copyright © 2017 Apple Inc. All Rights Reserved.
Page of
71
174
A variable declared with the
[[position]]
attribute as input to a fragment function can only be
declared with the
center_no_perspective
sampling and interpolation attribute. (See section
4.5.)
For
[[color(m)]]
,
m
is used to specify the color attachment index when accessing (reading or
writing) multiple color attachments in a fragment function. The
[[color(m)]]
attribute is only
supported in iOS.
The
[[sample_mask]]
attribute can only be declared once for a fragment function input.
The
[[render_target_array_index]]
and
[[viewport_array_index]]
attributes are only
available for macOS. For more details about
[[viewport_array_index]]
, see section 4.11.
Table 13 lists attributes that can be specified for tile arguments that are input to a fragment
function in iOS. The data types used to declare
[[pixel_position_in_tile]]
and
[[pixels_per_tile]]
must match.
Attribute_Corresponding_Data_Types_Description'>Attribute_Corresponding_Data_Types_Description__2017-9-12_|_Copyright_©_2017_Apple_Inc._All_Rights_Reserved._Page_of'>Attributes_for_Fragment_Function_Tile_Input_Arguments'>Table 13 Attributes for Fragment Function Tile Input Arguments
[[sample_mask,
post_depth_coverage]]
uint
The set of samples covered by the
primitive generating the fragment
after application of the early depth
and stencil tests during multisample
rasterization. The
[[early_fragment_tests]]
specifier must be used on the
fragment function; otherwise the
compilation fails.
[[render_target_
array_index]]
uchar
,
ushort
or
uint
The render target array index. This
refers to the face of a cubemap, an
array slice of a texture array, or an
array slice, face of a cubemap array.
For a cubemap the render target
array index is the face index, which is
a value from 0 to 5. For a cubemap
array the render target array index is
computed as: array slice index * 6 +
face index.
[[viewport_array_
index]]
uint
The viewport (and scissor rectangle)
index value of the primitive.
Attribute
Corresponding Data
Types
Description
2017-9-12 | Copyright © 2017 Apple Inc. All Rights Reserved.
Page of
72
174
[[tile_index]]
is a value from [0, n), where n is the number of tiles in the render target.
4.3.4.5
Fragment Function Output Attributes
The return type of a fragment function describes the per-fragment output. A fragment function
can output one or more render-target color values, a depth value, and a coverage mask, which
must be identified by using the attributes listed in Table 14. If the depth value is not output by
the fragment function, the depth value generated by the rasterizer is output to the depth
attachment.
Table 14 Attributes for Fragment Function Return Types
The color attachment index
m
for fragment output is specified in the same way as it is for
[[color(m)]]
for fragment input (see discussion for Table 12). Multiple elements in the
fragment function return type that use the same color attachment index for blending must be
declared with the same data type.
If there is only a single color attachment in a fragment function, then
[[color(m)]]
is optional.
If
[[color(m)]]
is not specified, the attachment index is 0. If multiple color attachments are
specified,
[[color(m)]]
must be specified for all color values. See examples of specifying the
color attachment in sections 4.6 and 4.7.
If
index(i)
is not specified in the attribute, an index of 0 is assumed. If
index(i)
is specified,
the value of
i
must be known at compile time.
Attribute
Corresponding Data
Types
Description
[[pixel_position_in_tile]] ushort2
or
uint2
(x, y) position of the fragment in
the tile.
[[pixels_per_tile]]
ushort2
or
uint2
(width, height) of the tile in
pixels.
[[tile_index]]
ushort
or
uint
1D tile index.
Attribute
Corresponding Data Types
[[color(m)]]
[[color(m), index(i)]]
floatn
,
halfn
,
intn
,
uintn
,
shortn
or
ushortn
m
is the color attachment index and must be known at
compile time. The index
i
can be used to specify one or
more colors output by a fragment function for a given
color attachment and is an input to the blend equation.
[[depth(depth_argument)]]
float
[[sample_mask]]
uint
2017-9-12 | Copyright © 2017 Apple Inc. All Rights Reserved.
Page of
73
174
Dostları ilə paylaş: |