npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2024 – Pkg Stats / Ryan Hefner

shader-tailor

v1.0.5

Published

πŸ’… Your personal shader stylist πŸ’…

Downloads

7

Readme

🧡 What's this?

Unleash the power of your Three.js materials with ShaderTailor. Stitch your own shader code into existing Three.js materials, before, after, or in place of any line of shader code you choose. ShaderTailor, where you're the designer and your shaders are the runway models!

πŸš€ Getting Started

Simply install the package via Yarn:

yarn add shader-tailor

Or, if you prefer npm, you can use:

npm install shader-tailor

And import it into your project:

import { shaderTailor } from 'shader-tailor'

πŸ› οΈ How to Use

The core of ShaderTailor is the builder function. It starts with a shader code and you can chain various methods to modify it.

const myShader = '...'
const tailoredShader = shaderTailor(myShader)
  .token('...')
  .replace('...')
  .insertBefore('...')
  .insertAfter('...')
  .exec()

Here's the step-by-step guide on how to thread your masterpiece:

Step 1: Choose your Fabric - .shaderTailor(shader)

Start with a shader code string that you want to modify. This is your raw material!

Step 2: Set the Marker - .token(token)

Sets the token string to look for in the shader code. This is your reference point for the coming changes.

Step 3: Stitch, Replace, or Add - .replace(content), .insertBefore(content), .insertAfter(content)

These methods allow you to modify the shader code around the specified token. You can either replace the token with your own code, insert code before the token, or insert code after the token. Or do all of them!

Step 4: Showtime - .exec()

Finally, call the .exec() method to apply the modifications. This method returns your freshly tailored shader code. VoilΓ , your custom shader is ready for the runway!

πŸ’‘ Examples

Here are some basic examples of how to use ShaderTailor:

const myShader = 'void main() { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); }'
const tailoredShader = shaderTailor(myShader)
  .token('gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);')
  .replace('gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0);')
  .exec()

// tailoredShader now contains: 'void main() { gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0); }'

Using ShaderTailor with Three.js materials' onBeforeCompile function:

import * as THREE from 'three'
import { shaderTailor } from 'shader-tailor'

const material = new THREE.MeshBasicMaterial()

material.onBeforeCompile = (shader) => {
  shader.fragmentShader = shaderTailor(shader.fragmentShader)
    .token('gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);')
    .replace('gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0);')
    .exec()
}

Using ShaderTailor with react-three-fiber materials' onBeforeCompile function:

import * as THREE from 'three'
import { shaderTailor } from 'shader-tailor'

<meshBasicMaterial onBeforeCompile={shader => {
  shader.fragmentShader = shaderTailor(shader.fragmentShader)
    .token('gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);')
    .replace('gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0);')
    .exec()
}} />

πŸ“– License

This project is licensed under the terms of the MIT license.

πŸ™‹β€β™‚οΈ Got Questions?

Feel free to open an issue or submit a pull request. I appreciate your contributions! πŸ₯°