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

shader3

v1.0.0-beta0.3

Published

A Three.js materials library with customizable shaders and noise functions.

Downloads

196

Readme

Shader3 - Material Lab

Shader3-Logo

Shader3 is a library that extends and customizes built-in Three.js materials, providing enhanced flexibility and control over 3D rendering. With support for shader customization and a suite of noise functions, it enables the creation of unique visual effects for advanced 3D experiences.

✨ Features

  • Custom Shader Materials: Extend and customize materials like MeshPhysicalMaterial , MeshDepthMaterial for your 3D objects.
  • Shader Customization: Modify vertex and fragment shaders with ease for fine-tuned rendering effects.
  • Noise Functions: A range of noise functions (e.g., Perlin, Simplex) for adding dynamic visual effects to your shaders.

📦 Installation

Install Shader3 using your preferred package manager:

npm install shader3

or

yarn add shader3

Importing Shader3

You can import the full library or specific materials depending on your project needs:

import * as Shader3 from "shader3"; // import all

Or for selective imports:

import { PhysicalShaderMaterial } from "shader3"; // import specific material

Alternatively use the standalone version found in ./dist locally

<script
  type="text/javascript"
  src="https://unpkg.com/shader3/dist/shader3.js"
></script>

<!-- This will give Shader3 -->

🛠️ Usage

Creating Custom Materials

Shader3-Demo

Usage

To create and use a custom material, follow the example below:

import * as Shader3 from "shader3"; // import all

const material = new Shader3.PhysicalShaderMaterial({
  vertexShader: `
    uniform float time; 
    void main () {
      s3_position.y += sin(s3_position.x + time);
    }
  `,
  fragmentShader: `
    uniform float time;
    void main () {
      gl_FragColor = gl_FragColor * 1.5;
    }
  `,
  uniforms: {
    time: { value: 0.0 },
  },
});

In this example, the PhysicalShaderMaterial is extended with custom vertex and fragment shaders to create a dynamic effect.

Updating Uniforms

Updating uniforms is as simple as modifying material properties, just like adjusting roughness:

material.time = elapsedTime; // Dynamically update time uniform

📜 Material APIs

Shader3 provides several extended material classes, each supporting custom shaders and uniforms:

PhysicalShaderMaterial

  • Extends THREE.MeshPhysicalMaterial.
  • Supports custom vertex and fragment shaders with additional uniform handling.

StandardShaderMaterial

  • Extends THREE.MeshStandardMaterial.
  • Customizable vertex and fragment shaders.

DepthShaderMaterial

  • Extends THREE.MeshDepthMaterial.
  • Allows shader customization for depth rendering.

MatcapShaderMaterial

  • Extends THREE.MeshMatcapMaterial.
  • Full shader and uniform customization support.

🌐 Noise Functions

Shader3 provides a variety of noise functions to enhance your visual effects. Here's an example using Perlin noise in a vertex shader:

import { perlin } from "shader3";

const vertexShader = `
${perlin}  // Add Perlin noise function
void main () {
  s3_position.y += perlin(s3_position);  // Apply noise
}`;

The following noise functions are included by default in Shader3:

perlin

  • Description: Implements Perlin noise for 2D and 3D vectors.
  • Functions:
    • perlin(P: vec2): float
      Returns the Perlin noise value for a 2D input vector.
    • perlin(P: vec3): float
      Returns the Perlin noise value for a 3D input vector.
    • perlin(P: vec3, rep: vec3): float
      Returns repeatable Perlin noise for a 3D input vector with repetition.

fbm

  • Description: Implements fractal Brownian motion (fBm) noise.
  • Functions:
    • fbm(P: float): float
      Returns fBm noise for a 1D input.
    • fbm(P: vec2): float
      Returns fBm noise for a 2D input.
    • fbm(P: vec3): float
      Returns fBm noise for a 3D input.
    • fbm(P: vec4): float
      Returns fBm noise for a 4D input.

simplex

  • Description: Implements Simplex noise for generating smooth gradients in 2D or 3D space.
  • Functions:
    • simplex(P: vec2): float
      Returns the Simplex noise value for a 2D input vector.
    • simplex(P: vec3): float
      Returns the Simplex noise value for a 3D input vector.
    • simplex(P: vec4): float
      Returns the Simplex noise value for a 4D input vector.
    • simplexFractal(P: vec3): float
      Returns the Simplex Fractal noise value for a 3D input vector.

truchetPattern

  • Description: Generates a Truchet pattern based on the input values.

  • Parameters:

    • s: A 2D vector input.
    • i: A floating-point index to determine the pattern variation.
    float pattern = truchetPattern(vec2(0.5, 0.8), 2.0);

🤝 Contributing

We welcome contributions! If you have ideas for new features, bug fixes, or improvements, feel free to open an issue or submit a pull request on our GitHub repository.

📄 License

Shader3 is licensed under the MIT License. For more information, refer to the LICENSE file.

🙌 Acknowledgements

  • Three.js: The core library for 3D rendering.
  • GLSL: The language used for shader programming.