GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - benpollarduk/LoFiEffects.WPF: A WPF library of controls and pixel shader effects for rendering content in reduced fidelity.

BranchesTags
Open more actions menu

Latest commit

 

History

142 Commits
142 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.nuget
.nuget
 
 
LoFiEffects.WPF.TestApp
LoFiEffects.WPF.TestApp
 
 
LoFiEffects.WPF.Tests
LoFiEffects.WPF.Tests
 
 
LoFiEffects.WPF
LoFiEffects.WPF
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
LoFiEffects.WPF.sln
LoFiEffects.WPF.sln
 
 
README.md
README.md
 
 

Repository files navigation

LoFiEffects.WPF

A WPF library for rendering content in reduced fidelity.

main-ci GitHub release NuGet NuGet Downloads codecov Quality Gate Status Maintainability Rating Security Rating Vulnerabilities Bugs License

Introduction

A library of controls and shader effects aimed at providing effects to degrade visual quality.

Getting Started

Clone the repo/pull NuGet

Clone the repo:

git clone https://github.com/benpollarduk/lofieffects.wpf.git

Or add the NuGet package:

dotnet add package LoFiEffects.WPF

Controls

Frame Rate Reduction

The FrameRateReductionPresenter can be used to reduce the frame rate that the content is rendered at.

Use

<FrameRateReductionPresenter FramesPerSecond="5">
    <Button Content="This is an example button"/>
</FrameRateReductionPresenter>

The FramesPerSecond property can be used to reduce the frame rate.

Note: Values higher than 60 will disable the effect and normal rendering will be resumed.

How it works

  • FrameRateReductionPresenter hosts WPF content and a FrameRateReductionMask.
  • FrameRateReductionMask creates a bitmap of the hosted content.
  • FrameRateReductionMask then renders this bitmap as its background.
  • FrameRateReductionMask isn't visible to hit testing so allows the UI beneath it to function as usual.

Sample Image

To illustrate the following shader effects this sample image will be used:

image

Shader Effects

All visual effects are created with shader effects.

Pixelate

Creates a pixelated effect reminiscent of the 8 bit era.

image

Example

<Button>
    <Button.Effect>
        <PixelateEffect Intensity="0.15"/>
    </Button.Effect>
</Button>

Properties

  • Intensity: A double specifying the intensity of the effect within a normalised range of 0-1.

Crt

An effect that aims to create the impression that the visual is being displayed on a cathode ray tube (CRT) display.

image

Example

<Button>
    <Button.Effect>
        <CrtEffect TextureWidth="100" TextureHeight="35" IncludeScanlines="False" Intensity="1" CurvatureIntensity="1" Brightness="0.5"/>
    </Button.Effect>
</Button>

Properties

  • TextureWidth: A double specifying the rendered width of the texture in WPF units.
  • TextureHeight: A double specifying the rendered height of the texture in WPF units.
  • IncludeScanlines: A boolean specifying if scan lines should be included.
  • Intensity: A double specifying the intensity of the effect within a normalised range of 0-1.
  • CurvatureIntensity: A double specifying the intensity of the curvature effect within a normalised range of 0-1.
  • Brightness: A double specifying the brightness within a normalised range of 0-1.

Degrade

Adds overall degradation to the visual. Similar to the Noise effect but works in a subtractive manner.

image

Example

<Button>
    <Button.Effect>
        <DegradeEffect Intensity="0.3" Density="0.8" Offset="0"/>
    </Button.Effect>
</Button>

Properties

  • Intensity: A double specifying the intensity of the effect within a normalised range of 0-1.
  • Density: A double specifying the density of the effect within a normalised range of 0-1.
  • Offset: A double specifying an offset to apply to the effect within a normalised range of 0-1. When this value changes different patterns are generated which can be used to add a pseudo-random effect.

Noise

Adds noise to the visual. Similar to Degrade but is additive.

image

Example

<Button>
    <Button.Effect>
        <NoiseEffect Intensity="0.3" Density="0.8" Offset="0"/>
    </Button.Effect>
</Button>

Properties

  • Intensity: A double specifying the intensity of the effect within a normalised range of 0-1.
  • Density: A double specifying the density of the effect within a normalised range of 0-1.
  • Offset: A double specifying an offset to apply to the effect within a normalised range of 0-1. When this value changes different patterns are generated which can be used to add a pseudo-random effect.

Grayscale

Applies a simple grayscale effect, converting the target into grayscale. The following purposely crude algorithm is used:

gray = (red + green + blue) / 3

image

Example

<Button>
    <Button.Effect>
        <GrayscaleEffect/>
    </Button.Effect>
</Button>

Negative

Applies a simple negative effect, inverting all channels except alpha, rendering the visual as a negative.

image

Example

<Button>
    <Button.Effect>
        <NegativeEffect/>
    </Button.Effect>
</Button>

Posterize

Reduces apparent bit depth across all channels to produce a banding effect.

