All Projects → FarazzShaikh → glNoise

FarazzShaikh / glNoise

Licence: MIT license
A collection of GLSL noise functions for use with WebGL with an easy to use API.

Programming Languages

GLSL
2045 projects
typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects
CSS
56736 projects

Projects that are alternatives of or similar to glNoise

FNode
Tool based in nodes to build GLSL shaders without any programming knowledge written in C using OpenGL and GLFW.
Stars: ✭ 81 (-56.22%)
Mutual labels:  shaders, glsl, glsl-shaders
deffx
A collection of useful shader effects made ready to be used with the Defold game engine
Stars: ✭ 33 (-82.16%)
Mutual labels:  shaders, glsl, glsl-shaders
Shader-Playgrounds
A WebGL shaders editor for beginners and otherwise.
Stars: ✭ 28 (-84.86%)
Mutual labels:  shaders, glsl, webgl2
Retrace.gl
Create, ray trace & export programatically defined Signed Distance Function CSG geometries with an API suited for generative art - in your browser! 🎉
Stars: ✭ 149 (-19.46%)
Mutual labels:  shaders, glsl, webgl2
Webgl Fundamentals
WebGL lessons that start with the basics
Stars: ✭ 3,315 (+1691.89%)
Mutual labels:  shaders, glsl, glsl-shaders
ModularMusicVisualizer
Project in Hiatus, unmaintained, being rewritten privately. Will Open Source when stuff is ready. Project will be Renamed.
Stars: ✭ 81 (-56.22%)
Mutual labels:  shaders, glsl, glsl-shaders
ShaderView
ShaderView is an Android View that makes it easy to use GLSL shaders for your app. It's the modern way to use shaders for Android instead of RenderScript.
Stars: ✭ 53 (-71.35%)
Mutual labels:  shaders, glsl, glsl-shaders
kotlin-glsl
Write your GLSL shaders in Kotlin.
Stars: ✭ 30 (-83.78%)
Mutual labels:  shaders, glsl, glsl-shaders
React Regl
React Fiber Reconciler Renderer for Regl WebGL
Stars: ✭ 171 (-7.57%)
Mutual labels:  shaders, glsl, glsl-shaders
YALCT
Yet Another Live Coding Tool - Powered by Veldrid and elbow grease
Stars: ✭ 25 (-86.49%)
Mutual labels:  shaders, glsl, glsl-shaders
30-days-of-shade
30 days of shaders in GLSL using GLSLCanvas
Stars: ✭ 134 (-27.57%)
Mutual labels:  shaders, glsl, glsl-shaders
Curtainsjs
curtains.js is a lightweight vanilla WebGL javascript library that turns HTML DOM elements into interactive textured planes.
Stars: ✭ 1,039 (+461.62%)
Mutual labels:  shaders, glsl, webgl2
Thebookofshaders
Step-by-step guide through the abstract and complex universe of Fragment Shaders.
Stars: ✭ 4,070 (+2100%)
Mutual labels:  shaders, glsl, glsl-shaders
3d Game Shaders For Beginners
🎮 A step-by-step guide to implementing SSAO, depth of field, lighting, normal mapping, and more for your 3D game.
Stars: ✭ 11,698 (+6223.24%)
Mutual labels:  shaders, glsl, glsl-shaders
Bookofshaders Godot
BookOfShaders in Godot Shader Language
Stars: ✭ 134 (-27.57%)
Mutual labels:  shaders, glsl
Fsynth
Web-based and pixels-based collaborative synthesizer
Stars: ✭ 146 (-21.08%)
Mutual labels:  shaders, glsl
NobleRT
A Minecraft shaderpack that enhances one's experience with the help of good-looking graphics and light simulations.
Stars: ✭ 76 (-58.92%)
Mutual labels:  shaders, glsl
Wisdom Shaders
A Minecraft shaderspack. Offers high performance with high quality at the same time.
Stars: ✭ 132 (-28.65%)
Mutual labels:  shaders, glsl
Reshade
A generic post-processing injector for games and video software.
Stars: ✭ 2,285 (+1135.14%)
Mutual labels:  shaders, glsl
procedural-tileable-shaders
Collection of tileable procedural textures such as: cellular noise, fbm, voronoi, perlin and other.
Stars: ✭ 175 (-5.41%)
Mutual labels:  shaders, glsl

Logo

gl-Noise

A collection of GLSL noise functions for use with WebGL with an easy to use API.
View Demo · Report Bug · API Docs

Table of Contents
  1. Why This?
  2. Installation
  3. Importing
  4. Usage - JavaScript
  5. Usage - GLSL
  6. Credits

Bubbles Take Control Take Control

These demos are real, you can click them! They contain the full code, too. 📦


Why this?

There already exist excellent resources that compile a list of algorithms such as:

And many more. But they all either require another library like Glslify or require you to manually copy and paste them into your shader code.

So this library addresses both those issues. It does not require any third-party libraries and you can include and use these noise functions without even having to give it a second thought.

