• Stars
    star
    139
  • Rank 262,954 (Top 6 %)
  • Language
    Java
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A shader based postFX library for processing.

PostFX for Processing Build Status Build status codebeat badge

A simple post effects library for processing.

Introduction

PostFX is a simple post effects library for processing. Post effects are applied to the whole scene after it was rendered, to enhance the scene with some special effects. For example the bloom effect helps to simulate the light diffusion to be more realistic.

PFX Example

Example of the post effects sobel, bloom and toon.

Why did I implement it?

There are a lot of tutorials which help you to implement a bloom filter in OpenGL (e.g. Learn OpenGL - Bloom). But for processing I could not find one that is as performant as I needed in my P3D renderings.

So I started to implement a simple but fast library to run post effects on P2D and P3D graphics objects.

What is included?

Here you find two examples which are based on the Lenna and Lichtenstein test images:

Lenna Effect

Lenna Effect

The PostFX library currently contains following built in effects:

  • bright pass
  • blur horizontal
  • blur vertical
  • sobel edge detection
  • toon filter

Version 1.1 adds a lot of new shaders:

Color

  • Brightness and Contrast Shader
  • Saturation and Vibrance Shader
  • Invert Shader
  • Grayscale Shader

Reconstruction

  • Denoise Shader

Effects

  • Bloom Shader
  • Pixelate Shader
  • Chromatic aberration shader
  • Noise Shader
  • Vignette Shader
  • RGB Split Shader

And there is also a method to run your own custom shaders.

Some of the shaders are from the spite/Wagner respoitory and only adapted to work in processing.

Example

There are two API's to use the PostFX library. The basic one is very easy and removes responsibility of the pass management. The advanced way is, where you have to create pass instances yourself, but have the freedom to manage them by your own.

Custom shaders are supported, in the basic and the advanced version.

Setup

To use the library you have to install it over the processing contribution manager.

Contribution Manager

Import following packages to use all classes of the PostFX library.

import ch.bildspur.postfx.builder.*;
import ch.bildspur.postfx.pass.*;
import ch.bildspur.postfx.*;

Use the library on every PGraphics3D or PGraphics2D object or even on the screen object (g).

Basic Example

To add a post effect to your processing sketch, you just have to create a new PostFX object.

PostFX fx;

void setup()
{
  size(500, 500, P3D);
  
  fx = new PostFX(this);  
}

Now you have to call the render() method of the PostFX library. This returns an object, on which you can call all implemented effects.

void draw()
{
  // draw something onto the screen
  background(22);
  box(100);

  // add bloom filter
  fx.render()
    .bloom(0.5, 20, 40)
    .compose();
}

Finally you can use compose() to draw it onto the main screen (g object). It is also possible to compose to onto another Graphics2D object.

Based on SimpleEffect example

Off-Screen Buffer

To add a post effect onto a off-screen graphics object, you have to create a new graphics object (canvas). To use the basic version of the API, instantiate a new PostFX object.

PostFX fx;
PGraphics canvas;

void setup()
{
  size(500, 500, P2D);
  
  fx = new PostFX(this);  
  canvas = createGraphics(width, height, P3D);
}

Now you have to draw onto your canvas and after rendering, you just pass the canvas into the render() method of the PostFX library. This returns an object, on which you can call all implemented effects.

void draw()
{
  canvas.beginDraw();
  // draw something onto the canvas
  canvas.endDraw();
  
  blendMode(BLEND);
  image(canvas, 0, 0);

  // add bloom filter
  blendMode(SCREEN);
  fx.render(canvas)
    .brightPass(0.5)
    .blur(20, 50)
    .compose();
}

Finally you can use compose() to draw it onto the main screen (g object). It is also possible to compose to onto another Graphics2D object.

Based on OffScreenEffect example

Pass Preloading

For performance reasons it is sometimes necessary to preload the pass and compile the shaders before you use it. For this problem, there is the method preloadPass.

To preload a pass you have to call the method and pass the class type as argument.

void setup()
{
  size(500, 500, P3D);

  fx = new PostFX(this);

  // compile shaders in setup
  fx.preload(BloomPass.class);
  fx.preload(RGBSplitPass.class);
}

Everything else works like usual, but you have now compiled your shaders in the setup() method and not in the time critical draw() method.

Based on PassPreloading example

Advanced

