Writing fragment shaders
Fragments (or pixels) are parts of the image that can be potentially displayed on screen. They are created from geometry (drawn primitives) in a process called rasterization. They have specific screen space coordinates (x, y, and depth) but don't have any other data. We need to write a fragment shader to specify the color that needs to be displayed on screen. In the fragment shader, we can also select an attachment into which a given color should be written.
How to do it...
- Create a text file. Select a name for the file, but use a
frag
extension for it (for example,shader.frag
). - Insert
#version 450
in the first line of the file. - Define a set of input variables (attributes) that are provided from the earlier pipeline stages. For each input variable:
- Define its location with a location layout qualifier and an index of the attribute:
layout( location = <index> )
- Provide an
in
storage qualifier - Specify the type of input variable (such as
vec4
,float
,ivec3
) - Provide a...
- Define its location with a location layout qualifier and an index of the attribute: