Git Product home page Git Product logo

glsl-pathtracer's Introduction

GLSL-PathTracer

A physically based path tracer that runs in a GLSL fragment shader.

Jinx

Tropical Island

Features

  • Unidirectional path tracer
  • Two-level BVH for instancing
  • Disney BSDF
  • Texture mapping (Albedo, Metallic-Roughness, Normal, Emission)
  • Analytic lights (Spherical, Rectangular, Directional)
  • Image based lighting
  • Multiple importance sampling
  • Tile rendering
  • OpenImageDenoise
  • Stochastic alpha testing
  • MagicaVoxel style homogeneous volumes
  • GLTF/GLB support (In progress)

Build Instructions

Please see INSTALL-WIN.txt for the build instructions for Windows and INSTALL-LINUX.txt for Linux

Sample Scenes

A couple of sample scenes are provided in the repository. Additional scenes can be downloaded from here: https://drive.google.com/file/d/1UFMMoVb5uB7WIvCeHOfQ2dCQSxNMXluB/view

Gallery

Monster

WW2

RenderMan Swatch

Dragon

Stormtrooper

Panther

Crown

Mustang

Mustang_Red

Hyperion

Ajax

Dining Room

Rank3PoliceUnit

Staircase

Substance Boy

References/Credits

glsl-pathtracer's People

Contributors

cedricguillemet avatar knightcrawler25 avatar leeteng2001 avatar nolram12345 avatar tuket 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  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

glsl-pathtracer's Issues

Crash when trying to open bedroom scene

PathTracer_d.exe!GLSLPathTracer::RenderOptions::operator=(const GLSLPathTracer::RenderOptions & __that)	C++
PathTracer_d.exe!loadScene(int index) Line 55	C++
PathTracer_d.exe!main() Line 230	C++
[External Code]	

On Windows 10, Debug version.
I think you should put assignment statement after checking.


        scene = LoadScene(std::string("./assets/")+sceneFilenames[index]);
        scene->renderOptions = renderOptions;
	if (!scene)
	{
		std::cout << "Unable to load scene\n";
		exit(0);
	}

Potential transmission issue

Really nice job with the path tracer, the implementation is very clean.

One potential issue I'm not sure about is that in the Disney BSDF paper for the transmission BSDF the half-vector for the refraction case is:

image

they then specify

The BRDF is reciprocal but the BTDF is not, so care must be taken when choosing i and o. In particular, for path tracing from the camera, i would represent the view direction and o the light direction.

It looks like that is currently backwards in your implementation?

I'm also wondering where the 4.0 factor comes from in your bsdf eval for transmission:
bsdf = state.mat.albedo * transmittance * (1.0 - F) * D * G * VDotH * LDotH * 4.0 * state.eta * state.eta / (denomSqrt * denomSqrt);

Missing dll when running PathTracer.exe

First of all, thanks a lot for sharing a release !

I'm missing a Visual C++ Redistributable Package to run your executable. Maybe you could provide details somewhere on what needs to be installed before running your program ?

image

Light Questions

Hi,

I am porting the renderer over to my GPL based SDF modeler / renderer.

I have some questions re data structures for the lights:

For radiusAreaType, x is the radius for sphere lights, z is a switch between sphere and quad lights and Y is the volume of the light source, right ?

Also what would be the best way to support directional (sun) light ? I guess just setting the lightDir variable directly to the direction without any falloff I guess ?

And thanks for the easy to understand source code.

Error on Intel Iris Plus Graphics

On the latest graphics driver version for Intel Iris Plus Graphics (27.20.100.9168) there is an error when running Version 0.2.1.

C:\Users\jacob\Downloads\Path Trace>PathTracer.exe
Loading Scene..
Model ./assets/cornell_box/cbox_ceiling.obj loaded
Model ./assets/cornell_box/cbox_floor.obj loaded
Model ./assets/cornell_box/cbox_back.obj loaded
Model ./assets/cornell_box/cbox_smallbox.obj loaded
Model ./assets/cornell_box/cbox_largebox.obj loaded
Model ./assets/cornell_box/cbox_greenwall.obj loaded
Model ./assets/cornell_box/cbox_redwall.obj loaded
Building BVH for ./assets/cornell_box/cbox_ceiling.obj
Building BVH for ./assets/cornell_box/cbox_floor.obj
Building BVH for ./assets/cornell_box/cbox_back.obj
Building BVH for ./assets/cornell_box/cbox_smallbox.obj
Building BVH for ./assets/cornell_box/cbox_largebox.obj
Building BVH for ./assets/cornell_box/cbox_greenwall.obj
Building BVH for ./assets/cornell_box/cbox_redwall.obj
Building scene BVH
Compiling Shader ./shaders/common/vertex.glsl -> 1
Compiling Shader ./shaders/tiled.glsl -> 2
Shader compilation error ./shaders/tiled.glsl
ERROR: 0:86: 'samplerBuffer' : reserved word
ERROR: 0:86: 'samplerBuffer' : syntax error syntax error



