Giter VIP home page Giter VIP logo

sdfu's Introduction

sdfu - Signed Distance Field Utilities

This is a small crate designed to help when working with signed distance fields in the context of computer graphics, especially ray-marching based renderers. Most of what is here is based on Inigo Quilez' excellent articles.

If you're using one of the more popular math libraries in Rust, then just enable the corresponding feature (currently, ultraviolet, nalgebra and vek are supported) and hopefully all the necessary traits are already implemented for you so that you can just start passing in your Vec3s or whatever your lib calls them and you're off to the races! If not, then you can implement the necessary traits in the mathtypes module and still use this library with your own math lib.

Demo

demo image

The image above was rendered with my own path tracing renderer, rayn by leveraging sdfu. The SDF that is rendered above was created with the following code:

use sdfu::SDF;
use ultraviolet::Vec3;

let sdf = sdfu::Sphere::new(0.45)
    .subtract(
        sdfu::Box::new(Vec3::new(0.25, 0.25, 1.5)))
    .union_smooth(
        sdfu::Sphere::new(0.3).translate(Vec3::new(0.3, 0.3, 0.0)),
        0.1)
    .union_smooth(
        sdfu::Sphere::new(0.3).translate(Vec3::new(-0.3, 0.3, 0.0)),
        0.1)
    .subtract(
        sdfu::Box::new(Vec3::new(0.125, 0.125, 1.5)).translate(Vec3::new(-0.3, 0.3, 0.0)))
    .subtract(
        sdfu::Box::new(Vec3::new(0.125, 0.125, 1.5)).translate(Vec3::new(0.3, 0.3, 0.0)))
    .subtract(
        sdfu::Box::new(Vec3::new(1.5, 0.1, 0.1)).translate(Vec3::new(0.0, 0.3, 0.0)))
    .subtract(
        sdfu::Box::new(Vec3::new(0.2, 2.0, 0.2)))
    .translate(Vec3::new(0.0, 0.0, -1.0));

sdfu's People

Contributors

fu5ha avatar w1th0utnam3 avatar simmsb avatar bonsairobo avatar folke avatar rodrimati1992 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.