2.0.0 • Published 12 months ago

shaded-image v2.0.0

Weekly downloads
7
License
MIT
Repository
-
Last release
12 months ago

shaded-image

Apply a stack of post-processing style shaders to a static image

Note When using React, I recommend using the React component wrapper shaded-image-react

NPM JavaScript Style Guide

Install

npm install shaded-image

Usage

Inbuilt Components

You can use one of the inbuilt effect components

<head>
  <script type="module">
    import "shaded-image";
  </script>
</head>
<body>
  <div style="display: flex">
    <si-greyscale-image image="./image.svg" class="logo" />
  </div>
</body>
<head>
  <script type="module">
    import "shaded-image";
  </script>
</head>
<body>
  <div style="display: flex">
    <si-anim-test-image image="./image.svg" class="logo" />
  </div>
</body>
`;

Custom Effects

You can create your own custom effects by defining a glsl fragment and vertex shader. Uniform and Varying values can be set using initFunction and updateFunction

GrayscaleImage.js

<head>
  <script type="module">
    import "shaded-image";
    const fragmentShader = `
      varying highp vec2 vTextureCoord;
      uniform sampler2D uSampler;

      void main(void) {
      	lowp vec4 tex = texture2D(uSampler, vTextureCoord);
      	lowp float col = (0.2126 * tex.r + 0.7152 * tex.g + 0.0722*tex.b);
      	gl_FragColor = vec4(col, col, col, tex.a);
      }

      `;
    const vertexShader = `
      attribute vec3 aVertexPosition;
      attribute vec2 aTextureCoord;

      varying highp vec2 vTextureCoord;

      void main(void) {
      	gl_Position =  vec4(aVertexPosition.xy, 0.0, 1.0);
      	vTextureCoord = aTextureCoord;
      }
    `;
    const shaders = [
      {
        vertexShader: vertexShader,
        fragmentShader: fragmentShader,
        initFunction: (args) => {},
        updateFunction: (args) => {},
      },
    ];

    const greyImage = document.querySelector("#example");
    greyImage.shaders = shaders;
  </script>
</head>
<body>
  <div style="display: flex">
    <si-shaded-image id="example" image="./image.svg" class="logo" />
  </div>
</body>

License

MIT © benjaminARowe

2.0.0

12 months ago

1.1.0

3 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago