GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com β€” GitHub - sebastianvasquezechavarria1234/river-flow: πŸŒΏπŸ’§ Real-time procedural landscape with flowing water, rendered in a single β”‚ HTML file using WebGL2 and GLSL raymarching.

BranchesTags
Open more actions menu

Latest commit

 

History

11 Commits
11 Commits

Folders and files

NameName
Last commit message
Last commit date
README.md
README.md
 
 
index.html
index.html
 
 
preview.jpg
preview.jpg
 
 
texture.jpg
texture.jpg
 
 

Repository files navigation

Preview

Where the River Goes

A real-time procedural landscape rendered entirely in a single HTML file.

Originally created by P_Malin on Shadertoy β€” ported to a standalone WebGL2 experience.


Table of Contents

  • About
  • Features
  • Quick Start
  • Project Structure
  • How It Works
  • Controls
  • Technical Details
  • Performance
  • Compatibility
  • Credits
  • License

About

A hacked flow and advection experiment that turned into something beautiful.

This project brings P_Malin's iconic Shadertoy shader to a self-contained HTML file. No build tools. No frameworks. No dependencies. Just open index.html in a browser and watch a river carve through procedural terrain in real time.

The entire scene β€” mountains, riverbed, water surface, foam, reflections, refractions, shadows, and atmospheric fog β€” is generated mathematically, pixel by pixel, every frame.


Features

Feature Description
Raymarched Terrain Procedural heightfield using Fractal Brownian Motion (FBM)
Flowing Water Animated river with realistic flow rates and meandering
Water Foam Dynamic foam generation based on flow velocity and depth
Refraction & Reflection Physically-based water surface with Fresnel equations
Cone Stepping Accelerated raymarching via heightfield cone optimization
Volumetric Fog Exponential distance-based fog with extinction and inscattering
Shadow Mapping Soft sun shadows on both terrain and water surface
Triplanar Texturing Texture projection without UV seams
Auto Camera Smooth camera flythrough following the river path
Mouse Control Click and drag to steer the camera
High DPI Automatic device pixel ratio scaling

Quick Start

  1. Clone or download the repository
  2. Open index.html in any modern browser
  3. Wait for texture.jpg to load
  4. Enjoy the scene

Note: A local server may be required for texture loading in some browsers. You can use:

# Python
python -m http.server 8000

# Node.js
npx serve .

Project Structure

.
β”œβ”€β”€ index.html      # Everything: HTML, JavaScript, and GLSL
β”œβ”€β”€ texture.jpg     # Terrain texture sampled via triplanar mapping
└── preview.jpg     # Screenshot of the rendered scene

Single file. Zero configuration. The fragment shader, vertex shader, WebGL setup, texture loading, and render loop all live inside index.html.


How It Works

Rendering Pipeline

Fragment Coord
      β”‚
      β–Ό
 Camera Ray Generation
      β”‚
      β–Ό
 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚  Raymarch Scene  β”‚ ← Cone stepping acceleration
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
    β”Œβ”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”
    β”‚           β”‚
 Terrain     Sky Color
    β”‚
    β–Ό
 Water Trace ──→ Refraction + Reflection
    β”‚
    β–Ό
 Lighting (Sun + Sky)
    β”‚
    β–Ό
 Fog Composition
    β”‚
    β–Ό
 Vignette + Tonemap
    β”‚
    β–Ό
   Pixel

Terrain Generation

The landscape is a heightmap built from layered FBM noise. Each octave doubles in frequency and halves in amplitude, creating natural-looking erosion patterns. A riverbed is carved by subtracting depth based on a sinusoidal meander function.

Water Surface

The water normal is computed via gradient-domain FBM with flow advection. Two noise samples are blended over time to create the illusion of moving water. Foam appears where flow velocity exceeds a threshold or where depth decreases near obstacles.

Lighting Model

  • Sun light β€” Blinn-Phong specular with Cook-Torrance distribution
  • Sky light β€” Hemisphere ambient proportional to surface normal
  • Fresnel β€” Schlick approximation blending reflection and refraction
  • Shadows β€” Secondary raymarch from water/terrain surface toward the sun

Controls

Input Action
Mouse drag Steer camera heading and distance
Automatic Camera follows the river when idle

Technical Details

Parameter Value
Raymarch steps 64
FBM octaves (terrain) 3
FBM octaves (water) 4
Water refraction index 1 / 1.3333 (real water)
Far clip 20.0 units
Sun direction (-1.0, 0.7, 0.25) normalized

Shader Defines

Define Effect
ENABLE_WATER Renders the water surface
ENABLE_FOAM Adds foam to the water
ENABLE_WATER_RECEIVE_SHADOW Shadows cast onto water
ENABLE_CONE_STEPPING Accelerates terrain raymarching

Performance

The shader is computationally intensive by design. Each pixel requires:

  • Multiple FBM evaluations for terrain height
  • A secondary raymarch for shadows
  • Refraction ray bounce
  • Reflection ray bounce
  • Flow and foam calculations

For smoother performance on lower-end GPUs, consider:

  • Reducing k_raymarchSteps from 64 to 32
  • Disabling ENABLE_WATER_RECEIVE_SHADOW
  • Removing supersampling if enabled

Compatibility

Browser Status
Chrome 80+ βœ… Full support
Firefox 80+ βœ… Full support
Edge 80+ βœ… Full support
Safari 15+ βœ… Full support
Mobile browsers ⚠️ May be slow due to shader complexity

Requirements: WebGL2 (#version 300 ES)


Credits

  • Shader Author: P_Malin β€” original "Where the River Goes" on Shadertoy
  • Hash function: Dave Hoskins β€” Hash without Sine
  • Block render technique: Shadertoy /ltlSWf

License

The original shader is authored by P_Malin and hosted on Shadertoy under their terms of use. This WebGL2 port is provided for educational and personal use.


Every pixel, every frame, computed from pure mathematics.
Made with ❀️ by SebastiÑn V

About

πŸŒΏπŸ’§ Real-time procedural landscape with flowing water, rendered in a single β”‚ HTML file using WebGL2 and GLSL raymarching.

river-flow-lemon.vercel.app/

Topics

creative-codingfragment-shaderglslhtml5landscapeprocedural-generationraymarchingrealtime-graphicsshadershadertoysingle-fileterrainwaterwebglwebgl2

Resources

Readme
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 β€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800Γ—600. No cookies required.