|
Vulkan2D
2D renderer written in C using Vulkan and SDL2
|
Shaders are an advanced tool to allow users to create hardware-accelerated effects on images they draw to the screen. In Vulkan2D, shaders are required to be written in Slang and you may only provide a fragment (pixel) shader. Shaders in VK2D can be accessed via the vk2dSlangLoad and vk2dSlangFrom functions and eventually used with vk2dRendererDrawShader. Vulkan2D will take Slang source code and compile it when you call those functions, additionally validating that they are in the correct format. Shaders loaded in this way are expected to have a few bindings,
push of type Push.sampler of type SamplerState.textures of type Texture2D<float4>.ConstantBuffer.Vulkan2D will check that all of those types are present and in the right binding in your shader. The names of the bindings are required.
Users may provide their own input constants to shaders via the addition of another binding at 3,3, ie
If you do set one of these, be aware they are aligned as std430, basically meaning they are vec4 (16-byte) aligned. When you are using a user data block, you are expected to give a buffer identically structured from the C side when calling vk2dRendererDrawShader.
For example, if you had in your shader
the C-equivalent struct would be
Vulkan2D will find the size of your user data struct in the shader automatically.
This is a basic example shader that you could drop in your project and use as a base for your effect development.