Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SreeXD committed Apr 5, 2024
0 parents commit aa422d9
Show file tree
Hide file tree
Showing 38 changed files with 10,774 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tabWidth": 4
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Nagendran N

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
88 changes: 88 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Three-PT

---

(This is WIP and not even close to completion)

WebGPU Path Tracer for Three.js

### Features (as of now)

- Uses Three.js constructs for meshes, materials etc
- Dedicated renderer for path tracing using WebGPU compute shaders
- Accelerated path tracing using linear BVH built entirely on the GPU
- Physically based rendering using microfacet BRDF
- Importance sampling

### To Do

- A Lot :l

### Usage

```js
const renderer = new PTRenderer({
canvas,
numBounces: 3,
});
renderer.setSize(innerWidth, innerHeight);

const camera = new THREE.PerspectiveCamera(45, innerWidth / innerHeight);
camera.position.set(0, 2, 5);
camera.lookAt(0, 0, 0);

const scene = new THREE.Scene();
scene.add(
new THREE.Mesh(
new THREE.SphereGeometry(1, 64, 32),
new THREE.MeshStandardMaterial({
color: "#bcbaff",
roughness: 0.99,
metalness: 0.01,
}),
),
);

scene.add(
new THREE.Mesh(
new THREE.SphereGeometry(2).translate(0, 5.5, 0),
new THREE.MeshStandardMaterial({
color: "white",
emissive: "white",
emissiveIntensity: 4,
}),
),
);

scene.add(
new THREE.Mesh(
new THREE.PlaneGeometry(100, 100)
.rotateX(-Math.PI / 2.0)
.translate(0, -1, 0),
new THREE.MeshStandardMaterial({
color: "white",
roughness: 0.8,
metalness: 0.2,
}),
),
);

await renderer.initialize();

const onFrame = () => {
renderer.render(scene, camera);
requestAnimationFrame(onFrame);
};

requestAnimationFrame(onFrame);
```

![code snippet result](https://i.imgur.com/SKoRC9u.png)

this is how the BVH looks for the above scene
![bvh](https://i.imgur.com/HZqhD8b.png)

### Renders

![render 1](https://i.imgur.com/be5sHDE.png)
![render 2](https://imgur.com/dWL0qQa.png)
18 changes: 18 additions & 0 deletions examples/three-pt-showcase/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parser: "@typescript-eslint/parser",
plugins: ["react-refresh"],
rules: {
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
},
};
24 changes: 24 additions & 0 deletions examples/three-pt-showcase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
3 changes: 3 additions & 0 deletions examples/three-pt-showcase/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tabWidth": 4
}
30 changes: 30 additions & 0 deletions examples/three-pt-showcase/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
project: ["./tsconfig.json", "./tsconfig.node.json"],
tsconfigRootDir: __dirname,
},
};
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
12 changes: 12 additions & 0 deletions examples/three-pt-showcase/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Three PT Showcase</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading

0 comments on commit aa422d9

Please # to comment.