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-atmosphere

v2.0.0

Published

Renders sky colors with Rayleigh and Mie scattering.

Downloads

25

Readme

glsl-atmosphere

Renders sky colors with Rayleigh and Mie scattering.

Demo

Install

npm install glsl-atmosphere

Example

Javascript

var quad = Geometry(gl)
    .attr('aPosition', [
        -1, -1, -1,
         1, -1, -1,
         1,  1, -1,
        -1, -1, -1,
         1,  1, -1,
        -1,  1, -1
    ]);

program.bind();
quad.bind(program);
program.uniforms.uSunPos = [0, 0.1, -1];
quad.draw();

Vertex Shader

attribute vec3 aPosition;

varying vec3 vPosition;

void main() {
    gl_Position = vec4(aPosition, 1.0);
    vPosition = aPosition;
}

Fragment Shader

varying vec3 vPosition;

uniform vec3 uSunPos;

#pragma glslify: atmosphere = require(glsl-atmosphere)

void main() {
    vec3 color = atmosphere(
        normalize(vPosition),           // normalized ray direction
        vec3(0,6372e3,0),               // ray origin
        uSunPos,                        // position of the sun
        22.0,                           // intensity of the sun
        6371e3,                         // radius of the planet in meters
        6471e3,                         // radius of the atmosphere in meters
        vec3(5.5e-6, 13.0e-6, 22.4e-6), // Rayleigh scattering coefficient
        21e-6,                          // Mie scattering coefficient
        8e3,                            // Rayleigh scale height
        1.2e3,                          // Mie scale height
        0.758                           // Mie preferred scattering direction
    );

    // Apply exposure.
    color = 1.0 - exp(-1.0 * color);

    gl_FragColor = vec4(color, 1);
}

API

#pragma glslify: atmosphere = require(glsl-atmosphere)

vec3 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAtmos, vec3 kRlh, float kMie, float shRlh, float shMie, float g)

Returns a vec3 representing the color of the sky along a view direction.

Takes:

  • vec3 r normalized ray direction, typically a ray cast from the observers eye through a pixel
  • vec3 r0 ray origin in meters, typically the position of the viewer's eye
  • vec3 pSun the position of the sun
  • float iSun intensity of the sun
  • float rPlanet radius of the planet in meters
  • float rAtoms radius of the atmosphere in meters
  • vec3 kRlh Rayleigh scattering coefficient
  • vec3 kMie Mie scattering coefficient
  • float shRlh Rayleigh scale height in meters
  • float shMie Mie scale height in meters
  • float g Mie preferred scattering direction

For an Earth-like atmosphere, see the settings in the example above.

Credits