Skip to content

Commit

Permalink
Merge pull request #8 from BLaZeKiLL/wip/tools
Browse files Browse the repository at this point in the history
Tools
  • Loading branch information
BLaZeKiLL authored Feb 7, 2024
2 parents 22d8e24 + 10af7a5 commit 294ffb7
Show file tree
Hide file tree
Showing 21 changed files with 9,196 additions and 10,893 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

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.
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.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Webray is a WebGPU powered ray tracer + Svelte based editor

The editor is available [here](https://blazekill.github.io/webray/) along [Demo Scene 01](https://github.com/BLaZeKiLL/webray/blob/main/src/data/demo_01.scene.json) and [Demo Scene 02](https://github.com/BLaZeKiLL/webray/blob/main/src/data/demo_02.scene.json) which can be imported.

### Tools
### Tools

- <img align="center" src="https://api.iconify.design/iconamoon/3d-light.svg?color=%23888888"> Objects in the current scene
- <img align="center" src="https://api.iconify.design/uil/image-download.svg?color=%23888888"> Download rendered image
- <img align="center" src="https://api.iconify.design/material-symbols/imagesmode-outline-rounded.svg?color=%23888888"> Render the current scene as an image
Expand All @@ -42,4 +43,4 @@ The editor is available [here](https://blazekill.github.io/webray/) along [Demo

<img src="./render.png">

The renderer is implemented in rust and compiled to wasm with the core kernel implemented as a wgsl compute shader using wgpu.
The renderer is implemented in rust and compiled to wasm with the core kernel implemented as a wgsl compute shader using wgpu.
Binary file modified editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
184 changes: 91 additions & 93 deletions scripts/cover.scene.js
Original file line number Diff line number Diff line change
@@ -1,101 +1,97 @@
import fs from 'fs';

function random_color() {
return [
Math.random() * Math.random(),
Math.random() * Math.random(),
Math.random() * Math.random()
];
return [
Math.random() * Math.random(),
Math.random() * Math.random(),
Math.random() * Math.random()
];
}

function random_color_satu() {
return [
(Math.random() / 2) + 0.5,
(Math.random() / 2) + 0.5,
(Math.random() / 2) + 0.5
];
return [Math.random() / 2 + 0.5, Math.random() / 2 + 0.5, Math.random() / 2 + 0.5];
}

function rgbToHex(color) {
return "#" + (1 << 24 | color[0] << 16 | color[1] << 8 | color[2]).toString(16).slice(1);
}
return '#' + ((1 << 24) | (color[0] << 16) | (color[1] << 8) | color[2]).toString(16).slice(1);
}

function make_sphere(name, id, mid, center, radius) {
return {
name: name,
id: id,
material_id: mid,
type: {
type: 'd_sphere',
position: center,
radius: radius
}
};
return {
name: name,
id: id,
material_id: mid,
type: {
type: 'd_sphere',
position: center,
radius: radius
}
};
}

function make_mat_diffuse(name, mid, color) {
return {
name: name,
id: mid,
type: {
type: 'd_mat_diffuse',
color: color
}
};
return {
name: name,
id: mid,
type: {
type: 'd_mat_diffuse',
color: color
}
};
}

function make_mat_metal(name, mid, color, roughness) {
return {
name: name,
id: mid,
type: {
type: 'd_mat_metal',
color: color,
roughness: roughness
}
};
return {
name: name,
id: mid,
type: {
type: 'd_mat_metal',
color: color,
roughness: roughness
}
};
}

function make_mat_dielectric(name, mid, ior) {
return {
name: name,
id: mid,
type: {
type: 'd_mat_dielectric',
ior: ior
}
};
return {
name: name,
id: mid,
type: {
type: 'd_mat_dielectric',
ior: ior
}
};
}

function vec3f_subtract(a, b) {
return [a[0] - b[0], a[1] - b[1], a[2] - b [2]];
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
}

function vec3f_length(a) {
return Math.sqrt((a[0] * a[0]) + (a[1] * a[1]) + (a[2] * a[2]));
return Math.sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
}

const scene = {
objects: [],
materials: [],
camera: {
objects: [],
materials: [],
camera: {
look_from: [13, 2, 3],
look_at: [0, 0, 0],
v_up: [0, 1, 0],
v_fov: 20,
dof_angle: 0.6,
dof_distance: 10
},
render_settings: {
},
render_settings: {
width: 1920,
height: 1080,
samples: 64,
bounces: 12,
tile_size: {
type: 'd_tile_size',
size: 256
size: 256
}
}
}
};

let mat_id = 0;
Expand All @@ -104,37 +100,35 @@ let obj_id = 0;
mat_id++;
obj_id++;

scene.materials.push(make_mat_diffuse(`Mat ${mat_id}`, mat_id, rgbToHex([0.5, 0.5, 0.5].map(x => x * 255))));
scene.materials.push(
make_mat_diffuse(`Mat ${mat_id}`, mat_id, rgbToHex([0.5, 0.5, 0.5].map((x) => x * 255)))
);
scene.objects.push(make_sphere(`Obj ${obj_id}`, obj_id, mat_id, [0, -1000, 0], 1000));

for (let x = -11; x < 11; x++) {
for (let y = -11; y < 11; y++) {
const choose_mat = Math.random();

const position = [
x + (0.9 * Math.random()),
0.2,
y + (0.9 * Math.random())
];

if (vec3f_length(vec3f_subtract(position, [4, 0.2, 0.0])) > 0.9) {
mat_id++;
obj_id++;

if (choose_mat < 0.8) {
const color = rgbToHex(random_color().map(x => x * 255));
scene.materials.push(make_mat_diffuse(`Mat ${mat_id}`, mat_id, color));
scene.objects.push(make_sphere(`Obj ${obj_id}`, obj_id, mat_id, position, 0.2));
} else if (choose_mat < 0.95) {
const color = rgbToHex(random_color_satu().map(x => x * 255));
scene.materials.push(make_mat_metal(`Mat ${mat_id}`, mat_id, color, Math.random() * 0.5));
scene.objects.push(make_sphere(`Obj ${obj_id}`, obj_id, mat_id, position, 0.2));
} else {
scene.materials.push(make_mat_dielectric(`Mat ${mat_id}`, mat_id, 1.5));
scene.objects.push(make_sphere(`Obj ${obj_id}`, obj_id, mat_id, position, 0.2));
}
}
}
for (let y = -11; y < 11; y++) {
const choose_mat = Math.random();

const position = [x + 0.9 * Math.random(), 0.2, y + 0.9 * Math.random()];

if (vec3f_length(vec3f_subtract(position, [4, 0.2, 0.0])) > 0.9) {
mat_id++;
obj_id++;

if (choose_mat < 0.8) {
const color = rgbToHex(random_color().map((x) => x * 255));
scene.materials.push(make_mat_diffuse(`Mat ${mat_id}`, mat_id, color));
scene.objects.push(make_sphere(`Obj ${obj_id}`, obj_id, mat_id, position, 0.2));
} else if (choose_mat < 0.95) {
const color = rgbToHex(random_color_satu().map((x) => x * 255));
scene.materials.push(make_mat_metal(`Mat ${mat_id}`, mat_id, color, Math.random() * 0.5));
scene.objects.push(make_sphere(`Obj ${obj_id}`, obj_id, mat_id, position, 0.2));
} else {
scene.materials.push(make_mat_dielectric(`Mat ${mat_id}`, mat_id, 1.5));
scene.objects.push(make_sphere(`Obj ${obj_id}`, obj_id, mat_id, position, 0.2));
}
}
}
}

mat_id++;
Expand All @@ -146,21 +140,25 @@ scene.objects.push(make_sphere(`Obj ${obj_id}`, obj_id, mat_id, [0, 1, 0], 1.0))
mat_id++;
obj_id++;

scene.materials.push(make_mat_diffuse(`Mat ${mat_id}`, mat_id, rgbToHex([0.4, 0.2, 0.1].map(x => x * 255))));
scene.materials.push(
make_mat_diffuse(`Mat ${mat_id}`, mat_id, rgbToHex([0.4, 0.2, 0.1].map((x) => x * 255)))
);
scene.objects.push(make_sphere(`Obj ${obj_id}`, obj_id, mat_id, [-4, 1, 0], 1.0));

mat_id++;
obj_id++;

scene.materials.push(make_mat_metal(`Mat ${mat_id}`, mat_id, rgbToHex([0.7, 0.6, 0.5].map(x => x * 255)), 0));
scene.materials.push(
make_mat_metal(`Mat ${mat_id}`, mat_id, rgbToHex([0.7, 0.6, 0.5].map((x) => x * 255)), 0)
);
scene.objects.push(make_sphere(`Obj ${obj_id}`, obj_id, mat_id, [4, 1, 0], 1.0));

const path = './src/data/demo_02.scene.json';

fs.writeFile(path, JSON.stringify(scene, null, 4), err => {
if (err) {
console.error('Error writing JSON to file:', err);
} else {
console.log('JSON data has been written to', path);
}
});
fs.writeFile(path, JSON.stringify(scene, null, 4), (err) => {
if (err) {
console.error('Error writing JSON to file:', err);
} else {
console.log('JSON data has been written to', path);
}
});
Loading

0 comments on commit 294ffb7

Please sign in to comment.