Examples can be found in the examples directory.

Installation

$ npm i gl-noise

or

$ yarn add gl-noise

gl-Noise uses ES Modules, in the browser, simply declare your script as a module and then import it as you would in node.

<script src="./main.js" type="module"></script>
<!--                         👆 This lets you use ES Module import syntax-->

Importing

If you are on Node, you can import like so:

import {
    // Loaders
    loadShaders,
    loadShadersRaw,
    loadShadersCSM,

    // Individual Shader Chunks
    Perlin,
    Simplex,
    Voronoi
} from "gl-noise"

In browsers (Chrome Desktop only), if you'd like to use NPM and the Node syntax then you will have to add an import-map to your HTML. Simply place this code above your script.

<script type="importmap">
{
    "imports": {
        "gl-noise": "/node_modules/gl-noise/build/glNoise.m.js",
    }
}
</script>

Then you can use Node-like imports:

import {} from "gl-noise"
//                 👆 Notice, we don't have to specify the
//                    whole path (node_modules/.../...).
//                    If you don't use the import-map, then
//                    you will have to specify the path.

In browsers, You can also download build/glNoise.m.js and import it from wherever you want to save it as an ES Module. Alternatively, you can also download the IIFE type module from build/glNoise.js and include it in a script tag like people have been doing forever.

<script src="lib/glNoise.js"></script>
<script src="./main.js"></script>

Usage - JavaScript

Shader Chunks

A Shader Chunk is a self-contained piece of shader code that can be injected and used in a shader program. gl-Noise provides various Shader Chunks.

import {
    Perlin,     // 👈 2D Perlin Noise
    Simplex,    // 👈 2D Simplex Noise
    Voronoi     // 👈 2D Voronoi Noise
} from "gl-noise"

It also has a bunch of utility functions. See the API Reference for more info on all available functions.

You can load these chunks along with shaders as you will see in the next section.

Loaders

Loaders are being deprecated in this package and being moved to a new one. Sorry.

Patching

patchShaders

This function patches shaders with the provided chunks. The chunks can be imported from gl-Noise and are just strings that will be appended to each shader.

import { Perlin, Simplex, Common } from "gl-noise"
import { CustomChunk } from "custom/path.glsl"

const _vertexShader = `
    void main() {
        gl_Position = ...
    }
`

const _fragmentShader = `
    void main() {
        gl_FragColor = ...
    }
`

// Patch a shader...
const vertexShader = await patchShaders(_vertexShader);

// ...or many at once
const [vertexShader, fragmentShader] = await patchShaders([_vertexShader, _fragmentShader]);


// Load specific chunks. If undefined or NULL, 
// only the "Common" shader chunk will be appened
const chunks = [
    [Perlin, Simplex],  // 👈 Chunks to include with vertexShader
    null,                       // 👈 Chunks to include with fragmentSha
]

const vertexShader = await patchShaders(_vertexShader, chunks);

patchShadersCSM

This function is to be used with THREE-CustomShaderMaterial. It appends shader chunks to the header section of the provided inputs.

const CSM_Shaders_= {
  defines: `...`,
  header: `...`,
  main: `...`,
};

const CSM_Chunks = [Perlin, Simplex]

// Loads shaders with CSM Friendly format
const CSM_Patched = await loadShadersCSM(CSM_Shaders_, CSM_Chunks)
const { defines, header, main } = CSM_Patched;

Usage - GLSL

Once the chunks are imported properly, using gl-Noise Within GLSL is a breeze. All you have to do is call the function you want with the right arguments.

float p = gln_perlin(uv);
float n = gln_normalize(p);

See the full list of available functions in the API Reference.

Development

The concept is pretty simple. You can fork it and write your GLSL functions in a file with the .glsl extension in the src directory. The function must be shader independent so no use of gl_FragCoord or any shader-specific variables.

Each new file must begin with the name directive like so:

// #name: <File Name without extension>

If your function requires functions from other files in this library, include the deps directive like so:

// #name: <File Name without extension>
// #deps: <Dependancy Name 1> <Dependancy Name 2> ... <Dependancy Name n>

You can document your code using JSDoc style comment blocks. The documentation is auto-generated so you MUST include a @name with the name of your function. See the preexisting functions for reference. This is because

Include your file in index.ts by importing it and exporting it like all the preexisting files. Make sure to include your new file in the _all array.

That's it. You can see if it builds by running

npm run build

It's ideal if you'd include your new noise function as an example but not required.

Credits

I have not come up with these noise functions. Here's attribution to the creators of them.

Noise Maker Reference License
Perlin Noise Hugh Kennedy GitHub MIT
Simplex Noise Ian McEwan GitHub MIT
Worley Noise Max Bittker GitHub MIT
Curl Noise Isaac Cohen GitHub ???

Every other function is by yours truly.

Note: Simplex Noise is patented. The one used here is just an approximation.

If you see your function being used in this library, please open an issue so I can credit you or remove the function ASAP.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].