• Stars
    star
    2,492
  • Rank 18,344 (Top 0.4 %)
  • Language GLSL
  • License
    Other
  • Created over 3 years ago
  • Updated about 1 month ago

Reviews

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

Repository Details

LYGIA, it's a granular and multi-language (GLSL, HLSL, WGSL, MSL and CUDA) shader library designed for performance and flexibility

LYGIA

LYGIA Shader Library

Tired of searching, porting and/or reimplementing the same functions over and over? LYGIA is a shader library of reusable functions that can be included easily into your projects. LYGIA is very granular and designed for reusability, performance, and flexibility. LYGIA can easily be added to any project or framework.

uUnity threejs p5 p5js openFrameworks touchDesigner glslViewer ob r3rf Figma irmf Ossia npm laforge synesthesia ogl

How to use it?

In your shader #include the functions you need:

#ifdef GL_ES
precision mediump float;
#endif

uniform vec2    u_resolution;
uniform float   u_time;

#include "lygia/space/ratio.glsl"
#include "lygia/math/decimate.glsl"
#include "lygia/draw/circle.glsl"

void main(void) {
    vec3 color = vec3(0.0);
    vec2 st = gl_FragCoord.xy/u_resolution.xy;
    st = ratio(st, u_resolution);
    
    color = vec3(st.x,st.y,abs(sin(u_time)));
    color = decimate(color, 20.);
    color += circle(st, .5, .1);
    
    gl_FragColor = vec4(color, 1.0);
}

LYGIA Locally

If you are working locally in an environment that can resolve #include dependencies, just clone LYGIA into your project relative to the shader you are loading:

    git clone https://github.com/patriciogonzalezvivo/lygia.git

or as a submodule:

    git submodule add https://github.com/patriciogonzalezvivo/lygia.git

or you may clone LYGIA without the git history and reduce the project size (9MB+) with the following command:

    npx degit https://github.com/patriciogonzalezvivo/lygia.git lygia

LYGIA on the cloud

If you are working on a cloud platform you probably want to resolve the dependencies without needing to install anything. Just add a link to https://lygia.xyz/resolve.js (JS) or https://lygia.xyz/resolve.esm.js (ES6 module):

    <!-- as a JavaScript source -->
    <script src="https://lygia.xyz/resolve.js"></script>

    <!-- Or as a ES6 module -->
    <script type="module">
        import resolveLygia from "https://lygia.xyz/resolve.esm.js"
    </script>

To then resolve the dependencies by passing a string or strings[] to resolveLygia() or resolveLygiaAsync():

    // 1. FIRST

    // Sync resolver, one include at a time
    vertSource = resolveLygia(vertSource);
    fragSource = resolveLygia(fragSource);

    // OR.
    
    // ASync resolver, all includes in parallel calls
    vertSource = resolveLygiaAsync(vertSource);
    fragSource = resolveLygiaAsync(fragSource);
    
    // 2. SECOND

    // Use the resolved source code 
    shdr = createShader(vertSource, fragSource);

This this function can also resolve dependencies to previous versions of LYGIA by using this pattern lygia/vX.X.X/... on you dependency paths. For example:

#include "lygia/v1.0.0/math/decimation.glsl"
#include "lygia/v1.1.0/math/decimation.glsl"

Integrations examples

Learn more about LYGIA and how to use it from these examples:

For more information, guidance, or feedback about using LYGIA, join #Lygia channel on shader.zone discord.

How is it organized?

The functions are divided into different categories:

  • math/: general math functions and constants: PI, SqrtLength(), etc.
  • space/: general spatial operations: scale(), rotate(), etc.
  • color/: general color operations: luma(), saturation(), blend modes, palettes, color space conversion, and tonemaps.
  • animation/: animation operations: easing
  • generative/: generative functions: random(), noise(), etc.
  • sdf/: signed distance field functions.
  • draw/: drawing functions like digits(), stroke(), fill, etc/.
  • sample/: sample operations
  • filter/: typical filter operations: different kind of blurs, mean and median filters.
  • distort/: distort sampling operations
  • simulate/: simulate sampling operations
  • lighting/: different lighting models and functions for foward/deferred/raymarching rendering
  • geometry/: operation related to geometries: intersections and AABB accelerating structures.
  • morphological/: morphological filters: dilation, erosion, alpha and poisson fill.

Flexible how?

