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

lightr

v0.1.1

Published

Bake lighting in HTML5 Canvas using normal maps.

Downloads

4

Readme

Lightr

Bake lighting in HTML5 Canvas using normal maps.

Take this:

diffuse

And this:

normal

And make this:

gif

Usage

Download Lightr.js, the API is pretty simple.

You can also install via npm.

npm install lightr

Lightr.lightHeight

Default 0.5

This controls the Z position of the light source. Currently Lightr only supports a single directional light for baking. Positive values mean the light will be above your sprite, so flat surfaces will get lit.

Lightr.ambientLight

Default [0.1, 0.1, 0.1]

This controls the color / intensity of the ambient light. This value is directly added to the final color, so [1, 1, 1] means your output will be fully white!

Lightr.minLightIntensity

Default 0.0

This controls the minimum light that any one pixel can receive. A value of 0 means that if the surface is facing away from the light source, it will be completely dark. A value of 1 means that all pixels are always fully lit.

Lightr.lightDiffuse

Default [1, 1, 1]

This controls the color of the light source. The default is a plain white light.

Array<Canvas> Lightr.bake(Image diffuseMap, Image normalMap, int numDirs)

This is the function you use to actually bake your lighting out to a set of images. The first two parameters are Image objects, that represent your diffuse (color) map, and the relevant normal map. numDirs is how many divisions of a full circle the lighting should calculate. For example, a value of 4 would give you 4 images back, one for each cardinal direction. A value of 8 gives you 8 images, and so on. I find that 6-8 images is sufficient for most purposes.

The return is an array of Canvas elements containing the rendered out lighting, in counter clockwise order. I utilize these by blending between them at runtime based on the direction of the light to my sprite.

Example

Lightr.minLightIntensity = 0.2;

var diffuse = new Image();
var normal = new Image();
diffuse.src = 'diffuse.png';
normal.src = 'normal.png';

diffuse.onload = function()
{
  normal.onload = function()
  {
    var buffers = Lightr.bake(diffuse, normal, 6);
  };
};

License

MIT