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

gl-material

v1.0.0

Published

define materials for 3d scenes

Downloads

4

Readme

gl-material

NPM version experimental js-standard-style

Standard format and constructor for reusable 3d materials.

A material is defined as an object with three properties:

  • fragment a fragment shader
  • styles a object describing all parameters that can vary, grouped into a single struct in the shader
  • name a string

Why is this useful? By using a common format, we can publish and share materials as npm modules! It's slightly higher level than publishing raw shader code, and lets us specify shaders alongside their parameters.

This module exposes a single function that takes an object in the standard format and generates a compiled shader program using gl-shader and glslify, by adding a generic vertex shader (see below), and optionally performing string replacement for constants.

install

Add to your project with

npm install gl-material

modules

The following modules can help you work with materials:

And the following materials are published as npm modules:

If you make one, publish it to npm as gl-material-x, and submit a PR to this repo to add it to the list!

example

Here's the definition of a flat material determined by a color:

var flat = {
	fragment: `precision highp float;\ 
		struct Style {\
			vec3 color;\
		};\
		uniform Style style;\
		void main() {\
			gl_FragColor = vec4(style.color, 1.0);\
		}`
	styles: {
		color: {type: 'vec3', default: [0, 100, 0]}
	},
	name: 'my-flat-material'
}

and we can construct a compiled shader program from this object

var material = require('gl-material')(gl, flat)

usage

material = require('gl-material')(gl, data, [constants])

Generate a compiled shader program for your material by providing these arguments

  • gl webgl context
  • data object with material data
  • constants optional mapping from string keys to values with which to replace them, e.g {LIGHTCOUNT: 1}

The result has two properties

  • material.shader compiled shader program
  • material.defaults default value for each style

vertex shader

The included vertex shader is generic, and has the following properties, which should cover a variety of use cases:

attributes

  • position vec3
  • normal vec3
  • uv vec2

uniforms

  • projection mat4
  • view mat4
  • model mat4
  • modelNormal mat3

varying properties provided to the fragment shader

  • vposition vec3
  • vnormal vec3
  • vuv vec3