Renders sky colors with Rayleigh and Mie scattering.

Overview

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

Issues
  • solve for both intersections

    solve for both intersections

    This patch updates the rsi function to solve for both roots of the quadratic and to solve for both the atmospheric and planetary intersection. The previous implementation assumes that the ray always starts inside the sphere, but under this implementation that is no longer necessary. which means you can calculate atmospheric scattering for distant planets: https://substack.neocities.org/earth/atmo.html

    I tested that the existing demo still works under this change. It looks different with more light on the bottom half, but still looks great. If you merge this I would bump the major version since this change will impact how existing demos look.

    opened by substack 2
  • Handle more intersection test cases

    Handle more intersection test cases

    The previous code did not account for many of them, leading to weird artifacts.

    It is debatable whether the "ray is starting inside the planet" case should maybe be ignored. May be useful in some approximation scenarios.

    opened by horazont 0
Owner
Rye Terrell
I don't find anything as satisfying as making tools that people like to use.
Rye Terrell
List of Persian Colors and hex colors for CSS, SCSS, PHP, JS, Python, and Ruby.

Persian Colors (Iranian colors) List of Persian Colors and hex colors for CSS, SCSS, PHP, C++, QML, JS, Python, Ruby and CSharp. Persian colors Name H

Max Base 12 Feb 22, 2022
A test using a TTGO module (ESP32 + screen) which renders a 3d scene using pingo library

A simple 3D renderer tested and developed for the TTGO T-Display ESP32 board. The 3d renderer is: https://github.com/fededevi/pingo The 3D renderer is

fedevi 8 Apr 28, 2022
AviSynth plugin that renders image-based subtitles.

Description Renders image-based subtitles such as VOBSUB and PGS. It returns a list of two clips. The first one is an RGB24 clip containing the render

null 4 Feb 19, 2022
Simple c++ library for work with console colors.

LCCS - Linux Console Control Sequences Simple c++ library for work with console colors. Example program color::SetColor(1,color::BLUE); cout << "ABOBA

Artem Vanty 1 Dec 23, 2021
A plugin editor for endless sky.

Editor This is a proof of concept plugin editor for Endless Sky. It uses Dear ImGui to render the UI on top of the game and as such it is technically

null 6 Mar 10, 2022
null 235 Jun 22, 2022
PikaScript is an ultra-lightweight Python engine with zero dependencies and zero-configuration, that can run with 4KB of RAM (such as STM32G030C8 and STM32F103C8), and is very easy to deploy and expand.

PikaScript 中文页| Star please~ 1. Abstract PikaScript is an ultra-lightweight Python engine with zero dependencies and zero-configuration, that can run

Lyon 786 Jun 27, 2022
Signed - a 3D modeling and construction language based on Lua and SDFs. Signed will be available for macOS and iOS and is heavily optimized for Metal.

Signed - A 3D modeling language Abstract Signed is a Lua based 3D modeling language, it provides a unique way to create high quality 3D content for yo

Markus Moenig 88 May 26, 2022
ESP32 firmware to read and control EMS and Heatronic compatible equipment such as boilers, thermostats, solar modules, and heat pumps

EMS-ESP is an open-source firmware for the Espressif ESP8266 and ESP32 microcontroller that communicates with EMS (Energy Management System) based equipment from manufacturers like Bosch, Buderus, Nefit, Junkers, Worcester and Sieger.

EMS-ESP 153 Jun 28, 2022
Hobbyist Operating System targeting x86_64 systems. Includes userspace, Virtual File System, An InitFS (tarfs), Lua port, easy porting, a decent LibC and LibM, and a shell that supports: piping, file redirection, and more.

SynnixOS Epic Hobby OS targeting x86_64 CPUs, it includes some hacked together functionality for most essential OSs although, with interactivity via Q

RaidTheWeb 40 May 27, 2022
🎮 Plants vs. Zombies multiplayer battle, developed via reverse engineering, inline hook and dynamic-link library injection. Two online players defend and attack as the plant side and zombie side respectively.

Plants vs. Zombies Online Battle This project has two original repositories: https://github.com/czs108/Plants-vs.-Zombies-Online-Battle https://github

Liugw 71 Oct 14, 2021
Free,Open-Source,Cross-platform agent and Post-exploiton tool written in Golang and C++, the architecture and usage like Cobalt Strike

Khepri Free,Open-Source,Cross-platform agent and Post-exploiton tool written in Golang and C++ Description Khepri is a Cross-platform agent, the archi

Young 1.3k Jun 24, 2022
PLP Project Programming Language | Programming for projects and computer science and research on computer and programming.

PLPv2b PLP Project Programming Language Programming Language for projects and computer science and research on computer and programming. What is PLP L

PLP Language 5 Jun 23, 2022
A run-time C++ library for working with units of measurement and conversions between them and with string representations of units and measurements

Units What's new Some of the CMake target names have changed in the latest release, please update builds appropriately Documentation A library that pr

Lawrence Livermore National Laboratory 103 Jun 24, 2022
Second life for famous JPEGView - fast and tiny viewer/editor for JPEG, BMP, PNG, WEBP, TGA, GIF and TIFF images with a minimalist GUI and base image processing.

JPEGView-Image-Viewer-and-Editor Updated Dec 07 2021. Version 1.1.1.0 has been released. Download link1, link2 added. Second life for famous JPEGView

Ann Hatt 20 Jun 9, 2022
An easy to build CO2 Monitor/Meter with Android and iOS App for real time visualization and charting of air data, data logger, a variety of communication options (BLE, WIFI, MQTT, ESP-Now) and many supported sensors.

CO2-Gadget An easy to build CO2 Monitor/Meter with cell phone App for real time visualization and charting of air data, datalogger, a variety of commu

Mariete 19 Jun 23, 2022
Allows to swap the Fn key and left Control key and other tweaks on Macbook Pro and Apple keyboards in GNU/Linux

A patched hid-apple kernel module UPDATE August 2020: swap_fn_leftctrl is now built-in in Linux 5.8 ?? UPDATE Jun 2020: New feature added (swap_fn_f13

Zakhar Semenov 295 Jun 23, 2022
Command line C++ and Python VSTi Host library with MFCC, FFT, RMS and audio extraction and .wav writing.

______ _ ___ ___ | ___ \ | | | \/ | | |_/ /___ _ __ __| | ___ _ __| . . | __ _ _ __

Leon Fedden 280 Jun 28, 2022
Classified is an easy and handy encryptor and and decryptor which is can protect your file.

CLASSIFIED Classified is an encrypted and a decrypter. It can encrypt anykind of file with any extension. It is very secure. The thing only matters is

Shreejan Dolai 3 Feb 13, 2022