Post-Processing
Each Shader can have one or more Post-Processing Shaders that can affect the final output of that Shader.
Define the chain of the Post-Processing Effects for a Shader as such in the Main Configuration File:
- name: linear
.
.
.
window-width: 300
window-height: 100
post-processing:
- name: glow
passes: 2
This will insert 2 Passes of the Glow Effect at the end of the Render Stage of the Shader.
-
Each
Post-Processing Effectis defined as aStructin its correspondingPrimitivefile -
Since each 'pass' of the
Post-ProcessingShader can have different values for the required attributes,WayVesuses the#expanddirective to specify variable names suffixed by thenumber of the currently-ongoing pass - 1. -
Each instance of the
Struct Primitivefor each 'pass' of thePost-ProcessingShader is controlled by theset<PostProcessingShaderName><PassNumber-1>(inout <PostProcessingShaderName> variableName)function -
For example, if
Glowhas 4 passes defined in the Main YAML Spec, the necessary functions that need to be defined arevoid setGlow0(inout Glow glow) {},void setGlow1(inout Glow glow) {}, and so on. -
Even if the same effect is encountered in a Chain as such, the effective pass number is still one greater than the last pass encountered. So after 2 passes of a
Post-ProcessingShader, whenever thatShaderis involved again in the same chain, then the variable suffix will correspond to the 3rd pass (setGlow2(inout Glow glow) {})
By default, Glow and Rotate Post-Processing Effects have been provided.
Glow Adds a Glowing Effect to the final output of the Shader.
| Property | Data Type | Description | Example |
|---|---|---|---|
| blendMode | float | Blend mode for the glow effect. 0 = Additive, 1 = Overlay | 0 |
| mixAlpha | float | Whether to use the Alpha Channel for the Glow Effect | 1 |
| offsetAngle | float | Offset (in degrees) for Glow directions | 90 |
| maxAngle | float | Max Angle (in degrees) for Glow directions | 360 |
| size | vec2 | Size of the Glow | vec2(10,10) |
| intensity | float | Intensity of the Glow | 0.5 |
| directions | float | Number of directions that are sampled radially. Higher is expensive. | 4 |
| coords | vec2 | The coordinates of the current Pixel/Fragment being processed. Can be modified. | - |
| quality | float | Quality of Glow. Higher is expensive. | 8 |
| color | vec4 | Overlay color for the Glow Effect | vec4(1.0, 1.0, 1.0, 1.0) |
| brightnessOffset | float | Adjusts brightness of the final Color | 0. |
| lightStrength | float | Brightens or darkens the opacity of the final Color | .5 |
| onTop | float | Whether to stack glow on top or below the sampled output | 0 |
Rotate Rotates the final output of the Shader
| Property | Data Type | Description | Example |
|---|---|---|---|
| angle | float | The angle (in degrees) by which to rotate the output | 90 |
| center | vec2 | The coordinates around which the rotation should take place | vec2(resolution.xy / 2) |
| coords | vec2 | The coordinates of the current Pixel/Fragment being processed. Can be modified. | - |
| transform | mat2 | Additional transformation matrix for complex transformations | IDENTITY_MATRIX |
Examples
Glow with 2 Passes
The following code needs to be placed in the common Shader Configuration file for which 2 Glow passes have been enabled:
#include ":utils/post-processing/glow/structs.glsl"
// 1st Pass
void setGlow0(inout Glow glow) {
glow.blendMode = 0;
glow.mixAlpha = 0.;
glow.offsetAngle = 0.;
glow.size = 9.0;
glow.intensity = 4.5 ;
glow.directions = 4.0;
glow.quality = 3.0;
glow.color = vec4(0.2392, 0.0745, 0.6196, 1.0);
glow.brightnessOffset = 0.2;
glow.lightStrength = 0.7;
}
// 2nd Pass
void setGlow1(inout Glow glow) {
glow.blendMode = 0;
glow.mixAlpha = 0.;
glow.offsetAngle = 0.;
glow.size = 3.0;
glow.intensity = 4.5;
glow.directions = 16.0;
glow.quality = 3.0;
glow.color = vec4(0.2392, 0.0745, 0.6196, 1.0);
glow.brightnessOffset = .2;
glow.lightStrength = 0.7;
}
Rotate at lower Audio Frequencies
Setting rotate.angle to Audio data sampled at lower values will add rotation whenever lower Frequencies are active
#include ":utils/post-processing/rotate/structs.glsl"
void setRotate0(inout Rotate rotate) {
rotate.angle = (-10 * abs(sin(3.5 * (clamp(texture(audioR,.1).x - .01, 0.1, .8)))));
rotate.center = resolution / 2.;
}