qvolray
changeset 21:4c62be57fc1a
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 11 Apr 2012 16:59:45 +0300 |
parents | 784d3d321caa 68c6eb619d1c |
children | 2d0dfb5751dc |
files | sdr/demo.p.glsl sdr/demo.v.glsl sdr/slice.p.glsl sdr/volray.p.glsl src/demo.cc src/ui.cc src/ui.h src/volray.cc src/volray.h |
diffstat | 9 files changed, 77 insertions(+), 14 deletions(-) [+] |
line diff
1.1 --- a/sdr/demo.p.glsl Wed Apr 11 06:44:06 2012 +0300 1.2 +++ b/sdr/demo.p.glsl Wed Apr 11 16:59:45 2012 +0300 1.3 @@ -1,10 +1,9 @@ 1.4 void main() 1.5 { 1.6 - float val = 0.7; 1.7 - float len = length(gl_FragCoord.xyz); 1.8 - /*if(len < 0.5) { 1.9 - val = 0.7; 1.10 - }*/ 1.11 + vec3 pos = gl_TexCoord[0].xyz * 2.0 - 1.0; 1.12 1.13 - gl_FragColor = vec4(gl_FragCoord.xyz / len, val); 1.14 + float len = length(pos); 1.15 + float val = 0.2 / (len * len); 1.16 + 1.17 + gl_FragColor = vec4(-pos / len, val); 1.18 }
2.1 --- a/sdr/demo.v.glsl Wed Apr 11 06:44:06 2012 +0300 2.2 +++ b/sdr/demo.v.glsl Wed Apr 11 16:59:45 2012 +0300 2.3 @@ -1,4 +1,5 @@ 2.4 void main() 2.5 { 2.6 gl_Position = gl_Vertex; 2.7 + gl_TexCoord[0] = gl_MultiTexCoord0; 2.8 }
3.1 --- a/sdr/slice.p.glsl Wed Apr 11 06:44:06 2012 +0300 3.2 +++ b/sdr/slice.p.glsl Wed Apr 11 16:59:45 2012 +0300 3.3 @@ -3,6 +3,6 @@ 3.4 3.5 void main() 3.6 { 3.7 - float val = texture3D(volume, gl_TexCoord[0].xyz).a; 3.8 + float val = texture3D(volume, gl_TexCoord[0].xyz).w; 3.9 gl_FragColor = vec4(texture1D(xfer_tex, val).xxx, 1.0); 3.10 }
4.1 --- a/sdr/volray.p.glsl Wed Apr 11 06:44:06 2012 +0300 4.2 +++ b/sdr/volray.p.glsl Wed Apr 11 16:59:45 2012 +0300 4.3 @@ -40,15 +40,19 @@ 4.4 gl_FragColor = vec4(color, 1.0); 4.5 } 4.6 4.7 -float eval(vec3 pos) 4.8 +float eval(vec3 pos, out vec3 grad) 4.9 { 4.10 vec3 tc = pos * 0.5 + 0.5; 4.11 4.12 if(tc.x < 0.0 || tc.y < 0.0 || tc.z < zclip || tc.x > 1.0 || tc.y > 1.0 || tc.z > 1.0) { 4.13 + grad = vec3(0.0, 0.0, 0.0); 4.14 return 0.0; 4.15 } 4.16 4.17 - return texture1D(xfer_tex, texture3D(volume, tc).a).x; 4.18 + vec4 texel = texture3D(volume, tc); 4.19 + grad = texel.xyz; 4.20 + 4.21 + return texture1D(xfer_tex, texel.a).x; 4.22 } 4.23 4.24 #define OFFS 0.01 4.25 @@ -63,12 +67,8 @@ 4.26 vec3 pos = ray.origin + ray.dir * t; 4.27 t += ray_step; 4.28 4.29 - float val = eval(pos); 4.30 vec3 norm; 4.31 - 4.32 - norm.x = eval(pos + vec3(OFFS, 0.0, 0.0)) - val; 4.33 - norm.y = eval(pos + vec3(0.0, OFFS, 0.0)) - val; 4.34 - norm.z = eval(pos + vec3(0.0, 0.0, OFFS)) - val; 4.35 + float val = eval(pos, norm); 4.36 4.37 col += shade(ray, pos, normalize(norm)) * val * energy; 4.38 energy -= val;
5.1 --- a/src/demo.cc Wed Apr 11 06:44:06 2012 +0300 5.2 +++ b/src/demo.cc Wed Apr 11 16:59:45 2012 +0300 5.3 @@ -41,6 +41,9 @@ 5.4 return; 5.5 } 5.6 5.7 + glPushAttrib(GL_VIEWPORT_BIT); 5.8 + glViewport(0, 0, SZ, SZ); 5.9 + 5.10 glBindFramebuffer(GL_FRAMEBUFFER, fbo); 5.11 bind_program(sdr_mballs); 5.12 5.13 @@ -48,14 +51,22 @@ 5.14 glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_3D, 5.15 vol->get_texture(), 0, i); 5.16 5.17 + float z = (float)i / (float)SZ; 5.18 + 5.19 glBegin(GL_QUADS); 5.20 + glTexCoord3f(0, 0, z); 5.21 glVertex2f(-1, -1); 5.22 + glTexCoord3f(1, 0, z); 5.23 glVertex2f(1, -1); 5.24 + glTexCoord3f(1, 1, z); 5.25 glVertex2f(1, 1); 5.26 + glTexCoord3f(0, 1, z); 5.27 glVertex2f(-1, 1); 5.28 glEnd(); 5.29 } 5.30 5.31 bind_program(0); 5.32 glBindFramebuffer(GL_FRAMEBUFFER, 0); 5.33 + 5.34 + glPopAttrib(); 5.35 }
6.1 --- a/src/ui.cc Wed Apr 11 06:44:06 2012 +0300 6.2 +++ b/src/ui.cc Wed Apr 11 16:59:45 2012 +0300 6.3 @@ -62,6 +62,22 @@ 6.4 6.5 SideWindow::SideWindow() 6.6 { 6.7 + QSlider *zslider = new QSlider(Qt::Horizontal); 6.8 + zslider->setRange(0, 256); 6.9 + zslider->setValue(volray_getvalue(VOLRAY_ZCURSOR) * 256.0); 6.10 + connect(zslider, SIGNAL(valueChanged(int)), this, SLOT(zslider_change(int))); 6.11 + 6.12 + QVBoxLayout *vbox = new QVBoxLayout; 6.13 + vbox->addWidget(zslider); 6.14 + 6.15 + QWidget *win = new QWidget; 6.16 + setWidget(win); 6.17 + win->setLayout(vbox); 6.18 +} 6.19 + 6.20 +void SideWindow::zslider_change(int val) 6.21 +{ 6.22 + volray_setvalue(VOLRAY_ZCURSOR, (float)val / 256.0); 6.23 } 6.24 6.25
7.1 --- a/src/ui.h Wed Apr 11 06:44:06 2012 +0300 7.2 +++ b/src/ui.h Wed Apr 11 16:59:45 2012 +0300 7.3 @@ -23,6 +23,9 @@ 7.4 7.5 class SideWindow : public QDockWidget { 7.6 Q_OBJECT 7.7 +private slots: 7.8 + void zslider_change(int val); 7.9 + 7.10 public: 7.11 SideWindow(); 7.12 };
8.1 --- a/src/volray.cc Wed Apr 11 06:44:06 2012 +0300 8.2 +++ b/src/volray.cc Wed Apr 11 16:59:45 2012 +0300 8.3 @@ -87,6 +87,32 @@ 8.4 return volume; 8.5 } 8.6 8.7 +void volray_setvalue(int which, float val) 8.8 +{ 8.9 + switch(which) { 8.10 + case VOLRAY_ZCURSOR: 8.11 + cur_z = val; 8.12 + set_uniform_float(vol_sdr, "zclip", cur_z); 8.13 + post_redisplay(); 8.14 + break; 8.15 + 8.16 + default: 8.17 + break; 8.18 + } 8.19 +} 8.20 + 8.21 +float volray_getvalue(int which) 8.22 +{ 8.23 + switch(which) { 8.24 + case VOLRAY_ZCURSOR: 8.25 + return cur_z; 8.26 + 8.27 + default: 8.28 + break; 8.29 + } 8.30 + return 0.0; 8.31 +} 8.32 + 8.33 void volray_draw(void) 8.34 { 8.35 /* recalculate primary ray texture if needed */
9.1 --- a/src/volray.h Wed Apr 11 06:44:06 2012 +0300 9.2 +++ b/src/volray.h Wed Apr 11 16:59:45 2012 +0300 9.3 @@ -8,6 +8,13 @@ 9.4 void volray_setvolume(Volume *vol); 9.5 Volume *volray_getvolume(); 9.6 9.7 +enum { 9.8 + VOLRAY_ZCURSOR 9.9 +}; 9.10 + 9.11 +void volray_setvalue(int which, float val); 9.12 +float volray_getvalue(int which); 9.13 + 9.14 void volray_resize(int xsz, int ysz); 9.15 void volray_draw(); 9.16