GithubHelp home page GithubHelp logo

jbikker / bvh_article Goto Github PK

View Code? Open in Web Editor NEW
314.0 10.0 30.0 17.08 MB

Code accompanying the blog post on bvh construction.

License: The Unlicense

C 62.36% Batchfile 0.02% Objective-C 1.09% C++ 36.53%

bvh_article's Introduction

Code for "How to Build a BVH"

INSTRUCTIONS: Open the "_ bvhdemo.sln" file (all the way at the top!), and make one of the 10 projects the active project.

Note: project files are for Visual Studio 2019; they will convert without issues to 2022 though.

Each project implements one of the 10 articles:

part 1, basics:
https://jacco.ompf2.com/2022/04/13/how-to-build-a-bvh-part-1-basics
...Which explains how to set up a minimal but working BVH in about 300 lines of code.
Project: basics.vcxproj, files: basics.cpp, basics.h

part 2, faster rays:
https://jacco.ompf2.com/2022/04/18/how-to-build-a-bvh-part-2-faster-rays
...in which rays are traced faster, at the expense of BVH build time.
Project: faster.vcxproj, files: faster.cpp, faster.h

part 3, quick builds:
https://jacco.ompf2.com/2022/04/21/how-to-build-a-bvh-part-3-quick-builds
...explains how a high-quality BVH can be constructed rapidly.
Project: quickbuild.vcxproj, files: quickbuild.cpp, quickbuild.h

part 4, animation:
https://jacco.ompf2.com/2022/04/26/how-to-build-a-bvh-part-4-animation
...in which various forms of animation are applied to BVHs.
Project: animation.vcxproj, files: animation.cpp, animation.h

part 5, TLAS & BLAS:
https://jacco.ompf2.com/2022/05/07/how-to-build-a-bvh-part-5-tlas-blas
...describes how a lot of BVHs can be made into one.
Project: toplevel.vcxproj, files: toplevel.cpp, toplevel.h

part 6, TLAS & BLAS part 2:
https://jacco.ompf2.com/2022/05/13/how-to-build-a-bvh-part-6-all-together-now
...which completes the discussion of article 5.
Project: alltogether.vcxproj, files: alltogether.cpp, alltogether.h

part 7, consolidation:
https://jacco.ompf2.com/2022/05/20/how-to-build-a-bvh-part-7-consolidate
...in which the BVH is applied to some nicer renders.
Project: pretty.vcxproj, files: pretty.cpp, pretty.h, bvh.cpp, bvh.h

part 8, whitted:
https://jacco.ompf2.com/2022/05/27/how-to-build-a-bvh-part-8-whitted-style
...completing part 7, with full recursive ray tracing, in real-time.
Project: whitted.vcxproj, files: whitted.cpp, whitted.h, bvh.*

part 9a, GPGPU:
https://jacco.ompf2.com/2022/06/03/how-to-build-a-bvh-part-9a-to-the-gpu
...which is really a GPGPU tutorial, using BVHs as an example.
Project: gpgpu.vcxproj, files: gpgpu.cpp, gpgpu.h, bvh.*

part 9b, 'massive':
https://jacco.ompf2.com/2022/06/15/how-to-build-a-bvh-part-9b-massive
...series finale, with TLAS & BLAS on the GPU. Also: GL/CL interop.
Project: massive.vcxproj, files: massive.cpp, massive.h, raytracer.cl.

NOTE: All projects share the same template files and build directories.
DISCLAIMER: None of this is supposed to be 'production quality'.
LICENSE: This code is covered by the Unlicense. Feel free, no strings.

P.S.: Follow me on Twitter, @j_bikker.

bvh_article's People

Contributors

davidpl1 avatar jbikker 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  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  avatar  avatar  avatar  avatar  avatar  avatar

bvh_article's Issues

ray direction calculation

Hi, I am a little confused about the way to calculate orientation calculation.
in chapter2:
https://github.com/jbikker/bvh_article/blob/89bf112b7ca8c277ac0a311119aa2e29d5ee41f1/faster.cpp#L277C1-L279C57

ray.O = float3( -1.5f, -0.2f, -2.5f );
float3 pixelPos = ray.O + p0 + (p1 - p0) * ((x + u) / (float)SCRWIDTH) + (p2 - p0) * ((y + v) / (float)SCRHEIGHT);
ray.D = normalize( pixelPos - ray.O ), ray.t = 1e30f;

Why need to add ray.O for pixelPos, and minus the ray.O to calculate ray,D. It seems the rays are emitted from (0,0,0), but the ray origin point is still ( -1.5f, -0.2f, -2.5f )

and in chapter1:
In chapter1:
https://github.com/jbikker/bvh_article/blob/89bf112b7ca8c277ac0a311119aa2e29d5ee41f1/basics.cpp#L182C1-L184C41

float3 pixelPos = p0 + (p1 - p0) * (x / (float)SCRWIDTH) + (p2 - p0) * (y / (float)SCRHEIGHT);
ray.D = normalize( pixelPos - ray.O );

there is different calculation for pixelPos (no ray.O added)

missing macros in win_tiny.h

Thanks for your great blog posts, I was just trying to play around with the code a bit this evening.

Immediately had troubles to get this to compile in a fresh installation of VS2022. Namely the DEFINE_ENUM_FLAG_OPERATORS from winnt.h seems missing in the win_tiny.h nowadays. Including the bigger windows.h again and commenting the tiny header works again:

#include "windows.h"
// #include "lib/win_tiny.h" // windows.h replacement for faster builds

#include "lib/win_tiny.h" // windows.h replacement for faster builds

I'm on win11 with a fairly recent sdk version: 10.0.22621.0 that I just downloaded. Thought I'll leave a quick note here before others spend hours on figuring out what was missing.

Cheers,
Thomas

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.