R2 Core Shaders

R2Stipple.h
Go to the documentation of this file.
1 #ifndef R2_STIPPLE_H
2 #define R2_STIPPLE_H
3
4 /// \file R2Stipple.h
5 /// \brief Stippling types and functions
6
7 #include "R2Viewport.h"
8
9 /// The type of stippling parameters.
10
11 struct R2_stipple_t {
12 /// A texture giving the stippling pattern. This texture is typically
13 /// tiled over the whole screen.
14 sampler2D pattern;
15 /// A scaling value for the noise texture UV coordinates
16 vec2 pattern_uv_scale;
17 /// A stippling threshold; The stippling algorithm discards pixels
18 /// with a stipple values less than this threshold. 0.0 discards no pixels,
19 /// 1.0 discards all pixels.
20 float threshold;
21 };
22
23 bool
24 R2_stippleRun(
25 const R2_stipple_t stipple,
26 const R2_viewport_t viewport,
27 const vec2 frag_coord)
28 {
29 // Tile the noise texture across the screen and sample it
30 // The sample is discarded if the sampled stipple value is less than the
31 // given stipple threshold.
32 vec2 screen_uv =
33 R2_viewportFragmentPositionToUV (viewport, frag_coord);
34 vec2 noise_uv =
35 screen_uv * stipple.pattern_uv_scale;
36 float noise_sample =
37 texture(stipple.pattern, noise_uv).r;
38 return noise_sample < stipple.threshold;
39 }
40
41 #endif // R2_STIPPLE_H
R2_stipple_t::threshold
float threshold
Definition: R2Stipple.h:20
R2Viewport.h
Viewport types and functions.
R2_viewport_t
The type of viewports.
Definition: R2Viewport.h:9
R2_stipple_t::pattern_uv_scale
vec2 pattern_uv_scale
A scaling value for the noise texture UV coordinates.
Definition: R2Stipple.h:16
R2_stipple_t::pattern
sampler2D pattern
Definition: R2Stipple.h:14
R2_viewportFragmentPositionToUV
vec2 R2_viewportFragmentPositionToUV(const R2_viewport_t v, const vec2 f_pos)
Definition: R2Viewport.h:24
R2_stipple_t
The type of stippling parameters.
Definition: R2Stipple.h:11