The advanced version is used as the underlaying layer of the basic API. It does not create the pass objects itself, but gives the freedom to manage them by your own.

Instead of an PostFX class you have to create a new PostFXSupervisor which handles all the pass buffers. For each pass, you have to create a pass object, which contains the implementation and the parameters.

It is possible to use the same pass object twice, with different parameter settings.

PostFXSupervisor supervisor;
BrightPass brightPass;
SobelPass sobelPass;

PGraphics canvas;

void setup()
{
  size(500, 500, P2D);

  // create supervisor and load shaders
  supervisor = new PostFXSupervisor(this);
  brightPass = new BrightPass(this, 0.3f);
  sobelPass = new SobelPass(this); 

  canvas = createGraphics(width, height, P3D);
}

To render the effects onto the canvas, you have to call the render() method on the supervisor and pass all the passes.

void draw()
{
  // draw a simple rotating cube around a sphere
  canvas.beginDraw();
  // draw something onto the canvas
  canvas.endDraw();

  blendMode(BLEND);
  image(canvas, 0, 0);

  // add white ring around sphere
  blendMode(SCREEN);
  supervisor.render(canvas);
  supervisor.pass(brightPass);
  supervisor.pass(sobelPass);
  supervisor.compose();
}

Finally, the compose() method draws the scene onto the main screen. It is possible to draw the result onto another another Graphics2D object.

Based on AdvancedEffect example

Custom Shader

This tutorial shows how to create a negate pass.

To add a custom shader as pass, you have to create a new class which implements the Pass interface.

class NegatePass implements Pass
{
  PShader shader;

  public NegatePass()
  {
    shader = loadShader("negateFrag.glsl");
  }

  @Override
    public void prepare(Supervisor supervisor) {
    // set parameters of the shader if needed
  }

  @Override
    public void apply(Supervisor supervisor) {
    PGraphics pass = supervisor.getNextPass();
    supervisor.clearPass(pass);

    pass.beginDraw();
    pass.shader(shader);
    pass.image(supervisor.getCurrentPass(), 0, 0);
    pass.endDraw();
  }
}

The shader for this example is very simple and just calculates one minus the color value.

#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif

uniform sampler2D texture;

varying vec4 vertColor;
varying vec4 vertTexCoord;

void main() {
    vec4 c = texture2D(texture, vertTexCoord.st) * vertColor;
    c.xyz = 1.0 - c.xyz;
    gl_FragColor = c;
}

To use the shader, you have to create a new instance of it and then add it as pass:

// in setup
NegatePass negatePass = new NegatePass();

// in draw
supervisor.render(canvas);
supervisor.pass(negatePass);
supervisor.compose();

Based on CustomShaderEffect example

Custom Shader Builder Pattern

With version 1.1 it is now also possible to add a custom shader directly to the builder pattern, which simplifies the whole process:

// in setup
NegatePass negatePass = new NegatePass();

// in draw
fx.render()
  .custom(negatePass)
  .compose();

About

Developed by Florian Bruggisser (bildspur.ch) 2017

More Repositories

1

architectural-floor-plan

AFPlan is an architectural floor plan analysis and recognition system to create extended plans for building services.
Kotlin
297
star
2

yolo-hand-detection

A pre-trained YOLO based hand detection network.
Python
220
star
3

kotlin-latex-listing

A syntax highlighting template for the Kotlin language in LaTeX listings.
TeX
114
star
4

artnet4j

Art-Net DMX over IP library for Java and Processing
Java
82
star
5

deep-vision-processing

Deep computer-vision algorithms for the Processing framework.
Java
79
star
6

realsense-processing

Intel RealSense 2 support for the Processing framework.
Java
74
star
7

mediapipe-silicon

Prebuilt Google MediaPipe packages for arm64.
Shell
69
star
8

LongLiveTheSquare

An algorithm to find the minimum bounding box.
C#
65
star
9

processing-bloom-filter

An example of a bloom filter as post fx in processing3.
GLSL
49
star
10

sharp-frame-extractor

Extracts sharp frames from a video.
Python
47
star
11

esp-dmx-max485

An example on how to send dmx over a max485 with an ESP8622 and ESP32.
C++
36
star
12

nanobind-stubgen

Generate python stub files for code completion in IDEs for nanobind modules.
Python
32
star
13

mediapipe-osc

MediaPipe examples which stream their detections over OSC.
Python
32
star
14

pyrealsense2-macosx