There are some functions whose behavior can be changed using the #defines keyword before including it. For example, gaussian blurs are usually are done in two passes. By default, these are performed on their 1D version, but if you are interested in using a 2D kernel, all in the same pass, you will need to add the GAUSSIANBLUR_2D keyword this way:

    #define GAUSSIANBLUR_2D
    #include "filter/gaussianBlur.glsl"

    void main(void) {
        ...
        
        vec2 pixel = 1./u_resolution;
        color = gaussianBlur(u_tex0, uv, pixel, 9);
        ...
    }

Design Principles

  1. It relies on #include "path/to/file.*lsl" which is defined by Khronos GLSL standard and requires a typical C-like pre-compiler MACRO which is easy to implement with just basic string operations to resolve dependencies.

Here you can find some implementations on different languages:

  • It's very granular. One function per file. The file and the function share the same name, namely: myFunc.glsl contains myFunct(). There are some files that just include a collection of files inside a folder with the same name. For example:
    color/blend.glsl
    // which includes
    color/blend/*.glsl

  • It's multi language. Right now most of is GLSL (*.glsl) and HLSL (*.hlsl), but we are slowly extending to WGSL (*.wgsl), CUDA (*.cuh) and Metal (*.msl).
    math/mirror.glsl
    math/mirror.hlsl
    math/mirror.wgsl
    math/mirror.msl
    math/mirror.cuh
  • Self documented. Each file contains a structured comment (in YAML) at the top of the file. This one contains the name of the original author, description, use, and #define options
    /*
    original_author: <FULL NAME>
    description: [DESCRIPTION + URL]
    use: <vec2> myFunc(<vec2> st, <float> x [, <float> y])
    options:
        - MYFUNC_TYPE
        - MYFUNC_SAMPLER_FNC()
    */
  • Prevents name collisions by using the following pattern where FNC_ is followed with the function name:
    #ifndef FNC_MYFUNC
    #define FNC_MYFUNC

    float myFunc(float in) {
        return in;
    }

    #endif
  • Templating capabilities through #defines. Probably the most frequent use is templating the sampling function for reusability. The #define options start with the name of the function, in this example MYFUNC_. They are added as options: in the header.
    #ifndef MYFUNC_TYPE
    #define MYFUNC_TYPE vec4
    #endif

    #ifndef MYFUNC_SAMPLER_FNC
    #define MYFUNC_SAMPLER_FNC(TEX, UV) texture2D(TEX, UV)
    #endif

    #ifndef FNC_MYFUNC
    #define FNC_MYFUNC
    MYFUNC_TYPE myFunc(SAMPLER_TYPE tex, vec2 st) {
        return MYFUNC_SAMPLER_FNC(tex, st);
    }
    #endif
  • Function Overloading. Arguments are arranged in such a way that optional elements are at the end. When possible sort them according their memory size (except textures that remain at the top). Ex.: SAMPLER_TYPE, mat4, mat3, mat2, vec4, vec3, vec2, float, ivec4, ivec3, ivec2, int, bool
    /*
    ...
    use: myFunc(<vec2> st, <vec2|float> x[, <float> y])
    */

    #ifndef FNC_MYFUNC
    #define FNC_MYFUNC
    vec2 myFunc(vec2 st, vec2 x) {
        return st * x;
    }

    vec2 myFunc(vec2 st, float x) {
        return st * x;
    }

    vec2 myFunc(vec2 st, float x, float y) {
        return st * vec2(x, y);
    }
    #endif

Contributions

LYGIA has a long way to go. Your support will be appreciated and rewarded! All contributors are automatically added to the commercial license. This support can take multiple forms:

  • fixing bugs!
  • expanding the cross-compatibility between languages GLSL/HLSL/MSL/WGSL/CUDA
  • contributing new functions
  • adding new examples and integrations for new environments like: GoDot, ISF, MaxMSP, etc.
  • through sponsorships

License

LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.

Sponsors and contributors are automatically added to the Patron License and they can ignore any non-commercial rule of the Prosperity License software (please take a look at the exceptions).

It's also possible to get a permanent commercial license hooked to a single and specific version of LYGIA.

Exceptions:

  • color/mixBox.glsl and color/mixBox.hlsl are copyrighted by Secret Weapons with their own non-commercial license. These functions also require a LUT texture which is provided for research and evaluation purposes, if you wish to obtain it together with a commercial license, please contact them at [email protected].

Credits

Created and mantained by Patricio Gonzalez Vivo( Mastodon | Twitter | Instagram | GitHub ) and every direct or indirect contributors to the GitHub. This library has been built over years, and in many cases on top of the work of brilliant and generous people like: Inigo Quiles, Morgan McGuire, Alan Wolfe, Hugh Kennedy, Matt DesLauriers, and many others.