C:\Users\jacob\Downloads\Path Trace>

Issue with large scale models

Hello,
I have a problem that seems to be related to the measure unit adopted. I would like to use obj models in scale 1.0 unit = 1mm.
img_184
This is a screenshot of the teapot.scene where the object is scaled up to be 100 times bigger.
I previously tried a version of this path tracer in October 2020 and I didn't experienced this issue.

Thanks and congrats for your great job.

Sampling the sun

Is there some example code or a fork which shows how to sample sun light for a given sun light direction ?

Thanks

Normal map in tangent space

The way you calculting tangent and bitangent in the function 0nb() looks very simple. But is it right?

void Onb(in vec3 N, inout vec3 T, inout vec3 B)
//-----------------------------------------------------------------------
{
    vec3 UpVector = abs(N.z) < 0.99999 ? vec3(0, 0, 1) : vec3(1, 0, 0);
    T = normalize(cross(UpVector, N));
    B = cross(N, T);
}

I think it will not produce right results, it may flip coordinates of normal map. Shouldn't we precompute tangent and bitangent based on triangle's edges and UV coordinates as something like dP/dUV?

Why dot and specular parameter is removed?

Hello.
Why in bsdfSampleRec.f * abs(dot(state.ffnormal, bsdfSampleRec.L)) / bsdfSampleRec.pdf; and same in other places in code
abs(dot(state.ffnormal, bsdfSampleRec.L)) is removed?
Why specular parameter is removed?

materials pathtrace shader issue

Hi,
I have a some suggestions about materials values in pathtrace shader.

I think that gamma correction should be used also if plain color is selected:

if (int(mat.texIDs.x) >= 0)
mat.albedo *= pow(texture(textureMapsArrayTex, vec3(texUV, int(mat.texIDs.x))).xyz, vec3(2.2));

else
mat.albedo = pow(mat.albedo, vec3(2.2));

Rigth now, the color selected from picker looks quite different from result.
The same also applies for metallic-roughness values.
Moreover, roughness value may be 0 if it comes from a texture and this may cause problems with transmission.

// Metallic Roughness Map
if (int(mat.texIDs.y) >= 0)
{
vec2 matRgh;
matRgh = pow(texture(textureMapsArrayTex, vec3(texUV, int(mat.texIDs.y))).zy, vec2(2.2));
mat.metallic = matRgh.x;
mat.roughness = matRgh.y;
}

I believe that it is better to apply the 0.001 minimum value also here, like this:

if (int(mat.texIDs.y) >= 0) {
vec2 matRgh;
matRgh = pow(texture(textureMapsArrayTex, vec3(texUV, int(mat.texIDs.y))).zy, vec2(2.2));
mat.metallic = matRgh.x;
mat.roughness = max(matRgh.y, 0.001);
}
else {
mat.metallic = pow(mat.metallic, 2.2);
mat.roughness = max(pow(mat.roughness, 2.2), 0.001);
}

Last thing, if I'm not mistaken, here should be used the real face normal:

Onb(state.ffnormal, T, B);

Onb(state.normal, T, B);

Hope this can be helpful.
Thanks for the great work!

Feature wanted

New feature request :)
I don't know if it fits your roadmap but I'd like to see displacement texture in the material. I'm working a lot with heightmap/displacement map and I'd like to plug the renderer over that. Thanks !

Planned things on my fork

Here is a small list of things I'd like to do/like to see in the coming weeks/months (no particular order):
provide API for rendering progress feedback
dearimgui UI : load scene, change rendering mode, dump infos

use cmake and move files (3rd party libs are not properly placed)

  • provide memory allocator
  • use assimp instead of tinyobj loader. .obj loading is inefficient and corrupts github merge info (got 1.8M+line change in my PR)

Scene loading failed on window

I'm trying load scene CoffeeCart.scene. Paths like ./assets/bathroom/floor.obj can't be loaded on window VS 2019. Assert genarated

Feature Request

I know the benefit of path tracing is that it enables dynamic, photorealistic lighting but would it (theoretically) be possible to bake the path traced lighting into a scene or asset?

Feel free to just close the issue if this is a stupid question; I'm new to graphics and such.

scene file light format

How do you define quad lights in .scene file? There is position, v1, v2 parameters.
Is 'position' a coordinates of the center of light? What are 'v1' and 'v2' vectors?
UPDATE
I think position, v1, v2 are just coordinates of the first three vertices of area light, right?

Anisotropy Bug

Circular halo on the anisotropic highlight. Mesh uvs are not used for the shading tangents so the mesh topology might not be the cause

anisotropy

Expected result (Cycles):

cycles

Improving Build intructions

hey I'm kind of stupid and I keep on getting stuck on the part where you open the sln because there isn't one so if you could add screenshots to the build instructions that'd be great
image

