Skip to content

Commit c40c3d9

Browse files
committed
Fixed flickering with frustrum culling at very small field of view
1 parent 38f99f4 commit c40c3d9

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/graphics.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class Camera {
302302
}
303303
}
304304
void input_X() {
305-
fov = fmax(fov-1.0f, 1.0f);
305+
fov = fmax(fov-1.0f, 1E-6f);
306306
dis = 0.5f*(float)width/tan(fov*pif/360.0f);
307307
}
308308
void input_Y() {

src/kernel.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,11 @@ string opencl_c_container() { return R( // ########################## begin of O
823823
const float x_right = !vr ? (float)( (int)def_screen_width/2-1) : ((float)( (int)def_screen_width/2-1)-(float)(def_screen_width/4u))*rtv;
824824
const float y_top = (float)(-(int)def_screen_height/2 );
825825
const float y_bottom = (float)((int)def_screen_height/2-1);
826-
float3 r00 = p0+normalize((float3)(x_left , y_top , -dis)); // get 4 edge vectors of frustrum, get_camray(...) inlined and redundant parts eliminated
827-
float3 r01 = p0+normalize((float3)(x_right, y_top , -dis));
828-
float3 r10 = p0+normalize((float3)(x_left , y_bottom, -dis));
829-
float3 r11 = p0+normalize((float3)(x_right, y_bottom, -dis));
826+
const float dis_clamped = fmin(dis, 1E4f); // avoid flickering at very small field of view
827+
float3 r00 = p0+normalize((float3)(x_left , y_top , -dis_clamped)); // get 4 edge vectors of frustrum, get_camray(...) inlined and redundant parts eliminated
828+
float3 r01 = p0+normalize((float3)(x_right, y_top , -dis_clamped));
829+
float3 r10 = p0+normalize((float3)(x_left , y_bottom, -dis_clamped));
830+
float3 r11 = p0+normalize((float3)(x_right, y_bottom, -dis_clamped));
830831
r00 = Rx*r00.x+Ry*r00.y+Rz*r00.z+pos-camera_center; // reverse rotation and reverse transformation of r00
831832
r01 = Rx*r01.x+Ry*r01.y+Rz*r01.z+pos-camera_center; // reverse rotation and reverse transformation of r01
832833
r10 = Rx*r10.x+Ry*r10.y+Rz*r10.z+pos-camera_center; // reverse rotation and reverse transformation of r10

src/setup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ void main_setup() { // benchmark; required extensions in defines.hpp: BENCHMARK,
717717
if(x==0u||x==Nx-1u||y==0u||y==Ny-1u||z==Nz-1u) lbm.flags[n] = TYPE_E;
718718
}); // ####################################################################### run simulation, export images and data ##########################################################################
719719
lbm.graphics.visualization_modes = VIS_FLAG_SURFACE|VIS_Q_CRITERION;
720-
lbm.graphics.set_camera_centered(20.0f, 30.0f, 1.0f, 1.648722f);
720+
lbm.graphics.set_camera_centered(20.0f, 30.0f, 0.0f, 1.648722f);
721721
lbm.run(0u); // initialize simulation
722722
#if defined(FP16S)
723723
const string path = get_exe_path()+"FP16S/"+to_string(memory)+"MB/";

0 commit comments

Comments
 (0)