glviewvol
changeset 9:931a6b35f1cd
added lighting and openmp normal calculation
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 30 Dec 2014 21:20:57 +0200 |
parents | fb6d93471352 |
children | 89efc666105c |
files | Makefile sdr/fast.p.glsl src/rend_fast.cc |
diffstat | 3 files changed, 37 insertions(+), 4 deletions(-) [+] |
line diff
1.1 --- a/Makefile Tue Dec 30 20:03:32 2014 +0200 1.2 +++ b/Makefile Tue Dec 30 21:20:57 2014 +0200 1.3 @@ -10,9 +10,9 @@ 1.4 def = -DUSE_GLUT 1.5 #inc = 1.6 1.7 -CFLAGS = -pedantic -Wall $(opt) $(dbg) $(def) $(inc) 1.8 +CFLAGS = -pedantic -Wall -fopenmp $(opt) $(dbg) $(def) $(inc) 1.9 CXXFLAGS = $(CFLAGS) 1.10 -LDFLAGS = $(libgl) -lm -limago 1.11 +LDFLAGS = $(libgl) -lm -limago -lgomp 1.12 1.13 ifeq ($(shell uname -s), Darwin) 1.14 libgl = -framework OpenGL -framework GLUT -lGLEW
2.1 --- a/sdr/fast.p.glsl Tue Dec 30 20:03:32 2014 +0200 2.2 +++ b/sdr/fast.p.glsl Tue Dec 30 21:20:57 2014 +0200 2.3 @@ -1,6 +1,21 @@ 2.4 uniform sampler3D vol_tex; 2.5 uniform sampler1D xfer_tex; 2.6 2.7 +const vec3 light_dir[3] = { 2.8 + vec3(0.5, 0.5, 1.0), 2.9 + vec3(-1.0, 0.2, 0.5), 2.10 + vec3(-0.2, 0.0, -7.0) 2.11 +}; 2.12 +const vec3 light_color[3] = { 2.13 + vec3(0.9, 0.7, 0.68), 2.14 + vec3(0.5, 0.6, 0.9), 2.15 + vec3(0.3, 0.3, 0.3) 2.16 +}; 2.17 + 2.18 +const vec3 ambient = vec3(0.1, 0.1, 0.1); 2.19 +const vec3 vdir = vec3(0.0, 0.0, 1.0); 2.20 +const float dimmer = 0.7; 2.21 + 2.22 void main() 2.23 { 2.24 vec3 tc = gl_TexCoord[0].xyz; 2.25 @@ -14,6 +29,22 @@ 2.26 float alpha = color.a * border; 2.27 if(alpha < 0.001) discard; 2.28 2.29 - gl_FragColor.rgb = voxel.rgb; 2.30 + vec3 norm = normalize(voxel.rgb * 2.0 - 1.0); 2.31 + 2.32 + vec3 diffuse = vec3(0.0, 0.0, 0.0); 2.33 + vec3 specular = vec3(0.0, 0.0, 0.0); 2.34 + 2.35 + for(int i=0; i<3; i++) { 2.36 + vec3 ldir = normalize(light_dir[i]); 2.37 + vec3 hdir = normalize(vdir + ldir); 2.38 + 2.39 + float ndotl = max(dot(norm, ldir), 0.0); 2.40 + float ndoth = max(dot(norm, hdir), 0.0); 2.41 + 2.42 + diffuse += light_color[i] * color.rgb * ndotl; 2.43 + specular += light_color[i] * vec3(0.6, 0.6, 0.6) * pow(ndoth, 50.0); 2.44 + } 2.45 + 2.46 + gl_FragColor.rgb = ambient + (diffuse + specular) * dimmer; 2.47 gl_FragColor.a = alpha; 2.48 }
3.1 --- a/src/rend_fast.cc Tue Dec 30 20:03:32 2014 +0200 3.2 +++ b/src/rend_fast.cc Tue Dec 30 21:20:57 2014 +0200 3.3 @@ -94,10 +94,12 @@ 3.4 3.5 for(int i=0; i<zsz; i++) { 3.6 float z = (float)i; 3.7 - float *pptr = slice; 3.8 3.9 +#pragma omp parallel for schedule(dynamic) 3.10 for(int j=0; j<ysz; j++) { 3.11 float y = (float)j; 3.12 + 3.13 + float *pptr = slice + (j * xsz) * 4; 3.14 for(int k=0; k<xsz; k++) { 3.15 float x = (float)k; 3.16