All Projects → luruke → Magicshader

luruke / Magicshader

🔮 Tiny helper for three.js to debug and write shaders

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Magicshader

Sky Shader
☀️ WebGL sky and sun shader editor
Stars: ✭ 90 (-56.1%)
Mutual labels:  webgl, glsl, threejs, shader
Three.meshline
Mesh replacement for THREE.Line
Stars: ✭ 1,644 (+701.95%)
Mutual labels:  webgl, glsl, threejs, shader
Polygon Shredder
The polygon shredder that takes many cubes and turns them into confetti
Stars: ✭ 686 (+234.63%)
Mutual labels:  webgl, glsl, threejs
Wagner
Effects composer for three.js
Stars: ✭ 930 (+353.66%)
Mutual labels:  webgl, glsl, threejs
Glsl Grid
Draws an antialiased grid along the X/Y/Z direction of a mesh.
Stars: ✭ 57 (-72.2%)
Mutual labels:  webgl, glsl, shader
Curtainsjs
curtains.js is a lightweight vanilla WebGL javascript library that turns HTML DOM elements into interactive textured planes.
Stars: ✭ 1,039 (+406.83%)
Mutual labels:  webgl, glsl, shader
Aladino
🧞‍♂️ Your magic WebGL carpet
Stars: ✭ 225 (+9.76%)
Mutual labels:  webgl, glsl, shader
Solarsys
Realistic Solar System simulation with three.js
Stars: ✭ 49 (-76.1%)
Mutual labels:  webgl, glsl, threejs
Three.phenomenon
⭐️ A tiny wrapper around three.js built for high-performance WebGL experiences.
Stars: ✭ 338 (+64.88%)
Mutual labels:  webgl, threejs, shader
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 (+5606.34%)
Mutual labels:  webgl, glsl, shader
Threejs Starter
Stars: ✭ 89 (-56.59%)
Mutual labels:  webgl, glsl, threejs
Glsl Worley
Worley noise implementation for WebGL shaders
Stars: ✭ 66 (-67.8%)
Mutual labels:  webgl, glsl, shader
Sketch
Explorations on cross-hatching, engraving, and similar non-photorealistic rendering.
Stars: ✭ 136 (-33.66%)
Mutual labels:  webgl, glsl, threejs
Glsl Godrays
This module implements a volumetric light scattering effect(godrays)
Stars: ✭ 155 (-24.39%)
Mutual labels:  webgl, glsl, shader
Droneworld
droneWorld: a 3D world map and a three.js playground
Stars: ✭ 197 (-3.9%)
Mutual labels:  webgl, threejs
Threejs Path Flow
🐬🐟 ↶Mesh Deformation / Bending / Following on a Curve
Stars: ✭ 165 (-19.51%)
Mutual labels:  webgl, threejs
React Three Next
React Three Fiber, Nextjs, Tailwind starter
Stars: ✭ 195 (-4.88%)
Mutual labels:  webgl, threejs
Expo Voxel
🎮🌳 Voxel Terrain made in React Native. ∛
Stars: ✭ 169 (-17.56%)
Mutual labels:  webgl, threejs
Threejs Sandbox
Set of experiments and extensions to THREE.js.
Stars: ✭ 163 (-20.49%)
Mutual labels:  webgl, threejs
React Globe
Create beautiful and interactive React + ThreeJS globe visualizations with ease.
Stars: ✭ 167 (-18.54%)
Mutual labels:  webgl, threejs

🔮 MagicShader

⚠️ probably won't work with modern version of threejs, last time I tested was with r114
pr is welcome

A thin wrapper on top of RawShaderMaterial, that allows to easily create new uniforms and live-edit them via dat.gui.

No need to create the uniforms manually and bind them with dat.gui.
Just write some comments in your GLSL, and everything will work magically ✨

🕵️‍♂️ How to use

Install via npm

npm i -D magicshader

and just use it instead of RawShaderMaterial:

import MagicShader from 'magicshader';

const material = new MagicShader({...})

The parameters are exactly the same.

🤷‍♀️ Ok...where the magic is?

Now you can add the // ms({}) magic comment after your uniforms.

Example:

const material = new MagicShader({
  vertexShader: `
    precision highp float;
    
    attribute vec3 position;
    uniform mat4 modelViewMatrix;
    uniform mat4 projectionMatrix;
    
    void main() {
      gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
    }
  `,
  fragmentShader: `
    precision highp float;

    uniform vec3 color; // ms({ value: '#ff0000' })

    void main() {
      gl_FragColor = vec4(color, 1.0);
    }
  `
});

This will give you:
1

No need to init your uniform or bind dat.gui.
You can just work on your GLSL files.

👨‍💻 What else?

const material = new MagicShader({
  name: 'Cube Shader!',
  vertexShader: `
    precision highp float;
    
    attribute vec3 position;
    uniform mat4 modelViewMatrix;
    uniform mat4 projectionMatrix;

    uniform vec3 translate; // ms({ value: [0, 0, 0], step: 0.01 })
    uniform float scale; // ms({ value: 0.5, options: { small: 0.5, medium: 1, big: 2 } })
    uniform mat4 aMatrix4; // ms({ value: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] })

    void main() {
      vec3 pos = position + translate;
      pos *= scale;

      gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
    }
  `,
  fragmentShader: `
    precision highp float;
    
    uniform vec3 color; // ms({ value: '#ff0000' })
    uniform float brightness; // ms({ value: 0, range: [0, 0.5], step: 0.1 })
    uniform vec2 dummyValue; // ms({ value: [1024, 768], range: [[0, 2000], [0, 1500]] })
    uniform bool visible; // ms({ value: 1, name: 'Visibility' })
    uniform int test; // ms({ value: 0 })

    void main() {
      gl_FragColor = vec4(color + brightness, 1.0);
    }
  `
});

Will result in:
full

🕵️‍ SpectorJS

With the SpectorJS extension enabled, you can live-edit the shaders. You can even add and modify "magic" uniforms on the fly.

full

💅 Ok, cool. Just finished my app and I'm ready to deploy

Then you can hide the dat.gui UI

import MagicShader, { gui } from 'magicshader';
gui.destroy();

😴 TODO

  • [ ] Do more tests...
  • [ ] add support for sampler2D and FBO?
  • [ ] check if it works with firefox/safari shader editor
  • [ ] inspect/edit threejs default uniforms (like projectionMatrix)
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].