Prebuilt pyrealsense2 packages for macOSX.
PowerShell
30
star
15

onnxruntime-silicon

ONNX Runtime prebuilt wheels for Apple Silicon (M1 / ARM64)
Python
28
star
16

mesh-sequence-player

A simple mesh sequence player based on open3d.
Python
23
star
17

yolo-mask-detection

A pre-trained YOLOv3 based mask detection network.
Python
21
star
18

smooth-servo

An processing library for smooth servo control.
Processing
21
star
19

pointcloud-processing

A point cloud visualisation and analysis library for Processing.
Java
19
star
20

madmapperapi

This is a documentation and example page for the MadMapper API.
16
star
21

sharp-tinder

Sharp-Tinder is a basic client framework for the very popular tinder dating app.
C#
13
star
22

librealsense-java

Intelยฎ RealSenseโ„ข SDK 2 wrapper for Java.
Java
13
star
23

opencv-processing

OpenCV for Processing. A creative coding computer vision library based on the official OpenCV Java API
Java
12
star
24

ArtNet3DotNet

ArtNet 3 Implementation for .NET in C#
C#
12
star
25

realsense-unity-mac

An example for using the Intel Realsense camera with Unity under MacOS.
C#
11
star
26

realsense-pose-detector

A simple pose detector which runs with the realsense framework.
Python
10
star
27

multi-pointcloud-example

An example on combining multiple pointclouds from different scans in unity.
C#
8
star
28

pointcloud-to-scenekit

PLY Pointcloud to Apple SceneKit converter.
Swift
8
star
29

syphon-python

Python wrapper for the GPU texture sharing framework Syphon (Metal & OpenGL).
Python
8
star
30

openvino-arm

Prebuilt openvino packages for arm64.
Shell
8
star
31

space-stream

An example which streams RGB-D images over spout or syphon
Python
8
star
32

auto-keypoint-retopology

Auto keypoint extractor for retopology.
Python
7
star
33

p5js-pointcloud

Pointcloud viewer proof of concept for p5js based on webGL
JavaScript
7
star
34

SimplexSolver

A simple simplex algorithm implemented in java.
Java
7
star
35

processing-imageglitch

Processing image glitch is a small library to add glitch to a PImage. The algorithm uses the singularity of jpeg compression, which allows to display even an corrupted image.
Processing
6
star
36

pg4nosql

A simple psycopg2 based wrapper for nosql like database interaction with python.
Python
6
star
37

seqosc

Sequencer for OSC to record and playback OSC messages.
Kotlin
5
star
38

temporal-shift

Spatial based storytelling by the use of motion based interaction.
Swift
5
star
39

duit

Duit is a Python library that provides a set of tools for working with data in a structured and efficient way.
Python
5
star
40

sweep-3d-lidar

A prototype of the sweep lidar scanner used for 3d scanning.
Processing
5
star
41

esp-ota-updater

App to update ESP32 and ESP8266 microchips over-the-air.
C#
5
star
42

webcam-capture-processing

A very basic webcam capture solution for processing.
Java
4
star
43

tvver-commercial

The commercial detection algorithm (CODA) is a simple way to detect similar patterns in a movie.
Java
4
star
44

spatial-interaction-examples

All the examples for the course spatial interaction.
Processing
4
star
45

pymesh2depthmap

A simple tool to create depth-maps out of 3d meshes.
Python
4
star
46

ble-serial-bridge

A firmware to use an ESP32 as a BLE device controlled over serial commands.
Java
4
star
47

mqtt-protobuf-example

A simple MQTT and Protobuf example in C#.
C#
4
star
48

opencv-sample-annotator

A simple tool to create positive and negative samples for cascading classifiers.
Kotlin
4
star
49

floor-plan-object-detection

Object detection on architectural floor plans with deep learning.
4
star
50

unity-quest-pointcloud

An example on how to display a pointcloud on the oculus quest with unity.
C#
4
star
51

sweep-processing

Sweep Library for Processing
Java
4
star
52

mediapipe-face-geometry

MediaPipe Face Geometry example in python.
Python
4
star
53

syphon-live-loop

Live loop software for syphon.
Kotlin
4
star
54

ar-pointcloud-example

View pointclouds in AR.
Swift
3
star
55

visual-push-x

Visual Push X is the next level VJ software which connects to the Ableton Push controller.
Kotlin
3
star
56

sonic-touch-localization

