# HG changeset patch # User John Tsiombikas # Date 1334152785 -10800 # Node ID 4c62be57fc1afc8324c291aca77763de38aae460 # Parent 784d3d321caa62b265ef6721419566d1da0e72d3# Parent 68c6eb619d1ca73d6b748af6e648fc14f085f838 foo diff -r 784d3d321caa -r 4c62be57fc1a sdr/demo.p.glsl --- a/sdr/demo.p.glsl Wed Apr 11 06:44:06 2012 +0300 +++ b/sdr/demo.p.glsl Wed Apr 11 16:59:45 2012 +0300 @@ -1,10 +1,9 @@ void main() { - float val = 0.7; - float len = length(gl_FragCoord.xyz); - /*if(len < 0.5) { - val = 0.7; - }*/ + vec3 pos = gl_TexCoord[0].xyz * 2.0 - 1.0; - gl_FragColor = vec4(gl_FragCoord.xyz / len, val); + float len = length(pos); + float val = 0.2 / (len * len); + + gl_FragColor = vec4(-pos / len, val); } diff -r 784d3d321caa -r 4c62be57fc1a sdr/demo.v.glsl --- a/sdr/demo.v.glsl Wed Apr 11 06:44:06 2012 +0300 +++ b/sdr/demo.v.glsl Wed Apr 11 16:59:45 2012 +0300 @@ -1,4 +1,5 @@ void main() { gl_Position = gl_Vertex; + gl_TexCoord[0] = gl_MultiTexCoord0; } diff -r 784d3d321caa -r 4c62be57fc1a sdr/slice.p.glsl --- a/sdr/slice.p.glsl Wed Apr 11 06:44:06 2012 +0300 +++ b/sdr/slice.p.glsl Wed Apr 11 16:59:45 2012 +0300 @@ -3,6 +3,6 @@ void main() { - float val = texture3D(volume, gl_TexCoord[0].xyz).a; + float val = texture3D(volume, gl_TexCoord[0].xyz).w; gl_FragColor = vec4(texture1D(xfer_tex, val).xxx, 1.0); } diff -r 784d3d321caa -r 4c62be57fc1a sdr/volray.p.glsl --- a/sdr/volray.p.glsl Wed Apr 11 06:44:06 2012 +0300 +++ b/sdr/volray.p.glsl Wed Apr 11 16:59:45 2012 +0300 @@ -40,15 +40,19 @@ gl_FragColor = vec4(color, 1.0); } -float eval(vec3 pos) +float eval(vec3 pos, out vec3 grad) { vec3 tc = pos * 0.5 + 0.5; if(tc.x < 0.0 || tc.y < 0.0 || tc.z < zclip || tc.x > 1.0 || tc.y > 1.0 || tc.z > 1.0) { + grad = vec3(0.0, 0.0, 0.0); return 0.0; } - return texture1D(xfer_tex, texture3D(volume, tc).a).x; + vec4 texel = texture3D(volume, tc); + grad = texel.xyz; + + return texture1D(xfer_tex, texel.a).x; } #define OFFS 0.01 @@ -63,12 +67,8 @@ vec3 pos = ray.origin + ray.dir * t; t += ray_step; - float val = eval(pos); vec3 norm; - - norm.x = eval(pos + vec3(OFFS, 0.0, 0.0)) - val; - norm.y = eval(pos + vec3(0.0, OFFS, 0.0)) - val; - norm.z = eval(pos + vec3(0.0, 0.0, OFFS)) - val; + float val = eval(pos, norm); col += shade(ray, pos, normalize(norm)) * val * energy; energy -= val; diff -r 784d3d321caa -r 4c62be57fc1a src/demo.cc --- a/src/demo.cc Wed Apr 11 06:44:06 2012 +0300 +++ b/src/demo.cc Wed Apr 11 16:59:45 2012 +0300 @@ -41,6 +41,9 @@ return; } + glPushAttrib(GL_VIEWPORT_BIT); + glViewport(0, 0, SZ, SZ); + glBindFramebuffer(GL_FRAMEBUFFER, fbo); bind_program(sdr_mballs); @@ -48,14 +51,22 @@ glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_3D, vol->get_texture(), 0, i); + float z = (float)i / (float)SZ; + glBegin(GL_QUADS); + glTexCoord3f(0, 0, z); glVertex2f(-1, -1); + glTexCoord3f(1, 0, z); glVertex2f(1, -1); + glTexCoord3f(1, 1, z); glVertex2f(1, 1); + glTexCoord3f(0, 1, z); glVertex2f(-1, 1); glEnd(); } bind_program(0); glBindFramebuffer(GL_FRAMEBUFFER, 0); + + glPopAttrib(); } diff -r 784d3d321caa -r 4c62be57fc1a src/ui.cc --- a/src/ui.cc Wed Apr 11 06:44:06 2012 +0300 +++ b/src/ui.cc Wed Apr 11 16:59:45 2012 +0300 @@ -62,6 +62,22 @@ SideWindow::SideWindow() { + QSlider *zslider = new QSlider(Qt::Horizontal); + zslider->setRange(0, 256); + zslider->setValue(volray_getvalue(VOLRAY_ZCURSOR) * 256.0); + connect(zslider, SIGNAL(valueChanged(int)), this, SLOT(zslider_change(int))); + + QVBoxLayout *vbox = new QVBoxLayout; + vbox->addWidget(zslider); + + QWidget *win = new QWidget; + setWidget(win); + win->setLayout(vbox); +} + +void SideWindow::zslider_change(int val) +{ + volray_setvalue(VOLRAY_ZCURSOR, (float)val / 256.0); } diff -r 784d3d321caa -r 4c62be57fc1a src/ui.h --- a/src/ui.h Wed Apr 11 06:44:06 2012 +0300 +++ b/src/ui.h Wed Apr 11 16:59:45 2012 +0300 @@ -23,6 +23,9 @@ class SideWindow : public QDockWidget { Q_OBJECT +private slots: + void zslider_change(int val); + public: SideWindow(); }; diff -r 784d3d321caa -r 4c62be57fc1a src/volray.cc --- a/src/volray.cc Wed Apr 11 06:44:06 2012 +0300 +++ b/src/volray.cc Wed Apr 11 16:59:45 2012 +0300 @@ -87,6 +87,32 @@ return volume; } +void volray_setvalue(int which, float val) +{ + switch(which) { + case VOLRAY_ZCURSOR: + cur_z = val; + set_uniform_float(vol_sdr, "zclip", cur_z); + post_redisplay(); + break; + + default: + break; + } +} + +float volray_getvalue(int which) +{ + switch(which) { + case VOLRAY_ZCURSOR: + return cur_z; + + default: + break; + } + return 0.0; +} + void volray_draw(void) { /* recalculate primary ray texture if needed */ diff -r 784d3d321caa -r 4c62be57fc1a src/volray.h --- a/src/volray.h Wed Apr 11 06:44:06 2012 +0300 +++ b/src/volray.h Wed Apr 11 16:59:45 2012 +0300 @@ -8,6 +8,13 @@ void volray_setvolume(Volume *vol); Volume *volray_getvolume(); +enum { + VOLRAY_ZCURSOR +}; + +void volray_setvalue(int which, float val); +float volray_getvalue(int which); + void volray_resize(int xsz, int ysz); void volray_draw();