Get the latest news and releases

Sign up for the news letter below, join the LYGIA's channel on Discord or follow the Github repository

More Repositories

1

thebookofshaders

Step-by-step guide through the abstract and complex universe of Fragment Shaders.
GLSL
5,989
star
2

glslViewer

Console-based GLSL Sandbox for 2D/3D shaders
C++
4,208
star
3

glslEditor

Simple WebGL Fragment Shader Editor
JavaScript
2,303
star
4

glslCanvas

Simple tool to load GLSL shaders on HTML Canvas using WebGL
JavaScript
1,753
star
5

PixelSpiritDeck

GLSL
483
star
6

glslGallery

JavaScript
363
star
7

glslTexture

Blender addon to create 2D textures from GLSL. It follows the same nomenclature that glslViewer, glslCanvas, glslEditor, ofxShader and PixelSpirit
Python
341
star
8

ofxFX

Unlocking the GPU Power on openFrameworks with this add-on for that make easy to use GLSL Shaders
C++
330
star
9

OpenLiDAR

DIY 3D LiDAR Scanner
C++
207
star
10

ofxStreetView

OF scraper for GoogleStreetView panoramas and depthmap
C++
183
star
11

sublime-glslViewer

Sublime Text 2/3 plugin for live coding GLSL Shaders
Python
147
star
12

ada

A general porpose OpenGL app library
C++
120
star
13

KinectCoreVision

Kinect Implementation of CCV
C++
100
star
14

hilma

library to generate 2D/3D geometries
C++
89
star
15

MidiGyver

C++
77
star
16

ofxFluid

GPU Fluid Simulation with a collisions layer
C++
76
star
17

vera

C++/WASM GL Framework
C++
65
star
18

vPlotter

Wireless vPlotter for RaspberryPi
C++
64
star
19

ofxComposer

Set of connecting boxes that let you load and processes different type of data on the GPU by using shaders.
C++
59
star
20

hypatia

Geo-Astronomical library for artist
C++
58
star
21

ofxVoro

OpenFrameworks wrapper of Voro++ that do 3D Voronoi Tessellation
C++
55
star
22

ofxPTAMM

Parallel Tracking and Multiple Mapping (PTAMM by Robert Castle) wrapper for openFrameworks.
C++
53
star
23

cursoOF

Curso en espaΓ±ol de openFrameworks aplicado a la creaciΓ³n
C++
53
star
24

Shell-Initiation

Exoteric *nix terminal tutorial
51
star
25

ofxShader

Objective-C
50
star
26

LineOfSight

What are the satellites in your line of sight?
JavaScript
47
star
27

ss2015

C++
46
star
28

.glslScreenSaver

Make your own custom ScreenSaver in linux using GlslViewer
GLSL
46
star
29

libopz

non official API library for the OP-Z
C++
46
star
30

lygia_threejs_examples

GLSL
40
star
31

sims2014

Simulation Studio, creative coding course taught at parsons school of design, MFADT
C++
40
star
32

ofxInteractiveSurface

For Mapping ofTextures to surfaces making transformations and masking all in one process
C++
37
star
33

ofxBlobTracker

Classic and simple blobTracker implementation used on CCV ( Created by Ramsin Khoshabeh ) + Finger Tracking
C++
33
star
34

tangram-sandbox

JavaScript
32
star
35

ofxThermalPrinter

