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

three-wboit

v1.0.15

Published

Weighted, blended order independent transparency pass for use with three.js.

Downloads

754

Readme

Three Wboit

Weighted, Blended Order Independent Transparency (paper, blog) for use with three.js. This implementation is designed as a rendering Pass. It can be used as a stand-alone replacement for a traditional render pass (i.e. renderer.render), or used as part of a larger rendering stack within Effect Composer.

Examples

  • Stand-Alone
    • Transparent Scene Demos
  • Scene Composer
    • Material Patching Demos
  • Three Versions
    • Patching Three v148 and older
    • Patching Three v149 to v151
    • Patching Three v152 and newer

More Info

There are several common techniques available for order independent transparency. This implementation uses Weighted, Blended Order-Indepent Transparency (WBOIT), both for it's high performance and also compatibility on slower hardware. This implementation is WebGL 1 compatible and mobile friendly.

One of the biggest advantages of order independent transparency is for the rendering of detailed transparent models. Typically when rendering such a model, it is common for some faces to be depth culled. When rendering with WBOIT, all faces will be visible. WBOIT is approximate, though, and while it provides good results it may not be appropriate for all use cases.

There are a variety of weight functions available when rendering with WBOIT. This is partially due to inconsistencies in rendering overlapping pixels at varying depths. Some weight functions are better at incorporating camera near / far planes, some are better at handling larger groups of overlapping triangles. This implementation includes a weight modifier within MeshWboitMaterial that attempts to adjust the weight function for both opacity and color depending on the depth of the fragments.

The biggest downside of this method is that due to the blending method used, as opacity approaches 1.0 objects still retain an artifically high amount of transparency. WBOIT enabled materials can be made opaque during the render pass by setting the material property transparent to false.

Install

  • Option 1: Copy files from src directory into project, import from files...
import { MeshWboitMaterial } from './materials/MeshWboitMaterial.js';
import { WboitPass } from './WboitPass.js';
  • Option 2: Install from npm, import from 'three-wboit'...
npm install three-wboit
import { MeshWboitMaterial, WboitPass } from 'three-wboit';
  • Option 3: Import directly from CDN...
import { MeshWboitMaterial, WboitPass } from 'https://unpkg.com/three-wboit/build/index.module.js';

Usage

To setup your scene to use WBOIT, create an instance of WboitPass.

When creating Mesh objects intended to be transparent, use the included material MeshWboitMaterial. Objects using this material have WBOIT enabled by default. WBOIT can be turned on / off on each object by setting the material's transparent property. The material is functionaly equivalent to MeshBasicMaterial, and supports all it's methods and properties.

When rendering your scene, instead of calling renderer.render(), call wboitPass.render( renderer ). Enjoy.

import * as THREE from 'three';

import { MeshWboitMaterial, WboitPass } from 'three-wboit';

const renderer = new THREE.WebGLRenderer( { preserveDrawingBuffer: true } );

const camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.10, 100 );

const scene = new THREE.Scene();
scene.add( new THREE.BoxGeometry(), new MeshWboitMaterial( { opacity: 0.5 } ) );

const wboitPass = new WboitPass( renderer, scene, camera, 0 /* optional clear color */, 1.0 /* optional clear alpha */);

...

render() {

    // OLD:
    //  renderer.render( scene, camera );

    // NEW:
    wboitPass.render( renderer );

}

Patching Materials

To use WboitPass with any existing material, use the included utility function WboitUtils.patch()

import * as THREE from 'three';

import { WboitUtils } from 'three-wboit';

const material = new THREE.MeshStandardMaterial();
WboitUtils.patch( material );

const myMesh = new THREE.Mesh( new THREE.BoxGeometry(), material );

NOTE: Three.js has made some changes to the renderer from versions v148 through v152, including how it renders transparent objects and how it deals with color space. For versions prior to 152 it is recommended to use the version of this library v1.0.13.

Acknowledgements

  • Weighted, Blended Order-Independent Transparency by Morgan McGuire and Louis Bavoil - Paper
  • Weighted, Blended WebGL 2 Example by Tarek Sherif @tsherif - Repo
  • Weighted, Blended Three.js Example by Alexander Rose @arose - Issue
  • Depth Peel Three.js Example by Dusan Bosnjak @pailhead - Pull