@@ -84,7 +84,7 @@ Pixel Camera::castDebugRay(Ray& ray, std::vector<DebugObject> particles) {
84
84
85
85
Pixel Camera::castVolumeRay (Ray& ray, std::vector<ParticleObject> particles, Pixel basePixel) {
86
86
double bestDistance = std::numeric_limits<float >::max ();
87
- double waterDepth = 0 ;
87
+ double waterDepth = - 0.2 ;
88
88
ParticleObject hitObject;
89
89
ParticleObject *hit = &hitObject;
90
90
hit = nullptr ;
@@ -105,17 +105,19 @@ Pixel Camera::castVolumeRay(Ray& ray, std::vector<ParticleObject> particles, Pix
105
105
waterDepth = waterDepth > 15 ? 15 : waterDepth; // Cap waterDepth at 15
106
106
107
107
// Copy the pixel from the base Frame
108
- Pixel pixel = Pixel (basePixel.getRedValue (), basePixel.getGreenValue (), basePixel.getRedValue ());
108
+ Pixel pixel = Pixel (basePixel.getRedValue (), basePixel.getGreenValue (), basePixel.getBlueValue ());
109
109
110
110
if (waterDepth <= 0 ) {
111
111
return pixel;
112
112
}
113
113
114
114
Pixel waterColor = Pixel (30 , 30 , 170 ); // Color of "pure water"
115
115
pixel.setShaderUsage (true );
116
+
116
117
// Shade the pixel depending on water depth
117
118
if (hit != nullptr ) {
118
119
// New Shading, should work smiliar to alpha
120
+
119
121
int diffR = waterColor.getRedValue () - pixel.getRedValue ();
120
122
int diffG = waterColor.getGreenValue () - pixel.getGreenValue ();
121
123
int diffB = waterColor.getBlueValue () - pixel.getBlueValue ();
@@ -129,6 +131,7 @@ Pixel Camera::castVolumeRay(Ray& ray, std::vector<ParticleObject> particles, Pix
129
131
pixel.setRed ((unsigned short )newR);
130
132
pixel.setGreen ((unsigned short )newG);
131
133
pixel.setBlue ((unsigned short )newB);
134
+
132
135
}
133
136
134
137
return pixel;
@@ -157,15 +160,14 @@ Frame Camera::renderFrame(std::vector<ParticleObject> particles, int frameID) {
157
160
158
161
// Ray Direction Vector
159
162
Vector3 vec_s = vec_u * u + vec_v * v + this ->direction * d;
160
- Ray ray = Ray (vec_s, this ->location );
163
+ Ray ray = Ray (vec_s. normalize () , this ->location );
161
164
162
165
// Set pixel in Frame
163
- frame.setPixel (x, y, castVolumeRay (ray, particles, getCurrentlyUsedBaseFrame (frameID).getPixel (x, y)));
164
-
166
+ frame.setPixel (x, y, castVolumeRay (ray, particles, getCurrentlyUsedBaseFrame (frameID).getPixel (x, y)));
165
167
}
166
168
}
167
169
168
- return Shader::applyGaussianSmoothing (frame, 5 , 8 );
170
+ return frame; // Shader::applyGaussianSmoothing(frame, 5, 8);
169
171
}
170
172
171
173
void Camera::renderGeometryFrames (Terrain terrain, Terrain gate) {
@@ -188,7 +190,7 @@ void Camera::renderGeometryFrames(Terrain terrain, Terrain gate) {
188
190
double v = t + (b - t) * (y + 0 .5f ) / this ->height ;
189
191
190
192
Vector3 vec_s = vec_u * u + vec_v * v + this ->direction * d;
191
- Ray ray = Ray (vec_s, this ->location );
193
+ Ray ray = Ray (vec_s. normalize () , this ->location );
192
194
193
195
baseFrameOpen.setPixel (x, y, castTerrainRay (ray, terrain));
194
196
}
@@ -202,7 +204,7 @@ void Camera::renderGeometryFrames(Terrain terrain, Terrain gate) {
202
204
double v = t + (b - t) * (y + 0 .5f ) / this ->height ;
203
205
204
206
Vector3 vec_s = vec_u * u + vec_v * v + this ->direction * d;
205
- Ray ray = Ray (vec_s, this ->location );
207
+ Ray ray = Ray (vec_s. normalize () , this ->location );
206
208
207
209
baseFrameClosed.setPixel (x, y, castTerrainGateRay (ray, terrain, gate));
208
210
}
@@ -251,10 +253,11 @@ Pixel Camera::castTerrainRay(Ray& ray, Terrain& terrain) {
251
253
rad = rad > M_PI ? rad - M_PI : rad;
252
254
253
255
// Get a factor between 1 and 0; 90° = 0 ; 0° = 180° = 1
254
- double factor = 1 - ( rad / (M_PI / 2 ));
256
+ double factor = 1 - std::fmax ( std::fmin ( rad / (M_PI / 2 ), 1 ), 0 );
255
257
256
258
// Darken the pixel based on the factor
257
259
Pixel p = Pixel (127 * factor, 67 * factor, 67 * factor);
260
+ p.setBaseDepth (bestDistance);
258
261
259
262
return p;
260
263
}
@@ -268,7 +271,7 @@ Pixel Camera::castTerrainGateRay(Ray& ray, Terrain& terrain, Terrain& gate) {
268
271
269
272
Pixel initColor = Pixel (200 , 200 , 200 ); // Make the background gray
270
273
271
- for (int i = 0 ; i < terrain.getFaceCount () + gate.getFaceCount (); i++) {
274
+ for (int i = 0 ; i <= terrain.getFaceCount () + gate.getFaceCount (); i++) {
272
275
double currDist = bestDistance;
273
276
274
277
if (i >= terrain.getFaceCount ()) {
@@ -293,9 +296,17 @@ Pixel Camera::castTerrainGateRay(Ray& ray, Terrain& terrain, Terrain& gate) {
293
296
294
297
// Calculate Light to not have just brown everywhere
295
298
if (hitIndex >= 0 ) {
299
+ Vector3 planar1;
300
+ Vector3 planar2;
296
301
297
- Vector3 planar1 = terrain.getFace (hitIndex).a - terrain.getFace (hitIndex).b ;
298
- Vector3 planar2 = terrain.getFace (hitIndex).a - terrain.getFace (hitIndex).c ;
302
+ if (hitIndex >= terrain.getFaceCount ()) {
303
+ planar1 = gate.getFace (hitIndex - terrain.getFaceCount ()).a - gate.getFace (hitIndex - terrain.getFaceCount ()).b ;
304
+ planar2 = gate.getFace (hitIndex - terrain.getFaceCount ()).a - gate.getFace (hitIndex - terrain.getFaceCount ()).c ;
305
+ }
306
+ else {
307
+ planar1 = terrain.getFace (hitIndex).a - terrain.getFace (hitIndex).b ;
308
+ planar2 = terrain.getFace (hitIndex).a - terrain.getFace (hitIndex).c ;
309
+ }
299
310
300
311
// Calculate norm vector
301
312
Vector3 n = planar1.cross (planar2).normalize ();
@@ -307,13 +318,14 @@ Pixel Camera::castTerrainGateRay(Ray& ray, Terrain& terrain, Terrain& gate) {
307
318
double rad = acos (n.dot (lightToHit) / (n.length () * lightToHit.length ()));
308
319
309
320
// Check if the angle is more than 180°, if so substract 180°
310
- rad = rad > M_PI ? rad - M_PI : rad;
321
+ rad = rad >= M_PI ? rad - M_PI : rad;
311
322
312
323
// Get a factor between 1 and 0; 90° = 0 ; 0° = 180° = 1
313
- double factor = 1 - ( rad / (M_PI / 2 ));
324
+ double factor = 1 - std::fmax ( std::fmin ( rad / (M_PI / 2 ), 1 ), 0 );
314
325
315
326
// Darken the pixel based on the factor
316
327
Pixel p = Pixel (127 * factor, 67 * factor, 67 * factor);
328
+ p.setBaseDepth (bestDistance);
317
329
318
330
return p;
319
331
}
@@ -336,14 +348,15 @@ void Camera::shareBaseFrame(int rank)
336
348
MPI_Comm_size (MPI_COMM_WORLD, &world_size);
337
349
338
350
for (int i = 1 ; i < world_size; i++) {
339
- Frame::MpiSendFrame (baseFrameOpen, i);
340
- Frame::MpiSendFrame (baseFrameClosed, i);
351
+ Frame::MpiSendFrame (this -> baseFrameOpen , i);
352
+ Frame::MpiSendFrame (this -> baseFrameClosed , i);
341
353
}
342
354
}
343
355
else {
344
356
this ->baseFrameOpen = Frame::MpiReceiveFrame (0 );
345
357
this ->baseFrameClosed = Frame::MpiReceiveFrame (0 );
346
- std::cout << " Base Frames passed to processor" << rank << std::endl;
358
+ cout << this ->baseFrameOpen .getPixel (400 , 300 ).getBaseDepth () << endl;
359
+ std::cout << " Base Frames passed to processor " << rank << std::endl;
347
360
}
348
361
}
349
362
0 commit comments