-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel2.cpp
More file actions
152 lines (104 loc) · 3.9 KB
/
level2.cpp
File metadata and controls
152 lines (104 loc) · 3.9 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
Create a levelset of ajax (smallajax.obj) with key rim and fill lights
*/
#include "ImageRender.h"
#include "ImplicitVolumeShapes.h"
#include "ImageRender.h"
#include "Fields.h"
#include "Camera.h"
#include "RectangularGrid.h"
#include "VolumeGrid.h"
#include "SparseGrid.h"
#include "Grids.h"
#include "ArgumentParser.h"
#include "ObjParser.h"
#include "Levelset.h"
#include <iostream>
#include <OpenImageIO/imageio.h>
#include <ctime>
using namespace OIIO;
using namespace lux;
int main(int argc, char *argv[])
{
// ********************** Parse inputs ************************
ArgumentParser parser(argc, argv);
if (parser.hasFlag("help"))
{
parser.help();
return 0;
}
int fStart = std::stoi(parser.getValue("fstart", "0"));
int fStop = std::stoi(parser.getValue("fstop", "0"));
bool cache = parser.hasFlag("cache");
std::cout << "Settings:\n\tfstart = " << fStart << ",\n\tfstop = " << fStop << ",\n\tcache = " << cache << "\n\n";
// ****************************Main Code*****************************
std::string ObjPath = "/home/eport/Documents/spring25/cpsc8190/physically-based-effects/starter/models/ajax/smallajax.obj";
ScalarGrid level;
level->init(500, 500, 500, 10, 10, 10, Vector(-5, -5, -5));
Levelset mySDF(level, ObjPath, 5, 0.2);
ScalarGrid ajaxLevelset;
// cache the grid if flag is set
if (cache) {
size_t pos = ObjPath.rfind(".obj");
if (pos != std::string::npos) {
ObjPath.erase(pos);
ObjPath += "-levelset.bin";
}
std::ifstream file(ObjPath);
if (file.is_open()) { // check if there is a file that exists to read it in
std::cout << "File exists!\n";
// read in file
ReadVolumeGrid(*ajaxLevelset, file);
} else { // create a new levelset if the file path isn't already there
std::cout << "Levelset does not already exist. Creating a new one...\n";
mySDF.ProcessA();
ajaxLevelset = mySDF.getLevelset();
std::ofstream out(ObjPath);
WriteVolumeGrid(*ajaxLevelset, out);
}
} else { // if cache flag is not set
mySDF.ProcessA();
ajaxLevelset = mySDF.getLevelset();
}
ScalarField ajax = gridded(ajaxLevelset);
Vector rotationAxis(1.0, 0.0, 0.0);
rotationAxis = rotationAxis * M_PI;
ajax = rotate(ajax, rotationAxis);
ajax = translate(ajax, Vector(0, 1.5, 0));
ajax = scale(ajax, 0.5);
// Color ajax
ColorField ajax_color = constant(Color(0.0, 0.0, 0.0, 1.0));
ColorField ajaxColor = constant(Color(1.0, 1.0, 1.0, 1.0));
ajax_color = ajax_color * mask(-ajax) + ajaxColor * mask(ajax);
// clamp ajax
float thickness = 0.05;
ajax = clamp(ajax/constant(thickness),0.0,1.0);
// Initialize raymarcher
RayMarcher rm(25, 10, 0.02, 0.5);
// make key light
ScalarGrid key;
key->init(500, 500, 500, 10, 10, 10, Vector(-5, -5, -5));
rm.AddDSM(Vector(0, -20, 0), Color(1, 0, 0, 1), key, ajax);
// make rim 40%
ScalarGrid rim;
rim->init(500, 500, 500, 10, 10, 10, Vector(-5, -5, -5));
rm.AddDSM(Vector(0, -2, -20), Color(0, 0.4, 0, 1), rim, ajax);
// make fill 20%
ScalarGrid fill;
fill->init(500, 500, 500, 10, 10, 10, Vector(-5, -5, -5));
rm.AddDSM(Vector(0, 20, 5), Color(0, 0, 0.2, 1), fill, ajax);
// create image render object
ImageRender ir(1920, 1080, 4);
ir.reset(1920, 1080, 4);
ir.setRayMarch(rm);
ir.setMarchType(1);
Camera cam = Camera();
// looking down
// cam.setEyeViewUp(Vector(0,30,0), Vector(0,-1,0), Vector(0,0,1));
// Look from the side
// cam.setEyeViewUp(Vector(30,0,0), Vector(-1,0,0), Vector(0,1,0));
// looking at the front
cam.setEyeViewUp(Vector(0, 0, 15), Vector(0, 0, -1), Vector(0, 1, 0));
ir.turntable("ajax", ajax, ajax_color, cam, fStart, fStop);
return 0;
}