### Ogl Integration Examples Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Provides examples for integrating LYGIA with Ogl. Contributed by John Ku. ```GLSL See: https://github.com/kujohn/lygia_ogl_examples ``` -------------------------------- ### 2D/3D Examples for P5.js (GLSL) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Offers 2D and 3D examples for LYGIA integration with P5.js, using GLSL shaders. These examples are available in the P5.js editor. ```GLSL See: https://editor.p5js.org/patriciogonzalezvivo/sketches ``` -------------------------------- ### 2D/3D Examples on GlslViewer (GLSL) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Features 2D and 3D examples for LYGIA using GlslViewer, with GLSL shaders. ```GLSL See: https://github.com/patriciogonzalezvivo/lygia_examples ``` -------------------------------- ### 2D Examples for OpenFrameworks (GLSL) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Showcases 2D examples for using LYGIA with OpenFrameworks, written in GLSL. ```GLSL See: https://github.com/patriciogonzalezvivo/lygia_of_examples ``` -------------------------------- ### 2D Examples on Ossia Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Showcases 2D examples for LYGIA integration with Ossia. Contributed by Jean-Michaƫl Celerier. ```GLSL See: https://github.com/ossia/score-examples ``` -------------------------------- ### Examples for Touch Designer (GLSL) - Static Resolver Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Presents examples for LYGIA in Touch Designer using GLSL shaders with a static resolver. Contributed by Victor Saz. ```GLSL See: https://github.com/vectorsize/lygia-td ``` -------------------------------- ### 2D Examples on Observable Notebook (GLSL) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Showcases 2D examples for LYGIA on Observable Notebook, using GLSL shaders. Contributed by Radames Ajna. ```GLSL See: https://observablehq.com/@radames/hello-lygia-shader-library ``` -------------------------------- ### 2D Examples for Processing (GLSL) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Provides 2D examples for using LYGIA with Processing, utilizing GLSL shaders. ```GLSL See: https://github.com/patriciogonzalezvivo/lygia_p5_examples ``` -------------------------------- ### 3D Example on Irmf Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Provides a 3D example for LYGIA within the Irmf framework. Contributed by Glenn Lewis. ```GLSL See: https://github.com/irmf/irmf-examples/tree/master/examples/028-lygia ``` -------------------------------- ### 2D/3D Examples for Unity3D (HLSL) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Provides 2D and 3D examples for LYGIA integration with Unity3D, using HLSL shaders. ```HLSL See: https://github.com/patriciogonzalezvivo/lygia_unity_examples ``` -------------------------------- ### Examples for Touch Designer (GLSL) - Dynamic Resolver Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Features examples for LYGIA in Touch Designer using GLSL shaders with a dynamic resolver. Contributed by Leith Ben Abdessalem. ```GLSL See: https://derivative.ca/community-post/asset/lygia-touchdesginer/66804 ``` -------------------------------- ### 2D Examples for Three.js (GLSL) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Features 2D examples for LYGIA integration with Three.js, employing GLSL shaders. ```GLSL See: https://github.com/patriciogonzalezvivo/lygia_threejs_examples ``` -------------------------------- ### 2D Examples for Three.js + React (GLSL) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Demonstrates 2D examples for LYGIA with Three.js and React, using GLSL shaders. Provided by Eduard Fossas. ```GLSL See: https://codesandbox.io/s/lygia-react-starter-fftx6p ``` -------------------------------- ### 3D Examples for Three.js (GLSL) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Presents 3D examples for LYGIA with Three.js, utilizing GLSL shaders. Contributed by Guido Schmidt. ```GLSL See: https://github.com/guidoschmidt/lygia_threejs_examples ``` -------------------------------- ### Examples for Unreal Engine (HLSL) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Offers examples for integrating LYGIA with Unreal Engine, using HLSL shaders. Contributed by Frank Lzt. ```HLSL See: https://github.com/franklzt/lygia_unreal_engine_examples ``` -------------------------------- ### 2D Templates for Ogl(TS) and Three.js(JS/TS) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Offers 2D templates for Ogl using TypeScript and Three.js using JavaScript/TypeScript for LYGIA integration. Contributed by Daeinc. ```TypeScript See: https://github.com/cdaein/create-ssam ``` ```JavaScript See: https://github.com/cdaein/create-ssam ``` -------------------------------- ### GLSL/HLSL/WGSL/Metal/CUDA Multi-language Example Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/DESIGN.md Demonstrates how Lygia supports multiple shading languages by providing equivalent functions across different platforms. This example shows the 'mirror' function implemented in GLSL, HLSL, WGSL, Metal, and CUDA. ```glsl math/mirror.glsl ``` ```hlsl math/mirror.hlsl ``` ```wgsl math/mirror.wgsl ``` ```msl math/mirror.msl ``` ```cuh math/mirror.cuh ``` -------------------------------- ### GLSL Function Overloading Example Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/DESIGN.md Illustrates GLSL function overloading in Lygia, where multiple functions share the same name but have different parameter lists. This example shows variations of `myFunc` accepting different types and numbers of arguments. ```glsl /* ... use: myFunc( st, x[, 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 ``` -------------------------------- ### Figma Noise & Texture Plugin Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/EXAMPLES.md Integrates LYGIA modules into Figma via a community plugin. Users can edit shaders in the 'Custom' tab. Contributed by Rogie King. ```GLSL See: https://www.figma.com/community/plugin/1138854718618193875 ``` -------------------------------- ### GLSL Templating with #defines Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/DESIGN.md Demonstrates how Lygia utilizes `#define` directives for templating, allowing functions to be customized at compile time. This example shows how to define sampling functions and data types for a generic `myFunc`. ```glsl #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 ``` -------------------------------- ### Basic GLSL Shader with Lygia Includes Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/README.md This example demonstrates how to include Lygia functions like 'ratio', 'decimate', and 'circle' in a GLSL fragment shader. It sets up precision, uniforms for resolution and time, and then uses the included functions to manipulate the output color based on screen coordinates and time. ```glsl #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); } ``` -------------------------------- ### GLSL to Metal Shader Conversion Methodology Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/README_METAL.md Provides a step-by-step guide for converting GLSL shader files to Metal Shading Language (MSL). This includes file renaming, import path adjustments, and type/keyword replacements. ```metal dupe *.glsl to *.msl find replace .glsl -> .msl find replace vec2 -> float2 find replace vec3 -> float3 find replace vec4 -> float4 find replace matN -> matrix find replace in function argument keyword -> '' find inout and replace with thread local memory keyword as reference ensure const is only used within functions, constant must be used for global scoped constants ``` -------------------------------- ### Clone LYGIA Locally Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/README.md Demonstrates how to clone the LYGIA repository locally using Git, either as a standard clone or a submodule. ```bash git clone https://github.com/patriciogonzalezvivo/lygia.git ``` ```bash git submodule add https://github.com/patriciogonzalezvivo/lygia.git ``` -------------------------------- ### LYGIA Versioned Includes Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/README.md Shows the GLSL syntax for including specific versions of LYGIA modules, using paths like `lygia/vX.X/...`. ```glsl #include "lygia/v1.0/math/decimation.glsl" ``` ```glsl #include "lygia/v1.2.1/math/decimation.glsl" ``` -------------------------------- ### Clone LYGIA Locally (No History) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/README.md Provides a command to clone LYGIA without its Git history, reducing the project size, using npx and degit. ```bash npx degit https://github.com/patriciogonzalezvivo/lygia.git lygia ``` -------------------------------- ### Lygia Self-Documented File Header (GLSL) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/DESIGN.md Illustrates the structured YAML comment header required at the top of each Lygia file. This header includes metadata such as contributors, description, usage signature, implementation notes, and configurable options. ```glsl /* contributors: description: [DESCRIPTION + URL] use: myFunc( st, x [, y]) notes: - The option MYFUNC_TYPE is not supported on WGSL. options: - MYFUNC_TYPE - MYFUNC_SAMPLER_FNC() */ ``` -------------------------------- ### Include LYGIA via CDN Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/README.md Illustrates how to include LYGIA's JavaScript resolver in an HTML file, either as a standard script or an ES6 module. ```html ``` ```html ``` -------------------------------- ### JavaScript GLSL Include Resolution (Online) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/README_GLSL.md Vanilla JavaScript and an npm module for resolving LYGIA GLSL include dependencies online. These utilities parse GLSL strings, solve `#include` directives, and can handle parallel resolution. ```javascript // Vanilla JS (online resolver) // See: https://lygia.xyz/resolve.js function resolveLygia(shaderCode) { // Parses shaderCode, resolves #include dependencies. // Returns a single string with all dependencies resolved. return "resolved_shader_code"; } async function resolveLygiaAsync(shaderCode) { // Resolves dependencies in parallel. return "resolved_shader_code_async"; } // npm module (online resolver) // See: https://www.npmjs.com/package/resolve-lygia // Usage is similar to the vanilla JS version, imported via npm. ``` -------------------------------- ### Resolve LYGIA Dependencies (JavaScript) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/README.md Demonstrates how to use `resolveLygia` (synchronous) and `resolveLygiaAsync` (asynchronous) in JavaScript to resolve LYGIA shader dependencies. ```javascript // Sync resolver, one include at a time vertSource = resolveLygia(vertSource); fragSource = resolveLygia(fragSource); ``` ```javascript // OR. // Async resolver, all includes in parallel calls vertSource = resolveLygiaAsync(vertSource); fragSource = resolveLygiaAsync(fragSource); ``` ```javascript // 2. SECOND // Use the resolved source code shdr = createShader(vertSource, fragSource); ``` -------------------------------- ### Customizable Gaussian Blur in GLSL Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/README.md Demonstrates how to customize the behavior of the gaussianBlur function in LYGIA using preprocessor directives. It shows how to enable a 2D kernel for a single-pass blur and how to change the sampling function. ```glsl #define GAUSSIANBLUR_2D #include "filter/gaussianBlur.glsl" void main(void) { ... vec2 pixel = 1./u_resolution; color = gaussianBlur(u_tex0, uv, pixel, 9); ... } ``` ```glsl // from #define GAUSSIANBLUR_SAMPLER_FNC(TEX, UV) texture2D(TEX, UV) // to #include "lygia/sample/clamp2edges.glsl" #define GAUSSIANBLUR_SAMPLER_FNC(TEX, UV) sampleClamp2edge(TEX, UV) ``` -------------------------------- ### Metal Shader Precision and Sampler Configuration Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/README_METAL.md Explains how to handle texture precision and sampler objects in Metal shaders, including the use of SAMPLER_TYPE and SAMPLER macros for compatibility. ```metal // SAMPLER_TYPE specifies the texture precisions. Defaults to texture2d // Ensure your texture definition matches the default float precision or override SAMPLER_TYPE. // SAMPLER specifies the Metal sampler object. Defaults to sampler( min_filter::linear, mag_filter::linear ) // Example usage: // texture2d myTexture; // sampler mySampler = sampler( min_filter::linear, mag_filter::linear ); ``` -------------------------------- ### Prune LYGIA Library Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/README.md Shows how to use the `prune.py` script to reduce the LYGIA library size by keeping only specific language dependencies. ```python python prune.py --all --keep glsl ``` -------------------------------- ### JavaScript GLSL Include Resolution (Bundlers) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/README_GLSL.md JavaScript plugins for Vite, esbuild, and webpack that enable local GLSL include resolution. These tools streamline the process of managing shader dependencies within build pipelines. ```javascript // vite glsl plugin (local bundle) // See: https://github.com/UstymUkhman/vite-plugin-glsl // Imports .glsl local dependencies or loads inline shaders through vite. // esbuild glsl plugin (local bundle) // See: https://github.com/ricardomatias/esbuild-plugin-glsl-include // Imports local .glsl dependencies through esbuild. // webpack glsl plugin (local bundle) // See: https://github.com/grieve/webpack-glsl-loader // Imports local .glsl dependencies through webpack. ``` -------------------------------- ### C++ GLSL Dependency Resolution (VERA) Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/README_GLSL.md VERA's routines for resolving GLSL dependencies, demonstrating a C++ approach to handling `#include` statements in shaders. This is useful for managing complex shader structures. ```cpp // VERA's routines for resolving GLSL dependencies // See: https://github.com/patriciogonzalezvivo/vera/blob/main/src/ops/fs.cpp#L110-L171 // The actual implementation involves file system operations and string manipulation // to find and include shader files. ``` -------------------------------- ### Python GLSL Include Resolver Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/README_GLSL.md A simple Python script for resolving GLSL include dependencies. This provides a straightforward way to manage shader includes using basic string operations. ```python # Small and simple routing to resolve includes # See: https://gist.github.com/patriciogonzalezvivo/9a50569c2ef9b08058706443a39d838e def resolve_includes(shader_code): # Implementation would parse shader_code, find #include directives, # read the included files, and replace the directives. pass ``` -------------------------------- ### C# GLSL Include Resolver Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/README_GLSL.md A C# utility for adding include functionality to GLSL, based on the GLSL standard. This implementation helps in resolving `#include` directives within GLSL shaders. ```csharp /* * GLSLIncludes by z0rg * A small utility to add the include feature to GLSL. * See: https://github.com/seb776/GLSLIncludes */ // Example usage would involve a class or functions to process GLSL strings // and resolve include paths. ``` -------------------------------- ### Metal Shader gl_FragCoord Compatibility Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/README_METAL.md Addresses the compatibility of gl_FragCoord in Metal shaders. It suggests using function definitions that pass [[position]] coordinates from the main shader as a workaround. ```metal // For gl_FragCoord compatibility, use function definitions that pass [[position]] coords // from your main shader entry point. // Example: // fragment float4 main_fragment(float4 position [[position]]) { // // Use position.xy for gl_FragCoord-like behavior // return float4(position.xy, 0.0, 1.0); // } ``` -------------------------------- ### GLSL Name Collision Prevention with #ifndef Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/DESIGN.md Shows the standard Lygia pattern for preventing name collisions in GLSL files using `#ifndef` guards. This ensures that a function definition is only included once, even if the file is included multiple times. ```glsl #ifndef FNC_MYFUNC #define FNC_MYFUNC float myFunc(float in) { return in; } #endif ``` -------------------------------- ### WGSL Function Naming Conventions Source: https://github.com/patriciogonzalezvivo/lygia/blob/main/DESIGN.md Details the specific function naming conventions required in WGSL due to its lack of function overloading. Functions are suffixed based on parameter and return type sizes (e.g., `random2` for `vec2` input, `random21` for `vec2` input and `vec1` output). ```wgsl // Scalar parameter and return type fn random(p: f32) -> f32 { ... } /* Scalar return type, parameter type size indicated by suffix - vec2 -> 2 - vec3 -> 3 - vec4 -> 4 */ fn random2(p: vec2f) -> f32 { ... } fn random3(p: vec3f) -> f32 { ... } fn random3(p: vec4f) -> f32 { ... } /* Inconsistent parameter and return types, two suffixes: - first for return type size - second for parameter type size */ fn random21(p: f32) -> vec2f { ... } fn random22(p: vec2f) -> vec2f { ... } fn random23(p: vec3f) -> vec2f { ... } fn random31(p: f32) -> vec3f { ... } fn random32(p: vec2f) -> vec3f { ... } fn random33(p_: vec3f) -> vec3f { ... } fn random41(p: f32) -> vec4f { ... } fn random42(p: vec2f) -> vec4f { ... } fn random43(p: vec3f) -> vec4f { ... } fn random44(p: vec4f) -> vec4f { ... } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.