![]() |
Vireo
0.0
Vireo 3D Rendering Hardware Interface
|
We will use the Slang shader language to write our shaders. By using Slang we will have only one code for all the supported graphics API.
The CMakeLists.txt
file supports the compilation of the shaders in the SPIR-V and DXIL intermediates formats.
Add a new shaders
directory under the src
directory, then add a new triangle_color.slang
file into the src/shaders
directory with the following content :
The POSITION
and COLOR
attributes in the VertexInput
struct refers to the fields of the vertexAttributes
array. Since Vulkan does not use textual attributes names but binding indices the fields must be in the same order in the struct and in the array.
The fragment shader uses the vertex color to produce a nice RGB gradient (the GPU calculates the color interpolation for each fragment/pixel from the vertices colors).
Reload the CMake project to add the new shader code to the list of shaders to compile then build the shaders
target.
If you look into the shaders
directory in the root of your project you will see four files with the compiled vertex and fragment shaders, both in SPIR-V and DXIL :
Now we can load the shaders in our onInit()
method, just after the vertex layout creation :
Next : Pipeline creation
Related manual page : Shaders