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

glsl-godrays

v1.0.2

Published

Shader function for rendering godrays(volumetric light scattering).

Downloads

52

Readme

glsl-godrays

This module implements the volumetric light scattering effect(godrays) described in "Volumetric Light Scattering as a Post-Process" as a GLSL shader. A demo is provided at: http://erkaman.github.io/glsl-godrays/

The camera in the demo is controlled as follows:

  • Keys W and S are used to walk forward and backward.
  • Keys A and D are used to stride left and right.
  • Keys O and L are used to fly up and down.
  • Hold down the key M to speed up the camera.
  • Hold down the left mouse button and move the mouse to turn the camera.

text

NPM

Rendering Setup

In order to implement the effect, no less than three rendering passes will have to be done:

  • Pass 1: Render all geometry that could occlude the light source as black. Normally render light source. And render all the above to a texture called the "occlusion texture". Note that this texture does not have to be exactly the size of the screen, but it can be smaller. And by making it smaller, lots of performance can be gained.

  • Pass 2: Render everything normally, to the default framebuffer.

  • Pass 3: Now enable alpha blending, because we will render the volumetric light rays in a fullscreen pass, and combine them with the scene rendered in pass 2 by simply using alpha blending. Also, as input to pass 3, is the "occlusion texture" that was rendered to in pass 1. This texture is used to ensure that unnatural streaks of light do not appear on objects that are occluding the light source.

For more details, please refer to the source code of the provided demo.

Shader Usage

In the third pass, the godrays are rendered in a fullscreen pass, where every fragment gets its color from the following function:

vec3 godrays(
    float density,
    float weight,
    float decay,
    float exposure,
    int numSamples,
    sampler2D occlusionTexture,
    vec2 screenSpaceLightPos,
    vec2 uv
    );

Where the parameters are

  • density please refer to the article "Volumetric Light Scattering as a Post-Process" for a definition of this parameter.
  • weight see the above.
  • decay see the above.
  • exposure see the above.
  • numSamples see the above. However, note that the maximum value of this parameter is 100!
  • occlusionTexture the "occlusion texture" created in pass 1.
  • screenSpaceLightPos the light position in screen space. In the source code of the demo it is shown how this can be calculated.
  • uv the coordinates of the current fragment. Note that x and y should both be in the interval [0,1], over the entire screen.