image

Example

<Button>
    <Button.Effect>
        <PosterizeEffect Steps="5"/>
    </Button.Effect>
</Button>

Properties

  • Steps: Sets the number of steps used to represent all channels. Supports values between 1 and 255. 1 will reduce a pure black visual as there will be only a single step, and 255 will have no effect as each channel will be represented in full. Low values will have a more pronounced effect, higher values will be subtle.

Posterize Multi Channel

Reduces apparent bit depth across all channels individually to produce a banding effect.

image

Example

<Button>
    <Button.Effect>
        <PosterizeMultiChannelEffect StepsR="3" StepsG="11" StepsB="5"/>
    </Button.Effect>
</Button>

Watercolor

Applies some simple filtering to produce a subtle watercolor effect.

image

Example

<Button>
    <Button.Effect>
        <WatercolorEffect TextureWidth="100" TextureHeight="35" Intensity="0.5"/>
    </Button.Effect>
</Button>

Properties

  • TextureWidth: A double specifying the rendered width of the texture in WPF units.
  • TextureHeight: A double specifying the rendered height of the texture in WPF units.
  • Intensity: A double specifying the intensity of the effect within a normalised range of 0-1.

Block Displacement

Displaces blocks of pixels in the visual to create a glitch or digital transmission error effect.

image

Example

<Button>
    <Button.Effect>
        <BlockDisplacementEffect Intensity="0.1" Resolution="50" Time="50"/>
    </Button.Effect>
</Button>

Properties

  • Intensity: A double specifying the intensity of the effect within a normalised range of 0-1.
  • Resolution: A double specifying the resolution of the blocks.
  • Time: A double specifying a time offset to animate the displacement over time.

Chromatic Aberration

Simulates the effect of chromatic aberration by separating color channels and shifting them.

image

Example

<Button>
    <Button.Effect>
        <ChromaticAberrationEffect Intensity="10" TextureWidth="100" TextureHeight="35"/>
    </Button.Effect>
</Button>

Properties

  • Intensity: A double specifying the intensity of the effect.
  • TextureWidth: A double specifying the rendered width of the texture in WPF units.
  • TextureHeight: A double specifying the rendered height of the texture in WPF units.

Sample And Hold

Simulates a sample and hold effect, keeping the color value of pixels over a region.

image

Example

<Button>
    <Button.Effect>
        <SampleAndHoldEffect Intensity="0.5"/>
    </Button.Effect>
</Button>

Properties

  • Intensity: A double specifying the intensity of the effect within a normalised range of 0-1.

Sample Rate Reduction

Reduces the sample rate of the visual, effectively lowering its fidelity.

image

Example

<Button>
    <Button.Effect>
        <SampleRateReductionEffect Scale="50" Jitter="0.05"/>
    </Button.Effect>
</Button>

Properties

  • Scale: A double specifying the scale of the reduction.
  • Jitter: A double specifying the level of jitter applied.

Wavefolding

Applies a wavefolding effect to the color channels of the visual to create distortion.

image

Example

<Button>
    <Button.Effect>
        <WavefoldingEffect Intensity="5"/>
    </Button.Effect>
</Button>

Properties

  • Intensity: A double specifying the intensity of the effect.

Hello World

For a Hello World example with a simple UI see LoFiEffects.WPF.TestApp/MainWindow.xaml

image

Compiling Shaders

Shaders can be compiled using FXC.exe. FXC.exe is part of the Windows SDK. The LoFiEffects.WPF project has a pre-build event that can be used to compile a shader effect when it is built.

The Shader variable needs to be set to the name of the shader effect to compile:

set Shader=Noise

Note: The path to fxc.exe may need to be changed to suit your build environment depending on the version installed.

REM to compile a shader specify the name of the shader, e.g:
REM set Shader=Crt
REM Otherwise use "", e.g:
REM set Shader=""
set Shader=""

set Fxc=C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x86\fxc.exe
set Input=$(ProjectDir)Effects\HLSL\%Shader%.fx
set Output=$(ProjectDir)Effects\Shaders\%Shader%.ps

if %Shader% == "" (
  echo Not compiling shader as no shader has been set. To compile a shader edit the $(ProjectName) pre-build event.
) else (
  echo Compiling shader %Input%...
  "%Fxc%" /O0 /Zi /T ps_2_0 /Fo "%Output%" "%Input%"
  echo Shader compiled to %Output%. Don't forget to set compiled shader build action to "Resource".
)

Note: If a shader is built for the first time its Build Action will need to be manually set to Resource to be used by the project.

About

A WPF library of controls and pixel shader effects for rendering content in reduced fidelity.

Topics

c-sharpcathode-ray-tubecontrolcrtdegradeframe-rategrayscalelibrarylo-filofinegativepixelatedposterizeposterizershadershader-effectsshadersspeckle-noisewpf

Resources

Readme
MIT license
Activity

Stars

4 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.