Giter Club home page Giter Club logo

glsl-smooth-min's Introduction

glsl-smooth-min

stable

Smooth minimum functions for GLSL, sourced from Iñigo Quílez's article.

Particularly useful when doing Shadertoy-style raymarching with distance fields: you can smoothly blend between two volumes, instead of doing a hard union with min(a, b).

Check it out in action

Usage

NPM

smin(float a, float b, float k)

Blends smoothly between a and b, with a smoothing amount determined by the value of k. For example:

#pragma glslify: smin = require(glsl-smooth-min)

float doModel(vec3 position) {
  // Take two sphere volumes
  float a = length(position + 0.5) - 0.7;
  float b = length(position - 0.5) - 0.7;

  // And smooth them together
  return smin(a, b, 0.8);
}

There are three variants of this function available, all with the same function signature:

#pragma glslify: poly = require(glsl-smooth-min/poly)
#pragma glslify: pow = require(glsl-smooth-min/pow)
#pragma glslify: exp = require(glsl-smooth-min/exp)

// Exports `poly` by default
#pragma glslify: poly = require(glsl-smooth-min)

Each of these variants differ somewhat in their results, and some are more appropriate in specific situations:

These three functions produce smooth results, with different qualities. The three accept a paramter k that controls the radious/distance of the smoothness. From these three, probably the polynomial is the fastest, and also the easiest to control, for k maps directly to a blending band size/distance. Unlike the other two, it probably suffers from second order discontinuities (derivatives), but visually is pleasing enough for most applications.

Contributing

See stackgl/contributing for details.

License

MIT. See LICENSE.md for details.

glsl-smooth-min's People

Contributors

hughsk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.