Giter Site home page Giter Site logo

glsl-path-tracer's Introduction

GLSL-path-tracer

A simple glsl path tracer with a kd-tree BVH whose only primitives are.. capsules

How to use

Inside libs/createMeshes.js you can code the scene you want to render, guess what, only capsules are supported, here's an example on how to create a scene:

function createMeshes(objects) {
    for(let j = 0; j < 450; j++) {

        let lx1 = Utils.rand() * 5 - 5 * 0.5; 
        let ly1 = Utils.rand() * 5 - 5 * 0.5;
        let lz1 = 10 + (Utils.rand() * 2.0 - 1.0) * 1.0;

        let r = 0.05;
        let z = Utils.rand() * 8;
        
        let lx2 = lx1 + (Utils.rand() * 2 - 1) * 0.5;
        let ly2 = ly1 + (Utils.rand() * 2 - 1) * 0.5;
        let lz2 = lz1 + z;

        let object  = new Line(
            new THREE.Vector3(lx1, ly1, lz1), 
            new THREE.Vector3(lx2, ly2, lz2), 
            r);
        
        let res = Utils.hslToRgb(Utils.rand() * 1 + 0, 1, 0.7);
        // sets the color of each object
        object.setColor(1,1,1);        

        if(Utils.rand() > 0.9) {
            // if this object is a light source,
            // using setEmissive will set the rgb color (range [0...infinity])
            // of the light emitted by this object 
            object.setEmissive(100, 100, 50);        
        }

        if(Utils.rand() > 0.65) {
            let grayValue = Math.pow(Math.random(), 1.0);
            object.setColor(0.15 * 2, 0.4 * 2, 1 * 2);        
        }

        objects.push(object);
    }
}

You can change various parameters of the renderer by modifying the values in libs/globals.js

var exposure = 30.5;  
// lower this value if you get low fps, and the path tracer will render smaller tiles at each frame
var tileSize = 2000;

var canvasWidth = 1200;
var canvasHeight = 800;

// increase this value if you get an error saying you fed too many objects to the renderer
// though I would argue your GPU will be exploded much sooner than you reach the point
// were this number is too small
var dataTextureSize = 2048;

var bokehStrength = 0.4;
// distance of the focal plane used to calculate the blur
var focalDistance = 9.5;

glsl-path-tracer's People

Contributors

domenicobrz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.