Loading...
Searching...
No Matches
ml::ShaderLibrary Class Reference

Built-in GLSL shaders and uniform parameters for Carousel effects. More...

#include <ShaderLibrary.h>

Classes

struct  Params
 All uniform parameters shared across the built-in shaders. More...

Public Types

enum class  Style {
  DEFAULT , FADE_EDGES , BLUR_UNFOCUSED , COVERFLOW_3D ,
  COLOR_TINT , WAVE_DISTORTION , DEPTH_OF_FIELD , SCALE_CENTER ,
  VIGNETTE , GRAYSCALE_EDGES , REFLECTION , ROTATION_3D ,
  PARALLAX , GLOW_CENTER , SLIDE_ANGLE , SEPIA_TONE ,
  ZOOM_PULSE , CUSTOM
}
 Available built-in visual styles. More...

Static Public Member Functions

static void applyUniforms (sf::Shader &shader, Style style, const Params &params)
 Push the appropriate Params fields as uniforms to shader.
static std::string_view blurUnfocused ()
 Return the GLSL source for the BLUR_UNFOCUSED style.
static std::string_view colorTint ()
 Return the GLSL source for the COLOR_TINT style.
static std::string_view coverflow3D ()
 Return the GLSL source for the COVERFLOW_3D style.
static std::string_view depthOfField ()
 Return the GLSL source for the DEPTH_OF_FIELD style.
static std::string_view fadeEdges ()
 Return the GLSL source for the FADE_EDGES style.
static std::string_view glowCenter ()
 Return the GLSL source for the GLOW_CENTER style.
static std::string_view grayscaleEdges ()
 Return the GLSL source for the GRAYSCALE_EDGES style.
static std::string_view parallax ()
 Return the GLSL source for the PARALLAX style.
static std::string_view reflection ()
 Return the GLSL source for the REFLECTION style.
static std::string_view rotation3D ()
 Return the GLSL source for the ROTATION_3D style.
static std::string_view scaleCenter ()
 Return the GLSL source for the SCALE_CENTER style.
static std::string_view sepiaTone ()
 Return the GLSL source for the SEPIA_TONE style.
static std::string_view slideAngle ()
 Return the GLSL source for the SLIDE_ANGLE style.
static std::string_view vignette ()
 Return the GLSL source for the VIGNETTE style.
static std::string_view waveDistortion ()
 Return the GLSL source for the WAVE_DISTORTION style.
static std::string_view zoomPulse ()
 Return the GLSL source for the ZOOM_PULSE style.

Detailed Description

Built-in GLSL shaders and uniform parameters for Carousel effects.

ShaderLibrary provides a catalogue of pre-written fragment shaders that can be applied to a Carousel's render texture, along with a Params struct that centralises every uniform value the shaders accept.

Selecting a style

Pass a Style value to Carousel::setStyle():

Tuning parameters

Retrieve and modify the carousel's Params, then the shader will pick up the new values on the next frame:

auto& p = carousel.getShaderParams();
p.blurAmount = 4.f;
p.focusWidth = 0.15f;

Custom shader

Use Style::CUSTOM and supply your own shader via Carousel::setShader():

carousel.setShader(&myShader, [](sf::Shader& s){
s.setUniform("uTime", clock.getElapsedTime().asSeconds());
});
void setUniform(const std::string &name, float x)
See also
Carousel, CarouselManifest

Definition at line 49 of file ShaderLibrary.h.

Member Enumeration Documentation

◆ Style

enum class ml::ShaderLibrary::Style
strong

Available built-in visual styles.