OpenFrameworks library to control mini thermal printers (https://www.adafruit.com/products/597)
C++
29
star
36

ofxBundle

Import bundle files with cameras and point clouds.
C++
29
star
37

lygia_unity_examples

ShaderLab
28
star
38

Meshes

Simple Python Module to load, construct, parse, transform, save meshes in OBJ/PLY format
Python
26
star
39

ofxBlackBox

Minimal aesthetic orientation GUI for openFrameworks with MultiTouch/TUIO compatibility
C
24
star
40

OFPlay

Simple and Easy Tool for install and manage openFrameworks libraries and projects
C++
24
star
41

ofxGame

Group of handy classes for making Interactive 2D Games. With time and work it could be a decent game engine
C++
24
star
42

sfpc_ll16

Lux Lingua introduction at SFPC
JavaScript
23
star
43

lygia_p5_examples

GLSL
22
star
44

HeNerator

script to generate HeN ipfs app exports of GLSL shaders
Python
22
star
45

ofxTuio

Old TUIO Wrapper
C
21
star
46

ofxPro

C++
19
star
47

AxiSurface

Python module to make 100% vector line compositions and export them as SVG or G-Code files
Python
18
star
48

lygia_of_examples

GLSL
18
star
49

RandomCity

JavaScript
18
star
50

patriciogv_algo2012

Algorithmic Animation Homework Parsons New School MFA DT 2012
C++
17
star
51

sNodes

Syphon Nodes EcoSystem wrote using openFrameworks for life coding of GLSL Shaders
C++
14
star
52

vscode-pickers

GLSL/HLSL Float, 2D/3D Vector and Color picker for vscode
JavaScript
14
star
53

vim-glslViewer

Vim pluging for glslViewer which allow you to live-code shaders from your RaspberryPi
Vim Script
13
star
54

ofxEliza

Wrapper for "Chatterbot Eliza 2.0" made by Gonzales Cenelia. With is a C++ implementation of this well know chatbot
C++
12
star
55

patriciogv_avsys2013

Audio/Video Systems Homework Parsons New School MFA DT 2013
C++
12
star
56

itp17

HTML
11
star
57

joyOfLight

application that provides a means for people to play with light-painting in an intuitive and colorful way.
C++
11
star
58

ofxKeyboard

openFrameworks Virtual Keyboard implementation using ofxTUIO
C
10
star
59

.dotfiles

CSS
10
star
60

ofxPiTFT

PiTFT addon for your RaspberryPi projects
Objective-C
10
star
61

ofxGlmTools

a set of tools that use glm library
C++
10
star
62

ISS

view of OpenStreetMap from the ISS
JavaScript
9
star
63

bootcamp2013_code

Processing
9
star
64

eyeo16

JavaScript
9
star
65

ofxTimelinePro

C++
9
star
66

Skylines03

City point cloud
C++
8
star
67

hilma_raymarcher

Cuda
8
star
68

ada_example3D

JavaScript
8
star
69

ofxPulseSensor

openFrameworks addon of PulseSensor ( for Arduino and RaspberryPi )
C++
7
star
70

ofxKinectStreamer

Multi-platform Kinect depth information streamer that use native openFrameworks addons
C
7
star
71

ofxMd2

Md2 viewer ported to openFrameworks byJellyFish.com and TheoWatson.com
C
7
star
72

Timeline

C++
6
star
73

ada_example

Simple example of an ADA program
HTML
6
star
74

AxiPrinter

Stand alone RaspberryPi controller for my AxiDraw A3
Python
6
star
75

wgpu_sandbox

rust/wgpu sandbox
Rust
6
star
76

opz_experiments

GLSL
4
star
77

openVis16

OpenVis 16' Talk about Maps and Shaders
JavaScript
4
star
78

Communitas

Interactive multiTouch table made using openFrameworks and TUIO protocol.
C++
4
star
79

ofxMapsPro

C++
4
star
80

oscLab

OSC client for the OP-Z (through libopz)
C
4
star
81

lygia_minecraft

Kotlin
4
star
82

ofxMtPhotoGallery

Mouse/TUIO moultiTouch PhotoGallery
C++
4
star
83

ofxKinectUsers

Kinect addon for re-programable gesture tracking
C++
4
star
84

glslBenchmark

JavaScript
4
star
85

RaspistillAPI

PHP Raspistill API
C++
4
star
86

patriciogonzalezvivo.com

Personal Portfolio
JavaScript
4
star
87

edenControl

iOS app for remote controlling EDEN software. That itΒ΄s an Interactive Ecosystem Simulation made specially for Efecto Mariposa.
Objective-C
4
star
88

ofxSubtitles

openFrameworks addon for working with .srt movie subtitles format
C++
4
star
89

lygia_examples

GLSL
4
star
90

mary

Open Source C++ Library for different telemetry sensors with Python bindings
C
3
star
91

PixelSpiritEditor

JavaScript
3
star
92

hawkeye

Refurnishing a Kodak Brownie Hawkeye with a RaspberryPi and RasbperryCam
GLSL
3
star
93

mesaDelTiempo

C++
3
star
94

ofxWiiOSC

Wiimote addon that connects to DarwiinOSC
C++
3
star
95

AlgorithmicNaturalis

3
star
96

southUp

http://southupmap.com/
HTML
3
star
97

ofxFXPro

C++
2
star
98

HardCodeAPaper

Write like you code. Write your academic paper in MarkDown and then export them to PDF in correct Chicago Style.
TeX
2
star
99

MotionRecorder

iOS Motion Recorder
Objective-C
2
star
100

OpenNI2TUIO

C++
2
star