Skip to content

Instantly share code, notes, and snippets.

View erichlof's full-sized avatar

Erich Loftis erichlof

View GitHub Profile
@erichlof
erichlof / Monte_Carlo_Rendering_Fragment.glsl
Created May 14, 2025 18:46
Experimenting with more traditional, unbiased Monte Carlo rendering
precision highp float;
precision highp int;
precision highp sampler2D;
#include <pathtracing_uniforms_and_defines>
uniform int uMaterialType;
uniform vec3 uMaterialColor;
#define N_LIGHTS 3.0
#define N_SPHERES 15
@erichlof
erichlof / Monte_Carlo_Rendering.js
Created May 14, 2025 18:44
Experimenting with more traditional, unbiased Monte Carlo rendering
// scene/demo-specific variables go here
let material_TypeObject, material_ColorObject;
let material_TypeController, material_ColorController;
let changeMaterialType = false;
let changeMaterialColor = false;
let matType = 0;
let matColor;
// called automatically from within initTHREEjs() function (located in InitCommon.js file)
@erichlof
erichlof / Monte_Carlo_Rendering.html
Created May 14, 2025 18:43
Experimenting with more traditional, unbiased Monte Carlo rendering
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js PathTracing Renderer - Monte Carlo Rendering</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<link href="css/default.css" rel="stylesheet">
<script type="importmap">
{
@erichlof
erichlof / CSG_Model_Rendering_Fragment.glsl
Created May 14, 2025 18:40
Making more interesting and complex models using CSG techniques
precision highp float;
precision highp int;
precision highp sampler2D;
#include <pathtracing_uniforms_and_defines>
uniform sampler2D tShape_DataTexture;
uniform sampler2D tAABB_DataTexture;
uniform vec3 uOutlineColor;
uniform float uOutlineIntensity;
@erichlof
erichlof / CSG_Model_Rendering.js
Created May 14, 2025 18:38
Making more interesting and complex models using CSG techniques
// scene/demo-specific variables go here
let boxGeometry, boxMaterial;
let boxMeshes = [];
let boxGeometries = [];
let totalNumberOfShapes = 0;
let shape = new THREE.Object3D();
let invMatrix = new THREE.Matrix4();
let el; // elements of the invMatrix
let shapeBoundingBox_minCorner = new THREE.Vector3();
@erichlof
erichlof / CSG_Model_Rendering.html
Created May 14, 2025 18:37
Making more interesting and complex models using CSG techniques
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js PathTracing Renderer - CSG Model Rendering</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<link href="css/default.css" rel="stylesheet">
<script type="importmap">
@erichlof
erichlof / BVH_Point_Light_Source_Fragment.glsl
Created February 20, 2025 21:22
shader (glsl) file for experimental sphere BVH (as opposed to typical AABB BVH)
precision highp float;
precision highp int;
precision highp sampler2D;
#include <pathtracing_uniforms_and_defines>
uniform sampler2D tTriangleTexture;
uniform sampler2D tAABBTexture;
uniform sampler2D tAlbedoTextures[8]; // 8 = max number of diffuse albedo textures per model
@erichlof
erichlof / BVH_Point_Light_Source.js
Created February 20, 2025 21:20
js file for experimental sphere BVH (as opposed to typical AABB BVH)
// scene/demo-specific variables go here
let modelMesh;
let modelScale = 1.0;
let modelPositionOffset = new THREE.Vector3();
let albedoTexture;
let total_number_of_triangles = 0;
let triangle_array;
let triangleMaterialMarkers = [];
let pathTracingMaterialList = [];
let uniqueMaterialTextures = [];
@erichlof
erichlof / BVH_Quick_Builder.js
Last active May 7, 2025 18:15
BVH_Quick_Builder.js
let buildnodes = [];
let leftWorklist = [];
let rightWorklist = [];
let nodesUsed = 1;
let aabb_array_copy;
let k, value, side0, side1, side2;
let bestSplit, goodSplit, okaySplit;
let bestAxis, goodAxis, okayAxis;
let currentMinCorner = new THREE.Vector3();
let currentMaxCorner = new THREE.Vector3();
@erichlof
erichlof / Ocean_And_Sky_Rendering.js
Created August 7, 2023 05:38
Static scene for Ocean and Sky Rendering demo (time is frozen)
// scene/demo-specific variables go here
let sunAngle = 0;
let sunDirection = new THREE.Vector3();
let tallBoxGeometry, tallBoxMaterial, tallBoxMesh;
let shortBoxGeometry, shortBoxMaterial, shortBoxMesh;
let PerlinNoiseTexture;
// called automatically from within initTHREEjs() function (located in InitCommon.js file)
function initSceneData()
{