volmetrics
changeset 30:e548d95e0667
fixed lighting, added parameter for volume rotation
author | Eleni Maria Stea <elene.mst@gmail.com> |
---|---|
date | Thu, 01 May 2014 15:28:51 +0300 |
parents | 77cbc31cd31f |
children | cfeecd093730 |
files | data/head.vol data/shaders/vol.f.glsl src/main.cc src/volume.cc src/volume.h |
diffstat | 5 files changed, 26 insertions(+), 27 deletions(-) [+] |
line diff
1.1 --- a/data/head.vol Sun Apr 27 21:07:10 2014 +0300 1.2 +++ b/data/head.vol Thu May 01 15:28:51 2014 +0300 1.3 @@ -1,5 +1,6 @@ 1.4 VOLUME 1.5 zaspect = 1 1.6 +up = z 1.7 1.8 SLICES 1.9
2.1 --- a/data/shaders/vol.f.glsl Sun Apr 27 21:07:10 2014 +0300 2.2 +++ b/data/shaders/vol.f.glsl Thu May 01 15:28:51 2014 +0300 2.3 @@ -20,7 +20,7 @@ 2.4 float dfdy = texture3D(tex, p + vec3(0.0, offs.y, 0.0)).x - texel; 2.5 float dfdz = texture3D(tex, p + vec3(0.0, 0.0, offs.z)).x - texel; 2.6 2.7 - return normalize(vec3(dfdx, dfdy, dfdz)); 2.8 + return -normalize(vec3(dfdx, dfdy, dfdz)); 2.9 } 2.10 2.11 void main() 2.12 @@ -33,7 +33,7 @@ 2.13 float texel = texture3D(tex, pt).x; 2.14 float val = transfer(texel, tmin, tmax); 2.15 2.16 - vec3 normal = calc_normal(pt, texel); 2.17 + vec3 normal = gl_NormalMatrix * calc_normal(pt, texel); 2.18 float ndotl = max(dot(normalize(ldir), normal), 0.0); 2.19 2.20 gl_FragColor = vec4(ndotl, ndotl, ndotl, val);
3.1 --- a/src/main.cc Sun Apr 27 21:07:10 2014 +0300 3.2 +++ b/src/main.cc Thu May 01 15:28:51 2014 +0300 3.3 @@ -26,7 +26,6 @@ 3.4 static void mouse_xfer(int button, int state, int x, int y); 3.5 static void motion_xfer(int x, int y); 3.6 static void volume_preview(); 3.7 -static void draw_slices(); 3.8 static void draw_iso(); 3.9 static void draw_volume(); 3.10 3.11 @@ -94,10 +93,6 @@ 3.12 glEnable(GL_DEPTH_TEST); 3.13 glEnable(GL_NORMALIZE); 3.14 3.15 - glEnable(GL_LIGHTING); 3.16 - glEnable(GL_LIGHT0); 3.17 - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1); 3.18 - 3.19 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 3.20 3.21 //FIXME shaders setup 3.22 @@ -245,13 +240,15 @@ 3.23 glEnd(); 3.24 glDisable(GL_TEXTURE_3D); 3.25 3.26 + glUseProgram(0); 3.27 + 3.28 glLineWidth(3); 3.29 glBegin(GL_LINE_LOOP); 3.30 glColor3f(0.4, 0.8, 0.4); 3.31 - glVertex3f(-1.0, 1.0, 0.0); 3.32 - glVertex3f(-1.0, 0.5, 0.0); 3.33 - glVertex3f(-0.5, 0.5, 0.0); 3.34 - glVertex3f(-0.5, 1.0, 0.0); 3.35 + glVertex3f(0, 1, 0); 3.36 + glVertex3f(0, 0.75, 0); 3.37 + glVertex3f(0.25, 0.75, 0); 3.38 + glVertex3f(0.25, 1, 0); 3.39 glEnd(); 3.40 3.41 glMatrixMode(GL_PROJECTION); 3.42 @@ -260,24 +257,9 @@ 3.43 glMatrixMode(GL_MODELVIEW); 3.44 glPopMatrix(); 3.45 3.46 - glUseProgram(0); 3.47 - 3.48 glEnable(GL_DEPTH_TEST); 3.49 } 3.50 3.51 -static void draw_slices() 3.52 -{ 3.53 - glBindTexture(GL_TEXTURE_3D, vol->get_texture()); 3.54 - glEnable(GL_TEXTURE_3D); 3.55 - glBegin(GL_QUADS); 3.56 - glTexCoord3f(0, 0, cur_z); glVertex3f(-1, -1, 0); 3.57 - glTexCoord3f(0, 1, cur_z); glVertex3f(-1, 1, 0); 3.58 - glTexCoord3f(1, 1, cur_z); glVertex3f(1, 1, 0); 3.59 - glTexCoord3f(1, 0, cur_z); glVertex3f(1, -1, 0); 3.60 - glEnd(); 3.61 - glDisable(GL_TEXTURE_3D); 3.62 -} 3.63 - 3.64 static void draw_iso() 3.65 { 3.66 if(mesh->is_empty()) { 3.67 @@ -304,6 +286,8 @@ 3.68 if(res_loc != -1) 3.69 glUniform3f(res_loc, (float)vol_res[0], (float)vol_res[1], (float)vol_res[2]); 3.70 3.71 + glRotatef(-vol->get_volume_rotation(), 1, 0, 0); 3.72 + 3.73 glDisable(GL_DEPTH_TEST); 3.74 glBindTexture(GL_TEXTURE_3D, vol->get_texture()); 3.75 glEnable(GL_TEXTURE_3D);
4.1 --- a/src/volume.cc Sun Apr 27 21:07:10 2014 +0300 4.2 +++ b/src/volume.cc Thu May 01 15:28:51 2014 +0300 4.3 @@ -21,6 +21,7 @@ 4.4 { 4.5 width = height = 0; 4.6 zaspect = 1; 4.7 + x_rot = 0; 4.8 vol_tex_valid = false; 4.9 4.10 glGenTextures(1, &vol_tex); 4.11 @@ -56,6 +57,8 @@ 4.12 4.13 bool Volume::load(const char *fname) 4.14 { 4.15 + char up = 'y'; 4.16 + 4.17 FILE *fp = fopen(fname, "r"); 4.18 if(!fp) { 4.19 fprintf(stderr, "Failed to open file: %s: %s\n", fname, strerror(errno)); 4.20 @@ -85,6 +88,7 @@ 4.21 reading_slices = true; 4.22 4.23 sscanf(line, "zaspect = %f", &zaspect); 4.24 + sscanf(line, "up = %c", &up); 4.25 } 4.26 else { 4.27 img_fnames.push_back(line); 4.28 @@ -103,6 +107,9 @@ 4.29 } 4.30 } 4.31 4.32 + if (up == 'z') 4.33 + x_rot = 90; 4.34 + 4.35 return true; 4.36 } 4.37 4.38 @@ -166,6 +173,11 @@ 4.39 return vol_tex; 4.40 } 4.41 4.42 +float Volume::get_volume_rotation() const 4.43 +{ 4.44 + return x_rot; 4.45 +} 4.46 + 4.47 static Mesh *cur_mesh; 4.48 static Volume *cur_vol; 4.49 static float low_thres, high_thres; 4.50 @@ -241,7 +253,6 @@ 4.51 4.52 void Volume::draw() const 4.53 { 4.54 - 4.55 } 4.56 4.57 static char *strip_whitespaces(char *buf)
5.1 --- a/src/volume.h Sun Apr 27 21:07:10 2014 +0300 5.2 +++ b/src/volume.h Thu May 01 15:28:51 2014 +0300 5.3 @@ -13,6 +13,7 @@ 5.4 int width; 5.5 int height; 5.6 float zaspect; 5.7 + float x_rot; 5.8 5.9 unsigned int vol_tex; 5.10 mutable bool vol_tex_valid; 5.11 @@ -38,6 +39,8 @@ 5.12 5.13 unsigned int get_texture() const; 5.14 5.15 + float get_volume_rotation() const; 5.16 + 5.17 void create_mesh(Mesh *mesh, float tmin, float tmax, int xres, int yres, int zres); 5.18 5.19 void draw() const;