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

babylon-deferred-lights

v0.0.20

Published

A deferred lighting solution for babylonjs

Downloads

682

Readme

Deferred Lighting

A deferred lighting solution for babylonjs.

What's deferred lighting? In a nutshell, 1000s of lights w/ no lag. (You can read more here)

npm: https://www.npmjs.com/package/babylon-deferred-lighting

demo: https://babylon-deferred-lighting.netlify.app/

Right now this only supports point lights, this will change.

How to use

import { DeferredPointLight } from "babylon-deferred-lighting";
import { Effect } from "@babylonjs/core/Materials/effect";

// ...

DeferredPointLight.reset(); // reset the lighting system
const scene = new BABYLON.Scene(engine);

//...

// enable the lighting system
DeferredPointLight.enable(
  scene,
  Effect.ShadersStore,
  /** camera, activeCamera by default */ null,
  /** GBuffer if you wanna use one */ null,
  /** performance mode */ false
);

Start by importing the deferred point light.

Reset the lighting system before you make your scene and enable it.

if you plan to use fewer than about 150 lights, performance mode will be fare better on low spec devices. Otherwise keep it turned off.

const light = new DeferredPointLight({  // All these are optional, you don't even need to pass in an object.
  position: BABYLON.Vector3.Zero(),    // position of the light
  color: BABYLON.Color3.Red(),        // color of the light 
  intensity: 0.2,                    // intensity of the light
  range: 2,                         // range of the light (beyond this, the light won't be visible, 0 means infinite range)
});

// set params after the light is made
light.position = new BABYLON.Vector3(1, 2, 3);
light.color = BABYLON.Color3.Blue();
light.intensity = 0.5;
light.range = 10;

light.isVisible = false; // make light invisible
light.alwaysSelectAsActiveLight = true // turns off frustum culling for this light and always tries to render it

You can make a light like so and control the parameters as you see fit.

// add the light to the system
DeferredPointLight.add(light);

// make a new light and add it at the same time
const uniqueId = DeferredPointLight.add({
  position: BABYLON.Vector3.Zero(),
  color: BABYLON.Color3.Red(),
  intensity: 0.2,
  range: 2,
});

// get the light we just made
const newLight = DeferredPointLight.getById(uniqueId);

// get all the lights
const allLights = DeferredPointLight.getAll();

// get all visible and active lights
const allVisibleActiveLights = DeferredPointLight.getAll({ active: true, visible: true });

// remove the lights
DeferredPointLight.remove(uniqueId); // by id
DeferredPointLight.remove(light); // or by object

After making the light, you have to add it to the system to see any effect.

You can also skip the making part and just pass the options to add, it will make a new light w/ those options to add.

You can get a light from the system if you have its id. or you can get all lights, or all active and/or visible lights.

once you're done w/ a light, go ahead and remove it from the system.

DeferredPointLight.freezeActive(); // disable frustum culling
DeferredPointLight.unfreezeActive(); // enable frustum culling

You can enable and disable frustum culling (cpu filtering out lights that are off screen) if you need it.

DeferredPointLight.TOTAL_LIGHTS_ALLOWED = 2000; // default: 1024
DeferredPointLight.TOTAL_PERFORMANCE_LIGHTS_ALLOWED = 200; // default: 128

You can decide the max cap for lights in normal and performance mode (don't go too high on performance mode)

The cap is evaluated after frustum culling, so it's the maximum cap of simultaneous lights on screen.

const pp = DeferredPointLight.postprocess;

You can get the postprocess that is doing all the lighting calclulations.

DeferredPointLight.disable();

You can get rid of the entire system once you no longer need it.

Have fun :)