This demo demoncetrates how to make a simple quad with 6 vertices and get 2 triangle of them, and finally sample a texture on it!
Custom Render Pipeline
A vertex function generates data for a single vertex and a fragment function generates data for a single fragment, but you decide how they work. You configure the stages of the pipeline with a goal in mind, meaning that you know what you want the pipeline to generate and how it generates those results.
Decide what data to pass into your render pipeline and what data is passed to later stages of the pipeline. There are typically three places where you do this:
The inputs to the pipeline, which are provided by your app and passed to the vertex stage.
The outputs of the vertex stage, which is passed to the rasterization stage.
The inputs to the fragment stage, which are provided by your app or generated by the rasterization stage.
In this sample, the input data for the pipeline is the position of a vertex and its color. To demonstrate the kind of transformation you typically perform in a vertex function, input coordinates are defined in a custom coordinate space, measured in pixels from the center of the view. These coordinates need to be translated into Metal’s coordinate system.
Declare an AAPLVertex structure, using SIMD vector types to hold the position and color data. To share a single definition for how the structure is laid out in memory, declare the structure in a common header and import it in both the Metal shader and the app.
typedef struct
{
vector_float4 position;
vector_float2 tex_coordinate;
} AAPLVertex;
source: Apple
using
time += view.preferredFramesPerSecond;
to rotate the quad around the z axis (0,0,1)
using simple transformation matrix to pass it to the vertex shader to calculaute new rotate pixels
SRT
simd::float4x4 transformationMatrix = Math::scale(1.5, 1.5, 1) * Math::rotate(time/60, 0, 0, 1) * AAPL::Math::translate(-0.0, 0.3, .0) ;