# HG changeset patch # User John Tsiombikas # Date 1419967257 -7200 # Node ID 931a6b35f1cd5047cdd80b9e5e3470c87f642bc1 # Parent fb6d934713522579df3c2a6f1e25d24e8a274312 added lighting and openmp normal calculation diff -r fb6d93471352 -r 931a6b35f1cd Makefile --- a/Makefile Tue Dec 30 20:03:32 2014 +0200 +++ b/Makefile Tue Dec 30 21:20:57 2014 +0200 @@ -10,9 +10,9 @@ def = -DUSE_GLUT #inc = -CFLAGS = -pedantic -Wall $(opt) $(dbg) $(def) $(inc) +CFLAGS = -pedantic -Wall -fopenmp $(opt) $(dbg) $(def) $(inc) CXXFLAGS = $(CFLAGS) -LDFLAGS = $(libgl) -lm -limago +LDFLAGS = $(libgl) -lm -limago -lgomp ifeq ($(shell uname -s), Darwin) libgl = -framework OpenGL -framework GLUT -lGLEW diff -r fb6d93471352 -r 931a6b35f1cd sdr/fast.p.glsl --- a/sdr/fast.p.glsl Tue Dec 30 20:03:32 2014 +0200 +++ b/sdr/fast.p.glsl Tue Dec 30 21:20:57 2014 +0200 @@ -1,6 +1,21 @@ uniform sampler3D vol_tex; uniform sampler1D xfer_tex; +const vec3 light_dir[3] = { + vec3(0.5, 0.5, 1.0), + vec3(-1.0, 0.2, 0.5), + vec3(-0.2, 0.0, -7.0) +}; +const vec3 light_color[3] = { + vec3(0.9, 0.7, 0.68), + vec3(0.5, 0.6, 0.9), + vec3(0.3, 0.3, 0.3) +}; + +const vec3 ambient = vec3(0.1, 0.1, 0.1); +const vec3 vdir = vec3(0.0, 0.0, 1.0); +const float dimmer = 0.7; + void main() { vec3 tc = gl_TexCoord[0].xyz; @@ -14,6 +29,22 @@ float alpha = color.a * border; if(alpha < 0.001) discard; - gl_FragColor.rgb = voxel.rgb; + vec3 norm = normalize(voxel.rgb * 2.0 - 1.0); + + vec3 diffuse = vec3(0.0, 0.0, 0.0); + vec3 specular = vec3(0.0, 0.0, 0.0); + + for(int i=0; i<3; i++) { + vec3 ldir = normalize(light_dir[i]); + vec3 hdir = normalize(vdir + ldir); + + float ndotl = max(dot(norm, ldir), 0.0); + float ndoth = max(dot(norm, hdir), 0.0); + + diffuse += light_color[i] * color.rgb * ndotl; + specular += light_color[i] * vec3(0.6, 0.6, 0.6) * pow(ndoth, 50.0); + } + + gl_FragColor.rgb = ambient + (diffuse + specular) * dimmer; gl_FragColor.a = alpha; } diff -r fb6d93471352 -r 931a6b35f1cd src/rend_fast.cc --- a/src/rend_fast.cc Tue Dec 30 20:03:32 2014 +0200 +++ b/src/rend_fast.cc Tue Dec 30 21:20:57 2014 +0200 @@ -94,10 +94,12 @@ for(int i=0; i