-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmesh_test.m
More file actions
36 lines (34 loc) · 902 Bytes
/
mesh_test.m
File metadata and controls
36 lines (34 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
%% setup
clc
xres = 25;
yres = 25;
nbrSamples = 10;
pathDepth = 6;
pathTracer = PathTracer(xres, yres, 'Spheres', nbrSamples, pathDepth);
output = zeros(xres,yres,3, 'single');
%% run
tic;
dim = [xres, yres];
tempColor = zeros(dim(1), dim(2), 3, 'single');
for sample = 1:nbrSamples
for x = 1:dim(1)
for y = 1:dim(2)
d = (([x,y]-1 + rand(1,2))./dim)*2 - 1;
aspectRatio = dim(1)/dim(2);
ray.direction = [d(1)*aspectRatio, -d(2), -1];
ray.direction = ray.direction / norm(ray.direction);
ray.origin = [0,0,0];
color = pathTracer.samplePath(ray, pathDepth);
tempColor(y,x,:) = squeeze(tempColor(y,x,:))' + color;
end
end
% output current state of image
image(tempColor ./ sample);
title(sample)
pause(0.01);
end
output = tempColor ./ nbrSamples;
toc;
%%
image(output);
axis equal