Value Effect
DEFAULT No shader — plain rendering
FADE_EDGES Alpha fade toward left and right edges
BLUR_UNFOCUSED Blur items away from the center
COVERFLOW_3D CoverFlow-style 3D perspective tilt
COLOR_TINT Apply a color tint to off-center items
WAVE_DISTORTION Sinusoidal distortion animation
DEPTH_OF_FIELD Depth-of-field blur with focus zone
SCALE_CENTER Scale up the center item
VIGNETTE Dark vignette around the edges
GRAYSCALE_EDGES Desaturate items away from center
REFLECTION Mirror reflection below items
ROTATION_3D Full 3D rotation effect
PARALLAX Parallax scroll layer offset
GLOW_CENTER Glow halo on the center item
SLIDE_ANGLE Angled slide transition
SEPIA_TONE Sepia color grading
ZOOM_PULSE Pulsing zoom animation
CUSTOM User-supplied shader via Carousel::setShader()
Enumerator
DEFAULT 
FADE_EDGES 
BLUR_UNFOCUSED 
COVERFLOW_3D 
COLOR_TINT 
WAVE_DISTORTION 
DEPTH_OF_FIELD 
SCALE_CENTER 
VIGNETTE 
GRAYSCALE_EDGES 
REFLECTION 
ROTATION_3D 
PARALLAX 
GLOW_CENTER 
SLIDE_ANGLE 
SEPIA_TONE 
ZOOM_PULSE 
CUSTOM 

Definition at line 135 of file ShaderLibrary.h.

Member Function Documentation

◆ applyUniforms()

void ml::ShaderLibrary::applyUniforms ( sf::Shader & shader,
Style style,
const Params & params )
static

Push the appropriate Params fields as uniforms to shader.

Called by Carousel once per frame before rendering. Only the uniforms relevant to style are set — unused fields are ignored.

Parameters
shaderThe active sf::Shader to update.
styleThe currently selected Style.
paramsThe parameter values to upload.

◆ blurUnfocused()

std::string_view ml::ShaderLibrary::blurUnfocused ( )
static

Return the GLSL source for the BLUR_UNFOCUSED style.

◆ colorTint()

std::string_view ml::ShaderLibrary::colorTint ( )
static

Return the GLSL source for the COLOR_TINT style.

◆ coverflow3D()

std::string_view ml::ShaderLibrary::coverflow3D ( )
static

Return the GLSL source for the COVERFLOW_3D style.

◆ depthOfField()

std::string_view ml::ShaderLibrary::depthOfField ( )
static

Return the GLSL source for the DEPTH_OF_FIELD style.

◆ fadeEdges()

std::string_view ml::ShaderLibrary::fadeEdges ( )
static

Return the GLSL source for the FADE_EDGES style.

◆ glowCenter()

std::string_view ml::ShaderLibrary::glowCenter ( )
static

Return the GLSL source for the GLOW_CENTER style.

◆ grayscaleEdges()

std::string_view ml::ShaderLibrary::grayscaleEdges ( )
static

Return the GLSL source for the GRAYSCALE_EDGES style.

◆ parallax()

std::string_view ml::ShaderLibrary::parallax ( )
static

Return the GLSL source for the PARALLAX style.

◆ reflection()

std::string_view ml::ShaderLibrary::reflection ( )
static

Return the GLSL source for the REFLECTION style.

◆ rotation3D()

std::string_view ml::ShaderLibrary::rotation3D ( )
static

Return the GLSL source for the ROTATION_3D style.

◆ scaleCenter()

std::string_view ml::ShaderLibrary::scaleCenter ( )
static

Return the GLSL source for the SCALE_CENTER style.

◆ sepiaTone()

std::string_view ml::ShaderLibrary::sepiaTone ( )
static

Return the GLSL source for the SEPIA_TONE style.

◆ slideAngle()

std::string_view ml::ShaderLibrary::slideAngle ( )
static

Return the GLSL source for the SLIDE_ANGLE style.

◆ vignette()

std::string_view ml::ShaderLibrary::vignette ( )
static

Return the GLSL source for the VIGNETTE style.

◆ waveDistortion()

std::string_view ml::ShaderLibrary::waveDistortion ( )
static

Return the GLSL source for the WAVE_DISTORTION style.

◆ zoomPulse()

std::string_view ml::ShaderLibrary::zoomPulse ( )
static

Return the GLSL source for the ZOOM_PULSE style.


The documentation for this class was generated from the following file: