0.0.5 • Published 3 years ago

shader-doodle v0.0.5

Weekly downloads
402
License
MIT
Repository
github
Last release
3 years ago

<shader-doodle />

Latest NPM release License

A friendly web-component for writing and rendering shaders.

demo

NOTE: this README and branch are for the new <shader-doodle /> alpha. To view the current stable version go to the v0 branch.

<shader-doodle /> is a simple web-component loosely based on the The Book of Shaders's glsl previewer and Shadertoy. It sets up a flat responsive canvas on which to draw fragment shaders, and provides several built in uniforms relating to time, resolution, mouse position, etc.

Usage

Script Include

<script src="https://unpkg.com/shader-doodle"></script>
<shader-doodle>
  <script type="x-shader/x-fragment">
    void main() {
      vec2 st = gl_FragCoord.xy / u_resolution.xy;
      vec3 color = vec3(st.x, st.y, abs(sin(u_time)));

      gl_FragColor = vec4(color, 1.0);
    }
  </script>
</shader-doodle>

Import

npm install shader-doodle

import 'shader-doodle';
<shader-doodle>
  <script type="x-shader/x-fragment">
    void main() {
      vec2 st = gl_FragCoord.xy / u_resolution.xy;
      vec3 color = vec3(st.x, st.y, abs(sin(u_time)));

      gl_FragColor = vec4(color, 1.0);
    }
  </script>
</shader-doodle>

API

Right now the api is fairly basic. The default syntax is vanilla glsl and there are several built in uniforms following the conventions seen in The Book of Shaders. If you prefer ShaderToy's syntax you can set an attribute like so: <shader-doodle shadertoy />.

Pre-Defined Uniforms

Default (<shader-doodle />)

  • uniform float u_time;: shader playback time (in seconds)
  • uniform float u_delta;: delta time between frames (in seconds)
  • uniform int u_frame;: shader playback frame
  • uniform vec4 u_date;: year, month, day and seconds
  • uniform vec2 u_resolution;: viewport resolution (in pixels)
  • uniform vec2 u_mouse;: mouse pixel coords (x & y)

Shadertoy (<shader-doodle shadertoy />)

  • uniform float iTime;: shader playback time (in seconds)
  • uniform float iDelta;: delta time between frames (in seconds)
  • uniform int iFrame;: shader playback frame
  • uniform vec4 iDate;: year, month, day and seconds
  • uniform vec2 iResolution;: viewport resolution (in pixels)
  • uniform vec4 iMouse;: -- mouse pixel coords. xy: current (if mousedown), zw: click.

NOTE: the only functional difference is in mouse position behavior

Next steps (ordered by priority)

  • shader precision attribute
  • clearColor attribute
  • touch support for mouse uniform
  • uniforms for device orientation & gyro
  • lerp attribute for mouse
  • custom uniform component
  • webgl2
  • api for multi-pass?

See Also

1.0.0-alpha.20

3 years ago

1.0.0-alpha.19

4 years ago

1.0.0-alpha.18

4 years ago

1.0.0-alpha.17

4 years ago

1.0.0-alpha.16

4 years ago

1.0.0-alpha.15

4 years ago

1.0.0-alpha.14

4 years ago

1.0.0-alpha.13

4 years ago

1.0.0-alpha.12

4 years ago

1.0.0-alpha.11

4 years ago

1.0.0-alpha.10

4 years ago

1.0.0-alpha.9

4 years ago

1.0.0-alpha.8

5 years ago

1.0.0-alpha.7

5 years ago

1.0.0-alpha.6

5 years ago

1.0.0-alpha.5

5 years ago

1.0.0-alpha.4

5 years ago

1.0.0-alpha.3

5 years ago

1.0.0-alpha.2

5 years ago

1.0.0-alpha.1

5 years ago

1.0.0-alpha.0

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago