|
| 1 | +// This is a minimal example of a custom shader you can import into ShaderGlass |
| 2 | +// Full specification and examples can be found at https://github.com/libretro/slang-shaders/blob/master/README.md |
| 3 | + |
| 4 | +#version 450 |
| 5 | + |
| 6 | +////////////////////////////////////////////////////////////////// |
| 7 | +// you can define parameters of your shader in this section |
| 8 | + |
| 9 | +#pragma parameter Boost "Boost" 1.0 0.0 2.0 0.1 |
| 10 | + |
| 11 | +layout(push_constant) uniform Push |
| 12 | +{ |
| 13 | + // built-in parameters |
| 14 | + vec4 SourceSize; |
| 15 | + vec4 OriginalSize; |
| 16 | + vec4 OutputSize; |
| 17 | + uint FrameCount; |
| 18 | + |
| 19 | + // your custom parameters |
| 20 | + float Boost; |
| 21 | +} params; |
| 22 | + |
| 23 | +layout(std140, set = 0, binding = 0) uniform UBO |
| 24 | +{ |
| 25 | + mat4 MVP; |
| 26 | +} global; |
| 27 | + |
| 28 | +////////////////////////////////////////////////////////////////// |
| 29 | +// vertex shader, you usually don't need to modify it |
| 30 | + |
| 31 | +#pragma stage vertex |
| 32 | + |
| 33 | +layout(location = 0) in vec4 Position; |
| 34 | +layout(location = 1) in vec2 TexCoord; |
| 35 | +layout(location = 0) out vec2 vTexCoord; |
| 36 | + |
| 37 | +void main() |
| 38 | +{ |
| 39 | + gl_Position = global.MVP * Position; |
| 40 | + vTexCoord = TexCoord; |
| 41 | +} |
| 42 | + |
| 43 | +////////////////////////////////////////////////////////////////// |
| 44 | +// fragment shader is where you define per-pixel operations |
| 45 | + |
| 46 | +#pragma stage fragment |
| 47 | + |
| 48 | +layout(location = 0) in vec2 vTexCoord; |
| 49 | +layout(location = 0) out vec4 FragColor; |
| 50 | +layout(set = 0, binding = 2) uniform sampler2D Source; |
| 51 | + |
| 52 | +void main() |
| 53 | +{ |
| 54 | + // this is the input pixel |
| 55 | + vec3 input_pixel = texture(Source, vTexCoord).rgb; |
| 56 | + |
| 57 | + // as an example, we swap RGB channels of the input image (rgb -> gbr) |
| 58 | + // and multiply by our custom Boost parameter |
| 59 | + vec3 processed_pixel = input_pixel.gbr * params.Boost; |
| 60 | + |
| 61 | + // set output pixel (aka fragment) color |
| 62 | + FragColor = vec4(processed_pixel, 1.0); |
| 63 | +} |
0 commit comments