# HG changeset patch # User Eleni Maria Stea # Date 1398947331 -10800 # Node ID e548d95e0667c3c6ee90eea9bc3e03de9d99e118 # Parent 77cbc31cd31f5d39d7dba94ebed43c4f827eb01b fixed lighting, added parameter for volume rotation diff -r 77cbc31cd31f -r e548d95e0667 data/head.vol --- a/data/head.vol Sun Apr 27 21:07:10 2014 +0300 +++ b/data/head.vol Thu May 01 15:28:51 2014 +0300 @@ -1,5 +1,6 @@ VOLUME zaspect = 1 +up = z SLICES diff -r 77cbc31cd31f -r e548d95e0667 data/shaders/vol.f.glsl --- a/data/shaders/vol.f.glsl Sun Apr 27 21:07:10 2014 +0300 +++ b/data/shaders/vol.f.glsl Thu May 01 15:28:51 2014 +0300 @@ -20,7 +20,7 @@ float dfdy = texture3D(tex, p + vec3(0.0, offs.y, 0.0)).x - texel; float dfdz = texture3D(tex, p + vec3(0.0, 0.0, offs.z)).x - texel; - return normalize(vec3(dfdx, dfdy, dfdz)); + return -normalize(vec3(dfdx, dfdy, dfdz)); } void main() @@ -33,7 +33,7 @@ float texel = texture3D(tex, pt).x; float val = transfer(texel, tmin, tmax); - vec3 normal = calc_normal(pt, texel); + vec3 normal = gl_NormalMatrix * calc_normal(pt, texel); float ndotl = max(dot(normalize(ldir), normal), 0.0); gl_FragColor = vec4(ndotl, ndotl, ndotl, val); diff -r 77cbc31cd31f -r e548d95e0667 src/main.cc --- a/src/main.cc Sun Apr 27 21:07:10 2014 +0300 +++ b/src/main.cc Thu May 01 15:28:51 2014 +0300 @@ -26,7 +26,6 @@ static void mouse_xfer(int button, int state, int x, int y); static void motion_xfer(int x, int y); static void volume_preview(); -static void draw_slices(); static void draw_iso(); static void draw_volume(); @@ -94,10 +93,6 @@ glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //FIXME shaders setup @@ -245,13 +240,15 @@ glEnd(); glDisable(GL_TEXTURE_3D); + glUseProgram(0); + glLineWidth(3); glBegin(GL_LINE_LOOP); glColor3f(0.4, 0.8, 0.4); - glVertex3f(-1.0, 1.0, 0.0); - glVertex3f(-1.0, 0.5, 0.0); - glVertex3f(-0.5, 0.5, 0.0); - glVertex3f(-0.5, 1.0, 0.0); + glVertex3f(0, 1, 0); + glVertex3f(0, 0.75, 0); + glVertex3f(0.25, 0.75, 0); + glVertex3f(0.25, 1, 0); glEnd(); glMatrixMode(GL_PROJECTION); @@ -260,24 +257,9 @@ glMatrixMode(GL_MODELVIEW); glPopMatrix(); - glUseProgram(0); - glEnable(GL_DEPTH_TEST); } -static void draw_slices() -{ - glBindTexture(GL_TEXTURE_3D, vol->get_texture()); - glEnable(GL_TEXTURE_3D); - glBegin(GL_QUADS); - glTexCoord3f(0, 0, cur_z); glVertex3f(-1, -1, 0); - glTexCoord3f(0, 1, cur_z); glVertex3f(-1, 1, 0); - glTexCoord3f(1, 1, cur_z); glVertex3f(1, 1, 0); - glTexCoord3f(1, 0, cur_z); glVertex3f(1, -1, 0); - glEnd(); - glDisable(GL_TEXTURE_3D); -} - static void draw_iso() { if(mesh->is_empty()) { @@ -304,6 +286,8 @@ if(res_loc != -1) glUniform3f(res_loc, (float)vol_res[0], (float)vol_res[1], (float)vol_res[2]); + glRotatef(-vol->get_volume_rotation(), 1, 0, 0); + glDisable(GL_DEPTH_TEST); glBindTexture(GL_TEXTURE_3D, vol->get_texture()); glEnable(GL_TEXTURE_3D); diff -r 77cbc31cd31f -r e548d95e0667 src/volume.cc --- a/src/volume.cc Sun Apr 27 21:07:10 2014 +0300 +++ b/src/volume.cc Thu May 01 15:28:51 2014 +0300 @@ -21,6 +21,7 @@ { width = height = 0; zaspect = 1; + x_rot = 0; vol_tex_valid = false; glGenTextures(1, &vol_tex); @@ -56,6 +57,8 @@ bool Volume::load(const char *fname) { + char up = 'y'; + FILE *fp = fopen(fname, "r"); if(!fp) { fprintf(stderr, "Failed to open file: %s: %s\n", fname, strerror(errno)); @@ -85,6 +88,7 @@ reading_slices = true; sscanf(line, "zaspect = %f", &zaspect); + sscanf(line, "up = %c", &up); } else { img_fnames.push_back(line); @@ -103,6 +107,9 @@ } } + if (up == 'z') + x_rot = 90; + return true; } @@ -166,6 +173,11 @@ return vol_tex; } +float Volume::get_volume_rotation() const +{ + return x_rot; +} + static Mesh *cur_mesh; static Volume *cur_vol; static float low_thres, high_thres; @@ -241,7 +253,6 @@ void Volume::draw() const { - } static char *strip_whitespaces(char *buf) diff -r 77cbc31cd31f -r e548d95e0667 src/volume.h --- a/src/volume.h Sun Apr 27 21:07:10 2014 +0300 +++ b/src/volume.h Thu May 01 15:28:51 2014 +0300 @@ -13,6 +13,7 @@ int width; int height; float zaspect; + float x_rot; unsigned int vol_tex; mutable bool vol_tex_valid; @@ -38,6 +39,8 @@ unsigned int get_texture() const; + float get_volume_rotation() const; + void create_mesh(Mesh *mesh, float tmin, float tmax, int xres, int yres, int zres); void draw() const;