@@ -14,75 +14,27 @@ Camera::Camera(Vector3 location, Vector3 direction, unsigned int width, unsigned
14
14
this ->direction = direction;
15
15
}
16
16
17
- void Camera::volumeRenderFrame (std::vector<DebugObject> particles, int frameID) {
18
-
19
- Frame frame = Frame (this ->width , this ->height , frameID);
20
- const double aspectRatio = (double )width / (double )height;
21
- // view plane parameters
22
- const double l = -1 .f *aspectRatio; // left
23
- const double r = +1 .f *aspectRatio; // right
24
- const double b = -1 .f ; // bottom
25
- const double t = +1 .f ; // top
26
- const double d = +2 .f ; // distance to camera
27
-
28
- // ////////////
29
- // TODO: 2.1.1
30
- // Cast a ray from 'cameraPos' through the center(!) of each pixel on the view plane.
31
- // Use the view plane parametrization given above (l, r, b, t and d).
32
- // cf. lecture slides 39-43
33
-
34
- // Calculate these vectors
35
- Vector3 vec_u = normalizeVector (findSkalarVectorWithYZero (this ->direction ));
36
- Vector3 vec_v = normalizeVector (findUpVector (this ->direction , vec_u));
37
-
38
- for (int x = 0 ; x < this ->width ; x++) {
39
- for (int y = 0 ; y < this ->height ; y++) {
40
- double u = l + (r - l) * (x + 0 .5f ) / this ->width ;
41
- double v = t + (b - t) * (y + 0 .5f ) / this ->height ;
42
-
43
- Vector3 vec_s = Vector3 (vec_u.x * u + vec_v.x * v + this ->direction .x * d,
44
- vec_u.y * u + vec_v.y * v + this ->direction .y * d,
45
- vec_u.z * u + vec_v.z * v + this ->direction .z * d);
46
-
47
- Ray ray = Ray (vec_s, this ->location );
48
-
49
-
50
- frame.setPixel (x, y, castVolumeRay (ray, particles));
51
- }
52
- }
53
-
54
- this ->outputDebugFrame (frame, ((" volume_output_cam_" + std::to_string (this ->ID )) + " .bmp" ).c_str ());
55
- }
56
-
57
17
void Camera::debugRenderFrame (std::vector<DebugObject> particles, int frameID) {
58
18
59
19
Frame frame = Frame (this ->width , this ->height , frameID);
60
20
const double aspectRatio = (double )width / (double )height;
61
21
// view plane parameters
62
22
const double l = -1 .f *aspectRatio; // left
63
23
const double r = +1 .f *aspectRatio; // right
64
- const double b = -1 .f ; // bottom
65
- const double t = +1 .f ; // top
66
- const double d = +2 .f ; // distance to camera
24
+ const double b = -1 .f ; // bottom
25
+ const double t = +1 .f ; // top
26
+ const double d = +2 .f ; // distance to camera
67
27
68
- // ////////////
69
- // TODO: 2.1.1
70
- // Cast a ray from 'cameraPos' through the center(!) of each pixel on the view plane.
71
- // Use the view plane parametrization given above (l, r, b, t and d).
72
- // cf. lecture slides 39-43
73
28
74
- // Calculate these vectors
75
- Vector3 vec_u = normalizeVector (findSkalarVectorWithYZero (this ->direction ));
76
- Vector3 vec_v = normalizeVector (findUpVector (this ->direction , vec_u));
29
+ Vector3 vec_u = findSkalarVectorWithYZero (this ->direction ).normalize ();
30
+ Vector3 vec_v = findUpVector (this ->direction , vec_u).normalize ();
77
31
78
32
for (int x = 0 ; x < this ->width ; x++) {
79
33
for (int y = 0 ; y < this ->height ; y++) {
80
34
double u = l + (r - l) * (x + 0 .5f ) / this ->width ;
81
35
double v = t + (b - t) * (y + 0 .5f ) / this ->height ;
82
36
83
- Vector3 vec_s = Vector3 (vec_u.x * u + vec_v.x * v + this ->direction .x * d,
84
- vec_u.y * u + vec_v.y * v + this ->direction .y * d,
85
- vec_u.z * u + vec_v.z * v + this ->direction .z * d);
37
+ Vector3 vec_s = vec_u * u + vec_v * v + this ->direction * d;
86
38
87
39
Ray ray = Ray (vec_s.normalize (), this ->location );
88
40
@@ -113,20 +65,20 @@ Pixel Camera::castDebugRay(Ray ray, std::vector<DebugObject> particles) {
113
65
}
114
66
}
115
67
116
- return hit == nullptr ? Pixel (0 , 0 , 0 ) : hitObject. getColor ( );
68
+ return hit == nullptr ? Pixel (0 , 0 , 0 ) : Pixel ( 0 , 255 , 0 );
117
69
}
118
70
119
- Pixel Camera::castVolumeRay (Ray ray, std::vector<DebugObject > particles) {
71
+ Pixel Camera::castVolumeRay (Ray ray, std::vector<ParticleObject > particles) {
120
72
double bestDistance = std::numeric_limits<float >::max ();
121
73
double waterDepth = 0 ;
122
- DebugObject hitObject;
123
- DebugObject *hit = &hitObject;
74
+ ParticleObject hitObject;
75
+ ParticleObject *hit = &hitObject;
124
76
hit = nullptr ;
125
77
126
- Pixel initColor = Pixel (255 ,255 ,255 ); // Make the background brown
78
+ Pixel initColor = Pixel (255 ,255 ,255 ); // Make the background white
127
79
128
80
for (int i = 0 ; i < particles.size (); i++) {
129
- DebugObject &obj = particles.at (i);
81
+ ParticleObject &obj = particles.at (i);
130
82
double currDist = bestDistance;
131
83
132
84
if (obj.intersects (ray, currDist, waterDepth)) {
@@ -138,24 +90,47 @@ Pixel Camera::castVolumeRay(Ray ray, std::vector<DebugObject> particles) {
138
90
}
139
91
140
92
if (hit != nullptr ) {
141
- double facRG = 1 - 0.8 *exp (-0 .3f * waterDepth);
93
+ double facRG = 1 - 0.8 *exp (-0 .15f * waterDepth);
142
94
double facB = 1 - 1.2 *exp (-0 .1f * waterDepth);
143
95
facB = facB < 0 ? 0 : facB;
144
96
initColor.setRed (initColor.getRedValue () - 255 * facRG);
145
97
initColor.setGreen (initColor.getGreenValue () - 255 * facRG);
146
98
initColor.setBlue (initColor.getBlueValue () - 220 * facB > 30 ? initColor.getBlueValue () - 220 * facB : 30 );
99
+ initColor.setShaderUsage (true );
147
100
}
148
101
149
102
150
103
return initColor;
151
104
}
152
105
153
- void Camera::renderFrame (std::vector<SphParticle> particles) {
154
- // TODO: implement rendering algorithm
155
- }
106
+ Frame Camera::renderFrame (std::vector<ParticleObject> particles, int frameID) {
107
+ Frame frame = Frame (this ->width , this ->height , frameID);
108
+ const double aspectRatio = (double )width / (double )height;
109
+ // view plane parameters
110
+ const double l = -1 .f *aspectRatio; // left
111
+ const double r = +1 .f *aspectRatio; // right
112
+ const double b = -1 .f ; // bottom
113
+ const double t = +1 .f ; // top
114
+ const double d = +2 .f ; // distance to camera
115
+
116
+
117
+ Vector3 vec_u = findSkalarVectorWithYZero (this ->direction ).normalize ();
118
+ Vector3 vec_v = findUpVector (this ->direction , vec_u).normalize ();
119
+
120
+ for (int x = 0 ; x < this ->width ; x++) {
121
+ for (int y = 0 ; y < this ->height ; y++) {
122
+ double u = l + (r - l) * (x + 0 .5f ) / this ->width ;
123
+ double v = t + (b - t) * (y + 0 .5f ) / this ->height ;
124
+
125
+ Vector3 vec_s = vec_u * u + vec_v * v + this ->direction * d;
126
+ Ray ray = Ray (vec_s, this ->location );
127
+
128
+
129
+ frame.setPixel (x, y, castVolumeRay (ray, particles));
130
+ }
131
+ }
156
132
157
- void Camera::mergeFramesAndFlushVideo (std::string file) {
158
- // TODO: merge all Frames to a video
133
+ return frame;
159
134
}
160
135
161
136
void Camera::outputDebugFrame (Frame f, const char * fileName) {
0 commit comments