Touch localization on a tabletop with the use of multiple microphones.
Java
3
star
57

sdent-universe

A space gameboy game.
C
3
star
58

ios-depth-recorder

A simple depth image recorder for ios.
Swift
3
star
59

comgr-particle-swarm

A 3d particle swarm with the ability to align itself to different figures.
Java
3
star
60

eyetracking-poc

Eye-tracking proof of concept in processing.
Processing
3
star
61

unity-mixamo-importer

A simple FBX importer for Mixamo rigged avatars.
C#
3
star
62

multi-pose-landmark-mediapipe

MediaPipe multi pose tracking graph implemented with python.
Python
3
star
63

lasercut-case-fusion360

Fusion360 script to create lasercut cases.
Python
3
star
64

mediapipe-extended

Mediapipe for python with extended solution support.
PowerShell
3
star
65

opendata-transport

This is an implementation of the Open Data Transport API in Java.
Java
2
star
66

processing4-tool-template

A basic template to create processing4 tools.
Kotlin
2
star
67

brush-gcode

A simple post-processor for gcode to enable brush dipping.
Python
2
star
68

topography-pcl-viewer

A simple topography pointcloud viewer.
Processing
2
star
69

processing-pose

Skeleton Tracking for Processing Example
Kotlin
2
star
70

midas-converter

Utility to convert RGB frames into depth frames by using MiDas.
Python
2
star
71

eucliddatasimulator

IP5 Euclid Data Simulator
Python
2
star
72

mac-to-name

A method to generate a unique name out of a mac address.
C
2
star
73

openrndr-pointcloud

Simple pointcloud rendering with openRNDR
Kotlin
2
star
74

deep-learning-playground

Just some scripts and tools which I use for deep learning (with focus on object detection).
Python
2
star
75

serial-osc-example

A simple example of SerialOSC with Processing and Arduino communicating.
Arduino
2
star
76

esp-osc-link

ESP8266 Open Sound Control (OSC) Uplink for Microcontrollers
C++
2
star
77

autonomous-turtle-os

This is a prototype repository of the self-driving turtle os.
C++
2
star
78

deep-vision-installation

Deep Vision is an art installation created as final artefact of my master thesis in design.
C++
2
star
79

sensitized

An example on how to use yolov2 from open cv within processing.
Kotlin
2
star
80

image-perspective-transform

Transform the viewangle of an image onto another image of the same object.
Kotlin
2
star
81

three-scan

Three Scan is a three dimensional LIDAR scanner.
C++
2
star
82

FlockingAlgorithm

A flocking algorithm with the ability to find objects.
Processing
2
star
83

visiongraph-pose-estimation

A visiongraph based pose estimator example with performance measurement.
Python
2
star
84

data-storage

A repository to host data used in various projects.
2
star
85

mirror-vr-player

Web VR video player which can be synced / mirrored to other clients.
Kotlin
2
star
86

onnx-processing-demo

A simple demo on how to run ONNX vision models in processing.
Java
2
star
87

zurich-events-visualizer

A python script to visualize events from Zurich.
HTML
2
star
88

abstract-diagram-syntax

An abstract diagram syntax for flowchart.
Kotlin
1
star
89

empathetic-soldering

What if your electronic circuits are empathetic?
C++
1
star
90

vibration-stroke-illusion

An experiment to simulate stroking with machines.
Processing
1
star
91

iad-embodied-interaction

Materials for the data embodiment input in the embodied interaction BA course.
Processing
1
star
92

unity-leap-pose-recognizer

Unity leapmotion pose recognizer with wekinator.
C#
1
star
93

achtungkurve-sound

Sound programming for the ยซAchtung, die Kurve!ยป HTML5 game.
JavaScript
1
star
94

human-pose-stream

A simple human pose estimation software that streams the pose data over OSC.
C++
1
star
95

darwinStebs

Student Training 8 bit Simulator for Mac OSX
C#
1
star
96

haptic-depth-creator

Create haptic depth printable pictures.
Processing
1
star
97

realsense-rig-simulator

A simpel rig simulator for D435 cameras.
Processing
1
star
98

bildspur-base

A library with basic components for creative applications in kotlin.
Kotlin
1
star
99

mirrorly

Mirror your main screen to your second screen for presentations.
C++
1
star
100

pyunicon

PyUnicon is a cross platform library to control keyboard and mouse.
Python
1
star