-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhumanoid-avatar.cpp
More file actions
192 lines (158 loc) · 7.1 KB
/
Copy pathhumanoid-avatar.cpp
File metadata and controls
192 lines (158 loc) · 7.1 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include "ImageRender.h"
#include "ImplicitVolumeShapes.h"
#include "ImageRender.h"
#include "Fields.h"
#include "Camera.h"
#include <iostream>
#include <OpenImageIO/imageio.h>
#include <ctime>
using namespace OIIO;
using namespace lux;
int main(int argc, char *argv[])
{
// ********************** initalize ************************
int fStart = 0;
int fStop = 119;
// ********************** Parse inputs ************************
if (argc > 2) {
fStart = std::stoi(argv[1]);
fStop = std::stoi(argv[2]);
}
// ********************** Defining the shapes *****************
float thickness = 0.1;
// left foot
ScalarField leftFoot1 = Sphere(Vector(-2.2, 6.5, 0.5), 2);
ScalarField leftFoot2 = Sphere(Vector(-2.2, 8.5, 0.5), 2);
ScalarField leftFoot = intersection(leftFoot1, leftFoot2);
leftFoot = clamp(leftFoot / constant(thickness), -1, 1.0);
// right foot
ScalarField rightFoot1 = Sphere(Vector(2.2, 6.5, 0.5), 2);
ScalarField rightFoot2 = Sphere(Vector(2.2, 8.5, 0.5), 2);
ScalarField rightFoot = intersection(rightFoot1, rightFoot2);
rightFoot = clamp(rightFoot / constant(thickness), -1, 1.0);
// left leg
ScalarField leftLeg1 = Ellipse(Vector(-2, 6, 0), Vector(0,1,0), 3.0, 1.0);
ScalarField leftLeg2 = Plane(Vector(0, 4, 0), Vector(0,-1,0));
ScalarField leftLeg = cutout(leftLeg1, leftLeg2);
leftLeg = clamp(leftLeg / constant(thickness), -1, 1.0);
leftLeg = Union(leftFoot, leftLeg);
// right leg
ScalarField rightLeg1 = Ellipse(Vector(2, 6, 0), Vector(0,1,0), 3.0, 1.0);
ScalarField rightLeg2 = Plane(Vector(0, 4, 0), Vector(0,-1,0));
ScalarField rightLeg = cutout(rightLeg1, rightLeg2);
rightLeg = clamp(rightLeg / constant(thickness), -1, 1.0);
rightLeg = Union(rightFoot, rightLeg);
// torso
ScalarField torso = Sphere(Vector(0, 1.5, 0), 3.5);
torso = clamp(torso / constant(thickness), 0, 1.0);
ScalarField fluffPatch = SteinerPatch(Vector(0,-0.5, 4), 1.5);
fluffPatch = add(fluffPatch, fluffPatch);
fluffPatch = scale(fluffPatch, 1.2);
ScalarField tail = Icosahedron(Vector(0, 7.5, -10));
tail = scale(tail, 0.3);
tail = clamp(tail / constant(thickness), -1, 1.0);
fluffPatch = clamp(fluffPatch / constant(thickness), -1, 1.0);
// neck
ScalarField neck = CsgBox(Vector(0, -2.2, 0), 1.2, 2.0);
neck = clamp(neck / constant(thickness), -1, 1.0);
torso = blinnblend(torso, neck, 2, 1.5);
// attach to torso and apply colors
torso = Union(torso, leftLeg);
torso = Union(torso, rightLeg);
ScalarField fluffs = Union(tail, fluffPatch);
torso = Union(torso, fluffs);
// arms
Vector norm = Vector(0,1,0);
norm.normalize();
ScalarField arms = Torus(Vector(0, 0, 1), norm, 1.0, 0.15);
arms = scale(arms, 6);
arms = clamp(arms / constant(thickness), -1, 1.0);
ScalarField armCutout = Plane(Vector(0, 0, 2.5), Vector(0,0,-1));
arms = cutout(arms, armCutout);
// arms = add(arms, arms); // the density was smaller here than everywhere else so doubled it
// hands
ScalarField leftHand = Sphere(Vector(6, 0, 4.5), 1.3);
leftHand = clamp(leftHand / constant(thickness), -1, 1.0);
ScalarField rightHand = Sphere(Vector(-6, 0, 4.5), 1.3);
rightHand = clamp(rightHand / constant(thickness), -1, 1.0);
arms = Union(arms, leftHand);
arms = Union(arms, rightHand);
torso = Union(torso, arms);
// head
ScalarField head = Sphere(Vector(0, -4, 0), 2.3);
ScalarField rightEye = Sphere(Vector(-1, -4.5, 2), 0.5);
ScalarField leftEye = Sphere(Vector(1, -4.5, 2), 0.5);
ScalarField eyes = Union(leftEye, rightEye);
eyes = clamp(eyes / constant(thickness), -1, 1.0);
head = Union(head, eyes);
head = clamp(head / constant(thickness), -1, 1.0);
// nose
ScalarField snout = Cone(Vector(0, -4, 5), Vector(0,0,-1), 3.5, 0.4);
snout = clamp(snout / constant(thickness), -1, 1.0);
ScalarField nose = Sphere(Vector(0, -4, 4.4), 0.7);
nose = clamp(nose / constant(thickness), -1, 1.0);
nose = blinnblend(nose, snout, 4, 10);
head = Union(head, nose);
// Left ear
ScalarField leftEar = Ellipse(Vector(-1.7, -7, 0), Vector(0.5,1,0), 3, 0.8);
leftEar = Shell(leftEar, 0.5);
ScalarField leCutout = Plane(Vector(0, 0, 0.1), Vector(0,0,-1));
leftEar = cutout(leftEar, leCutout);
leftEar = clamp(leftEar / constant(thickness), -1, 1.0);
head = Union(head, leftEar);
// right ear
ScalarField rightEar = Ellipse(Vector(1.7, -7, 0), Vector(-0.5,1,0), 3, 0.8);
rightEar = Shell(rightEar, 0.5);
ScalarField reCutout = Plane(Vector(0, 0, 0.1), Vector(0,0,-1));
rightEar = cutout(rightEar, leCutout);
rightEar = clamp(rightEar / constant(thickness), -1, 1.0);
head = Union(head, rightEar);
// // connect head to the neck
ScalarField Stan = Union(head, torso);
//***************************************************************
// apply color to the body
// Stan = clamp(Stan / constant(thickness), 0.0, 1.0);
ColorField StanColor = constant(Color(0.0, 1.0, 0.0, 0.0)) ; // combined color variable
Color CM = Color(9.5, 6.7, 1.5, 0.0); // current Color variable // purple
double luminance = CM.red() + CM.green() + CM.blue();
ColorField cm = constant(CM / luminance); // current ColorField variable
// ColorField cm = constant(CM);
StanColor = (StanColor * mask(-Stan)) + (cm * mask(Stan));
// // apply color to fluffs
// tail = clamp(tail / constant(thickness), 0.0, 1.0);
CM = Color(95.0, 95.0, 95.0, 0.0); // white
luminance = CM.red() + CM.green() + CM.blue();
cm = constant(CM / luminance);
// cm = constant(CM);
StanColor = (StanColor * mask(-tail)) + (cm * mask(tail));
// fluffPatch = clamp(fluffPatch / constant(thickness), 0.0, 1.0);
CM = Color(1, 1, 1, 0.0); // yellow
luminance = CM.red() + CM.green() + CM.blue();
cm = constant(CM / luminance);
// cm = constant(CM);
StanColor = (StanColor * mask(-fluffPatch)) + (cm * mask(fluffPatch));
// apply color to eyes
// eyes = clamp(eyes / constant(thickness), 0.0, 1.0);
CM = Color(75, 2, 21, 0.0); //red
luminance = CM.red() + CM.green() + CM.blue();
cm = constant(CM / luminance);
// cm = constant(CM);
StanColor = (StanColor * mask(-eyes)) + (cm * mask(eyes));
// *****************************************************************
Stan = clamp(Stan / constant(thickness), 0.0, 1.0);
// ColorField cm = constant(Color(1.0, 0.0, 1.0, 0.0)) * Stan;
// TODOEJP add in the ability to change raymarching settings and pass it to the image render
// create image render object
ImageRender ir(1920, 1080, 4);
ir.reset(1920, 1080, 4);
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,30), Vector(0,0,-1), Vector(0,1,0));
// ir.render("testerimage001.exr", Stan, StanColor, cam);
ir.turntable("stan", Stan, StanColor, cam, fStart, fStop);
return 0;
}