Too slow ?

Hi,
I'm not sure, maybe this is normal ? But the window freeze and this is really slow.
This is really difficult to use gizmo for displace object or modifying value on the GUI.
Maybe there is some update problem ?
My graphics card is an rtx 2080s.
Thanks.

Fix quarter rendering window issue in MacOS

The actual resolution of window is different if you have retina display (like MacOS), thus we need to query from SDL once more after we have created the window to get the actual drawable size. Thus will fix the black range in the rendering window

    auto window_flags = (SDL_WindowFlags) (SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE |
                                                      SDL_WINDOW_ALLOW_HIGHDPI);
    loopdata.mWindow = SDL_CreateWindow("GLSL Raytracing", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                        renderOptions.windowResolution.x, renderOptions.windowResolution.y,
                                        window_flags);
    
    // Query actual drawable window size
    int w, h;
    SDL_GL_GetDrawableSize(loopdata.mWindow, &w, &h);
    renderOptions.windowResolution.x = w;
    renderOptions.windowResolution.y = h;

Before:
Screenshot 2022-12-14 at 10 38 20 AM

After:
Screenshot 2022-12-14 at 10 38 43 AM

Check if inside Object

Hi, I am writing an SDF modeler and for the ray marching to be correct I need to know if the path tracer state is currently inside or outside an object.

Would that be somehow evident from the State struct ?

Thanks

compilation error (linking stage) on Linux, "cannot find -lOpenImageDenoise"

hi

I have compiled successfuly up to 100% but I get a linker error:

...
[ 96%] Building CXX object CMakeFiles/PathTracer.dir/thirdparty/imguizmo/ImGuizmo.cpp.o
[100%] Linking CXX executable PathTracer
/usr/bin/ld: cannot find -lOpenImageDenoise
collect2: error: ld returned 1 exit status

I see OpenImageDenoise.lib under GLSL-PathTracer/thirdparty/oidn/lib, is it not the library the linker needs?

I am on Ubuntu 18.04, cmake 3.18.

Do you have any idea?
thanks

edit: I realise there are only .dll or .lib files for the oidn thirdparty folder, no .so neither .a file. After googling a bit, it seems it is an Intel library. on there website they say "You need a CPU with SSE4.1 support or Apple Silicon to run Intel Open Image Denoise"
Now, I am running on a Jetson machine, Linux for tegra, i.e. ARM cpu, so I cannot use this lib anyway.
If so, then can I compile without image denoising? if yes, how can I do it?

Missing Assets

Hi, I was looking through your scenes and they reference some missing files, was this done on purpose because they are closed source or just an oversight?

The scenes are beautiful and I would love to test them in my raytracer.

Lack of test files

Please when you implement new features, add test files for checking it

Raymarcher: Glass and shadow rays

Hi,

I am working on an programmatic SDF modeler / ray marcher and I wonder how to handle light sources behind glass. Right now the shadow rays hit the glass and just produce a shadow.

What is the correct way, when hitting glass, skipping through the glass (i.e. ignoring it) for shadow rays or something more complex, i.e. refracting the shadow rays ?

Thanks!

Screen Shot 2021-09-21 at 09 03 14

?

Tone mapping ruins the constant background color

Hi, thanks for the great project!

In the shader code in tonemap.glsl, tonemap is applied to all pixels, which is not correct if a constant background color is desired. See the effects below:

Without tone mapping:
Screen Shot 2021-12-29 at 12 20 30

With tone mapping:
Screen Shot 2021-12-29 at 12 21 39

I think whether it is background can be recorded as the w component in pathTraceTexture. Maybe there are other better ideas?

New features

What I plan to do:

  • thin abstraction/API for mesh injection
  • gltf loader as an example
  • shader code reduction (regroup most things inside a common shader and #include)
  • loading dialog for native/web
  • multithreaded bvh computation
  • scene tweaking (move/orient/scale objects)
  • material tweaking
  • replace SOIL with something up to date

What I'd like to have:

  • displacement
  • hability to change an object matrix, recompute scene bvh without updating object bvh
  • Pixel information feedback, render to a buffer : materialid,objectid
  • remove glm. Only a few things are used. Maybe replace it with just a header with the needed functions/structures

To experiment:

  • denoiser using bilateral (need normal buffer)
  • reprojection of previous frame

Crash with Normal Texture

I am trying to imporve woo rendering with normal map texture to see wood grain but I have an issue (image) when loading this asset.zip :

To see the crash you need to modify ST-CL3-009-00.scene
// without crash
line 47 : normalTexture ST-CL3-009-00\images\wood_normal_grey**.xxx.**png
// with crash
line 47 : normalTexture ST-CL3-009-00\images\wood_normal_grey.png

Is there any known limitation regarding texture size, or POT/NPOT, or format (png vs jpeg) ?

image

assets.zip

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.