Subversion Repositories gelsvn

Rev

Rev 643 | Rev 657 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 643 Rev 647
Line 9... Line 9...
9
#include <GLUT/GLUT.h>
9
#include <GLUT/GLUT.h>
10
 
10
 
11
#include <algorithm>
11
#include <algorithm>
12
#include <string>
12
#include <string>
13
#include <cstdlib>
13
#include <cstdlib>
-
 
14
#include "../Geometry/TriMesh.h"
14
#include "../CGLA/Mat3x3d.h"
15
#include "../CGLA/Mat3x3d.h"
15
#include "../GLGraphics/glsl_shader.h"
16
#include "../GLGraphics/glsl_shader.h"
-
 
17
#include "../GLGraphics/draw.h"
16
#include "../HMesh/Manifold.h"
18
#include "../HMesh/Manifold.h"
17
#include "../HMesh/AttributeVector.h"
19
#include "../HMesh/AttributeVector.h"
18
#include "../HMesh/curvature.h"
20
#include "../HMesh/curvature.h"
19
 
21
 
20
using namespace CGLA;
22
using namespace CGLA;
21
using namespace HMesh;
23
using namespace HMesh;
22
using namespace std;
24
using namespace std;
23
 
-
 
-
 
25
using namespace Geometry;
24
namespace GLGraphics
26
namespace GLGraphics
25
{
27
{
-
 
28
    void draw_ball() {
-
 
29
        static TriMesh mesh;
-
 
30
        if(mesh.geometry.no_vertices()==0)
-
 
31
        {
-
 
32
            GLfloat sphere_verts[] = {0.91358,0,0,-0.91358,0,0,0,0.91358,0,0,-0.91358,0,0,0,0.91358,0,0,-0.91358,0.54321,-0.54321,0.54321,0.54321,0.54321,-0.54321,-0.54321,0.54321,0.54321,-0.54321,-0.54321,-0.54321,0.54321,0.54321,0.54321,-0.54321,0.54321,-0.54321,-0.54321,-0.54321,0.54321,0.54321,-0.54321,-0.54321,0.444444,0,0.814815,0,-0.814815,0.444444,0.814815,-0.444444,0,0.444444,0,-0.814815,0,0.814815,-0.444444,0.814815,0.444444,0,-0.444444,0,0.814815,0,0.814815,0.444444,-0.814815,0.444444,0,-0.444444,0,-0.814815,0,-0.814815,-0.444444,-0.814815,-0.444444,0,0,0.444444,0.814815,0.814815,0,0.444444,0.444444,0.814815,0,0,0.444444,-0.814815,-0.814815,0,-0.444444,-0.444444,0.814815,0,0,-0.444444,0.814815,-0.814815,0,0.444444,-0.444444,-0.814815,0,0,-0.444444,-0.814815,0.814815,0,-0.444444,0.444444,-0.814815,0};
-
 
33
            GLuint sphere_indices[] = {28,11,15,27,5,15,33,7,15,33,13,16,35,4,16,38,7,16,38,14,17,37,1,17,28,7,17,37,14,18,36,6,18,30,8,18,30,12,19,32,3,19,29,8,19,29,11,20,28,1,20,37,8,20,34,13,21,33,5,21,27,9,21,27,11,22,29,3,22,32,9,22,32,12,23,31,2,23,34,9,23,31,12,24,30,6,24,36,10,24,36,14,25,38,4,25,35,10,25,35,13,26,34,2,26,31,10,26,22,9,27,21,5,27,15,11,27,15,7,28,17,1,28,20,11,28,20,8,29,19,3,29,22,11,29,19,8,30,18,6,30,24,12,30,24,10,31,26,2,31,23,12,31,23,9,32,22,3,32,19,12,32,16,7,33,15,5,33,21,13,33,21,9,34,23,2,34,26,13,34,26,10,35,25,4,35,16,13,35,25,10,36,24,6,36,18,14,36,18,8,37,20,1,37,17,14,37,17,7,38,16,4,38,25,14,38};
-
 
34
            
-
 
35
            for(int i=0;i<38;++i) {
-
 
36
                int idx0 = 3*i;
-
 
37
                mesh.geometry.add_vertex(Vec3f(sphere_verts[idx0],sphere_verts[idx0+1],sphere_verts[idx0+2]));
-
 
38
            }
-
 
39
            for(int i=0;i<72;++i) {
-
 
40
                int idx0 = 3*i;
-
 
41
                mesh.geometry.add_face(Vec3i(sphere_indices[idx0]-1,sphere_indices[idx0+1]-1,sphere_indices[idx0+2]-1));
-
 
42
            }
-
 
43
            mesh.compute_normals();
-
 
44
        }
-
 
45
        draw(mesh);
-
 
46
    }
26
    
47
    
27
    GLuint get_noise_texture_id()
48
    GLuint get_noise_texture_id()
28
    {
49
    {
29
        static GLuint texname=0;
50
        static GLuint texname=0;
30
        static bool was_here = false;
51
        static bool was_here = false;
Line 41... Line 62...
41
                int intensity = 255.0 * (float(gel_rand()) / GEL_RAND_MAX);
62
                int intensity = 255.0 * (float(gel_rand()) / GEL_RAND_MAX);
42
                texels[i] = (unsigned char) intensity;
63
                texels[i] = (unsigned char) intensity;
43
            }
64
            }
44
            
65
            
45
            glGenTextures(1, &texname);	
66
            glGenTextures(1, &texname);	
46
            glBindTexture(GL_TEXTURE_3D, texname);	
67
            glBindTexture(GL_TEXTURE_3D, texname);
47
            glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
68
            glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
48
            glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
69
            glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
49
            glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
70
            glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
50
            glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
71
            glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
51
            glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
72
            glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
Line 196... Line 217...
196
    "	\n"
217
    "	\n"
197
    "	gl_FragColor =  d+s;\n"
218
    "	gl_FragColor =  d+s;\n"
198
    "}\n";
219
    "}\n";
199
    
220
    
200
    HMesh::VertexAttributeVector<CGLA::Vec3f> DebugRenderer::vertex_colors;
221
    HMesh::VertexAttributeVector<CGLA::Vec3f> DebugRenderer::vertex_colors;
-
 
222
    HMesh::HalfEdgeAttributeVector<CGLA::Vec3f> DebugRenderer::edge_colors;
201
    HMesh::FaceAttributeVector<CGLA::Vec3f> DebugRenderer::face_colors;
223
    HMesh::FaceAttributeVector<CGLA::Vec3f> DebugRenderer::face_colors;
202
 
224
 
203
    
225
    
204
    void DebugRenderer::compile_display_list(const HMesh::Manifold& m, bool smooth)
226
    void DebugRenderer::compile_display_list(const HMesh::Manifold& m, bool smooth)
205
    {
227
    {
206
        GLint old_prog;
228
        GLint old_prog;
207
        glGetIntegerv(GL_CURRENT_PROGRAM, &old_prog);
229
        glGetIntegerv(GL_CURRENT_PROGRAM, &old_prog);
208
        glUseProgram(prog);
230
        glUseProgram(prog);
209
        glNewList(display_list,GL_COMPILE);
231
        glNewList(display_list,GL_COMPILE);
-
 
232
        glEnable(GL_POLYGON_OFFSET_FILL);
-
 
233
        glPolygonOffset(1,1);
210
        for(FaceID f: m.faces()){
234
        for(FaceID f: m.faces()){
211
            Vec3f c = face_colors[f];
235
            Vec3f c = face_colors[f];
212
            glColor3f(c[0], c[1], c[2]);
236
            glColor3f(c[0], c[1], c[2]);
213
            if(!smooth)
237
            if(!smooth)
214
                glNormal3dv(normal(m, f).get());
238
                glNormal3dv(normal(m, f).get());
Line 223... Line 247...
223
                    glNormal3dv(n.get());
247
                    glNormal3dv(n.get());
224
                glVertex3dv(m.pos(w.vertex()).get());
248
                glVertex3dv(m.pos(w.vertex()).get());
225
            }
249
            }
226
            glEnd();
250
            glEnd();
227
        }
251
        }
-
 
252
        glLineWidth(2);
-
 
253
        glDisable(GL_POLYGON_OFFSET_FILL);
-
 
254
        glBegin(GL_LINES);
-
 
255
        for(auto hid: m.halfedges())
228
 
256
        {
-
 
257
            Walker w = m.walker(hid);
-
 
258
            Vec3f c = edge_colors[hid];
-
 
259
            glColor3fv(c.get());
-
 
260
            glNormal3dv(normal(m, w.opp().vertex()).get());
-
 
261
            glVertex3dv(m.pos(w.opp().vertex()).get());
-
 
262
            glNormal3dv(normal(m, w.vertex()).get());
-
 
263
            glVertex3dv(m.pos(w.vertex()).get());
-
 
264
        }
-
 
265
        glEnd();
-
 
266
        glLineWidth(1);
229
        Vec3d c;
267
        Vec3d c;
230
        float r;
268
        float r;
231
        bsphere(m, c, r);
269
        bsphere(m, c, r);
-
 
270
        r *= 0.003;
232
        for(auto vid : m.vertices())
271
        for(auto vid : m.vertices())
233
        {
272
        {
234
            Vec3d p = m.pos(vid);
273
            Vec3d p = m.pos(vid);
235
            Vec3f c = vertex_colors[vid];
274
            Vec3f c = vertex_colors[vid];
236
            glColor3f(c[0], c[1], c[2]);
275
            glColor3f(c[0], c[1], c[2]);
237
            glPushMatrix();
276
            glPushMatrix();
238
            glTranslated(p[0], p[1], p[2]);
277
            glTranslated(p[0], p[1], p[2]);
239
            glutSolidSphere(0.01*r, 7, 7);
278
            glScalef(r, r, r);
-
 
279
            draw_ball();
240
            glPopMatrix();
280
            glPopMatrix();
241
        }
281
        }
-
 
282
        glEnd();
242
        glEndList();
283
        glEndList();
243
        glUseProgram(old_prog);
284
        glUseProgram(old_prog);
244
    }
285
    }
245
    
286
    
246
    const string ReflectionLineRenderer::vss = 
287
    const string ReflectionLineRenderer::vss = 
Line 336... Line 377...
336
    "	\n"
377
    "	\n"
337
    "	gl_FragColor =  d+s;\n"
378
    "	gl_FragColor =  d+s;\n"
338
    "}\n";
379
    "}\n";
339
    
380
    
340
    
381
    
341
    void GlazedRenderer::compile_display_list(const HMesh::Manifold& m, bool smooth, float bsphere_rad)
382
    void GlazedRenderer::compile_display_list(const HMesh::Manifold& m, bool smooth)
342
    {
383
    {
343
        GLint old_prog;
384
        GLint old_prog;
344
        glGetIntegerv(GL_CURRENT_PROGRAM, &old_prog);
385
        glGetIntegerv(GL_CURRENT_PROGRAM, &old_prog);
345
        glUseProgram(prog);
386
        glUseProgram(prog);
346
        glNewList(display_list,GL_COMPILE);
387
        glNewList(display_list,GL_COMPILE);
347
        glBindTexture(GL_TEXTURE_3D, get_noise_texture_id());
388
        glBindTexture(GL_TEXTURE_3D, get_noise_texture_id());
348
        glUniform1iARB(glGetUniformLocationARB(prog, "noise_tex"),0);
389
        glUniform1iARB(glGetUniformLocationARB(prog, "noise_tex"),0);
-
 
390
        float r;
-
 
391
        Vec3d c;
-
 
392
        bsphere(m, c, r);
349
        glUniform1fARB(glGetUniformLocationARB(prog, "noise_scale"),12.0/bsphere_rad);
393
        glUniform1fARB(glGetUniformLocationARB(prog, "noise_scale"),12.0/r);
350
        GLGraphics::draw(m, smooth);
394
        GLGraphics::draw(m, smooth);
351
        glEndList();
395
        glEndList();
352
        glUseProgram(old_prog);
396
        glUseProgram(old_prog);
353
 
397
 
354
    }
398
    }
Line 544... Line 588...
544
        glUseProgram(old_prog);
588
        glUseProgram(old_prog);
545
        
589
        
546
    }
590
    }
547
    
591
    
548
    
592
    
549
    void LineFieldRenderer::compile_display_list(const HMesh::Manifold& m,HMesh::VertexAttributeVector<CGLA::Vec3d>& lines, float _r)
593
    void LineFieldRenderer::compile_display_list(const HMesh::Manifold& m,HMesh::VertexAttributeVector<CGLA::Vec3d>& lines)
550
    {
594
    {
-
 
595
        float r;
-
 
596
        Vec3d c;
551
        glNewList(display_list,GL_COMPILE);
597
        bsphere(m, c, r);
552
        float noise_scale = 10.0f/r;
598
        float noise_scale = 10.0f/r;
553
        float line_scale = 0.003f;
599
        float line_scale = 0.02f;
554
        
600
        
555
        GLint old_prog;
601
        GLint old_prog;
556
        glGetIntegerv(GL_CURRENT_PROGRAM, &old_prog);
602
        glGetIntegerv(GL_CURRENT_PROGRAM, &old_prog);
557
        glUseProgram(prog);	
603
        glUseProgram(prog);
-
 
604
        glNewList(display_list,GL_COMPILE);
558
        glUniform1fARB(glGetUniformLocationARB(prog, "scale_line"),line_scale*noise_scale);
605
        glUniform1fARB(glGetUniformLocationARB(prog, "line_scale"),line_scale);
559
        glUniform1fARB(glGetUniformLocationARB(prog, "noise_scale"),noise_scale);
606
        glUniform1fARB(glGetUniformLocationARB(prog, "noise_scale"),noise_scale);
560
        glUniform1iARB(glGetUniformLocationARB(prog, "noise_tex"),0);
607
        glUniform1iARB(glGetUniformLocationARB(prog, "noise_tex"),0);
561
        GLuint direction = glGetAttribLocation(prog, "direction");	
608
        GLuint direction = glGetAttribLocation(prog, "direction");	
562
        glBindTexture(GL_TEXTURE_3D, get_noise_texture_id());
609
        glBindTexture(GL_TEXTURE_3D, get_noise_texture_id());
563
 
610
 
-
 
611
 
564
        for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f){
612
        for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f){
565
            if(no_edges(m, *f) == 3)
613
            if(no_edges(m, *f) == 3)
566
                glBegin(GL_TRIANGLES);
614
                glBegin(GL_TRIANGLES);
567
            else 
615
            else 
568
                glBegin(GL_POLYGON);
616
                glBegin(GL_POLYGON);
569
            
617
            
-
 
618
            Vec3d n(normal(m, *f));
-
 
619
            Vec3d d0 = lines[m.walker(*f).vertex()];
-
 
620
            d0 = normalize(d0-n*dot(n,d0));
570
            for(Walker w = m.walker(*f); !w.full_circle(); w = w.circulate_face_ccw()){
621
            for(Walker w = m.walker(*f); !w.full_circle(); w = w.circulate_face_ccw()){
571
                Vec3d n(normal(m, w.vertex()));
622
                Vec3d n(normal(m, w.vertex()));
572
                glNormal3dv(n.get());
623
                glNormal3dv(n.get());
573
                
624
                
574
                Vec3d d = lines[w.vertex()];
625
                Vec3d d = lines[w.vertex()];
575
                d = normalize(d-n*dot(n,d));
626
                d = normalize(d-n*dot(n,d));
-
 
627
                if(dot(d,d0)<0) d=-d;
576
                glVertexAttrib3dv(direction, d.get());
628
                glVertexAttrib3dv(direction, d.get());
577
                glVertex3dv(m.pos(w.vertex()).get());
629
                glVertex3dv(m.pos(w.vertex()).get());
578
            }
630
            }
579
            glEnd();
631
            glEnd();
580
        }
632
        }
581
        
633
 
582
        glBindTexture(GL_TEXTURE_3D, 0);
634
        glBindTexture(GL_TEXTURE_3D, 0);
583
        glEndList();	
635
        glEndList();	
584
        glUseProgram(old_prog);
636
        glUseProgram(old_prog);
585
        
637
        
586
    }
638
    }
Line 600... Line 652...
600
    "	_n = normalize(gl_NormalMatrix * gl_Normal);\n"
652
    "	_n = normalize(gl_NormalMatrix * gl_Normal);\n"
601
    "}\n";
653
    "}\n";
602
    
654
    
603
    const string LineFieldRenderer::fss =
655
    const string LineFieldRenderer::fss =
604
    "uniform sampler3D noise_tex;\n"
656
    "uniform sampler3D noise_tex;\n"
605
    "uniform float scale_line;\n"
657
    "uniform float line_scale;\n"
606
    "uniform float noise_scale;\n"
658
    "uniform float noise_scale;\n"
607
    "varying vec3 _n;\n"
659
    "varying vec3 _n;\n"
608
    "varying vec3 dir_obj;\n"
660
    "varying vec3 dir_obj;\n"
609
    "varying vec3 v_obj;\n"
661
    "varying vec3 v_obj;\n"
610
    "\n"
662
    "\n"
611
    "float tex(vec3 p) {return smoothstep(0.2,0.3,texture3D(noise_tex, p).x);}\n"
663
    "float tex(vec3 p) {return smoothstep(0.2,0.4,texture3D(noise_tex, p).x);}\n"
612
    "void main(void)\n"
664
    "void main(void)\n"
613
    "{\n"
665
    "{\n"
614
    "   vec3 n = normalize(_n);\n"
666
    "   vec3 n = normalize(_n);\n"
-
 
667
    "   vec3 d = normalize(dir_obj);\n"
615
    "   float I = "
668
    "   float I = "
616
    "             tex(noise_scale*v_obj + 6.0*scale_line*dir_obj) + \n"
669
    "             tex(noise_scale*v_obj + 6.0*line_scale*d) + \n"
617
    "             tex(noise_scale*v_obj - 6.0*scale_line*dir_obj) + \n"
670
    "             tex(noise_scale*v_obj - 6.0*line_scale*d) + \n"
618
    "             tex(noise_scale*v_obj + 5.0*scale_line*dir_obj) + \n"
671
    "             tex(noise_scale*v_obj + 5.0*line_scale*d) + \n"
619
    "             tex(noise_scale*v_obj - 5.0*scale_line*dir_obj) + \n"
672
    "             tex(noise_scale*v_obj - 5.0*line_scale*d) + \n"
620
    "             tex(noise_scale*v_obj + 4.0*scale_line*dir_obj) + \n"
673
    "             tex(noise_scale*v_obj + 4.0*line_scale*d) + \n"
621
    "             tex(noise_scale*v_obj - 4.0*scale_line*dir_obj) + \n"
674
    "             tex(noise_scale*v_obj - 4.0*line_scale*d) + \n"
622
    "             tex(noise_scale*v_obj + 3.0*scale_line*dir_obj) + \n"
675
    "             tex(noise_scale*v_obj + 3.0*line_scale*d) + \n"
623
    "             tex(noise_scale*v_obj - 3.0*scale_line*dir_obj) + \n"
676
    "             tex(noise_scale*v_obj - 3.0*line_scale*d) + \n"
624
    "             tex(noise_scale*v_obj + 2.0*scale_line*dir_obj) + \n"
677
    "             tex(noise_scale*v_obj + 2.0*line_scale*d) + \n"
625
    "             tex(noise_scale*v_obj - 2.0*scale_line*dir_obj) + \n"
678
    "             tex(noise_scale*v_obj - 2.0*line_scale*d) + \n"
626
    "             tex(noise_scale*v_obj + 1.0*scale_line*dir_obj) + \n"
679
    "             tex(noise_scale*v_obj + 1.0*line_scale*d) + \n"
627
    "             tex(noise_scale*v_obj - 1.0*scale_line*dir_obj) + \n"
680
    "             tex(noise_scale*v_obj - 1.0*line_scale*d) + \n"
628
    "			  tex(noise_scale*v_obj); \n"
681
    "			  tex(noise_scale*v_obj); \n"
629
    "	\n"
682
    "	\n"
630
    "   float diff = max(0.0,dot(n,vec3(0.0, 0.0, 1.0)));\n"
683
    "   float diff = max(0.0,dot(n,vec3(0.0, 0.0, 1.0)));\n"
631
    "	gl_FragColor.rgb = vec3(diff*I*(1.0/13.0));\n"
684
    "	gl_FragColor.rgb = vec3(diff*I/13.0);\n"
632
    "	gl_FragColor.a = 1.0;\n"
685
    "	gl_FragColor.a = 1.0;\n"
633
    "}\n";
686
    "}\n";
634
    
687
    
-
 
688
    GLuint HarmonicsRenderer::prog_P0 = 0;
-
 
689
    GLGraphics::Console::variable<float> HarmonicsRenderer::display_harmonics_time;
-
 
690
    GLGraphics::Console::variable<int> HarmonicsRenderer::display_harmonics_diffuse;
-
 
691
    GLGraphics::Console::variable<int> HarmonicsRenderer::display_harmonics_highlight;
-
 
692
    
-
 
693
    string vss =
-
 
694
	"#version 120\n"
-
 
695
	"#extension GL_EXT_gpu_shader4 : enable\n"
-
 
696
	"	\n"
-
 
697
	"	\n"
-
 
698
	"	attribute float eigenvalue;\n"
-
 
699
	"	attribute float eigenvalue2;\n"
-
 
700
	"	varying vec3 normal;\n"
-
 
701
	"	varying float eig;\n"
-
 
702
	"	varying float eig2;\n"
-
 
703
	"	\n"
-
 
704
	"	void main(void)\n"
-
 
705
	"	{\n"
-
 
706
	"		gl_Position =  ftransform();\n"
-
 
707
	"		normal = normalize(gl_NormalMatrix * gl_Normal);\n"
-
 
708
	"		eig = eigenvalue;\n"
-
 
709
	"		eig2 = eigenvalue2;\n"
-
 
710
	"	}\n";
-
 
711
	
-
 
712
	string fss =
-
 
713
	"#version 120\n"
-
 
714
	"#extension GL_EXT_gpu_shader4 : enable\n"
-
 
715
	"	\n"
-
 
716
	"	varying vec3 normal;\n"
-
 
717
	"	varying float eig;\n"
-
 
718
	"	varying float eig2;\n"
-
 
719
	"	uniform float eig_max;\n"
-
 
720
	"	uniform float eig_max2;\n"
-
 
721
	"	uniform bool do_highlight;\n"
-
 
722
	"	uniform bool do_diffuse;\n"
-
 
723
	"	const vec3 light_dir = vec3(0,0,1);\n"
-
 
724
	"	\n"
-
 
725
	" float basef(float x) {return max(0.0,min(1.0,2.0-4.0*abs(x)));\n}"
-
 
726
	"	void main()\n"
-
 
727
	"	{\n"
-
 
728
	"		float dot_ln = max(0.0,dot(light_dir, normal));\n"
-
 
729
	"		\n"
-
 
730
	"		float eig_norm = eig/eig_max;\n"
-
 
731
	"		float stripe_signal = 250 * eig_norm;\n"
-
 
732
	//"		vec4 stripe_col = abs(stripe_signal) < 3.14 ? vec4(1,1,0,0) : vec4(.4,.4,.4,0);\n"
-
 
733
	"		vec4 stripe_col = -vec4(.4,.4,.4,0);\n"
-
 
734
	"		\n"
-
 
735
	"       float alpha = (1.0-eig_norm) * 2.0 * 3.1415926;\n"
-
 
736
	"       float offs = 2.0*3.1415/3.0;\n"
-
 
737
	"		gl_FragColor = vec4(0,0,1,0)*basef(eig_norm)+vec4(0,1,0,0)*basef(eig_norm-0.5)+vec4(1,0,0,0)* basef(eig_norm-1.0);\n"
-
 
738
	"		if(do_diffuse)   gl_FragColor *= dot_ln;\n"
-
 
739
	"		if(do_highlight) gl_FragColor += dot_ln*dot_ln*dot_ln*dot_ln*dot_ln*dot_ln*dot_ln*vec4(.5,.5,.5,0);\n"
-
 
740
	"		gl_FragColor -= vec4(.4,.4,.4,.4)*smoothstep(0.2,0.6,cos(stripe_signal));\n"
-
 
741
	"	}\n";
-
 
742
    
-
 
743
 
-
 
744
    HarmonicsRenderer::HarmonicsRenderer(HMesh::Manifold& _m, HMesh::Harmonics* _h, GLGraphics::Console& cs): m(&_m), h(_h)
-
 
745
    {
-
 
746
        if (prog_P0 == 0) {
-
 
747
            string shader_path = "/Users/jab/GEL/apps/MeshEdit/";
-
 
748
            GLuint vs = create_glsl_shader(GL_VERTEX_SHADER, vss);
-
 
749
            GLuint fs = create_glsl_shader(GL_FRAGMENT_SHADER, fss);
-
 
750
            
-
 
751
            // Create the program
-
 
752
            prog_P0 = glCreateProgram();
-
 
753
            
-
 
754
            // Attach all shaders
-
 
755
            if(vs) glAttachShader(prog_P0, vs);
-
 
756
            if(fs) glAttachShader(prog_P0, fs);
-
 
757
            
-
 
758
            // Link the program object and print out the info log
-
 
759
            glLinkProgram(prog_P0);
-
 
760
            print_glsl_program_log(prog_P0);
-
 
761
            
-
 
762
            // Install program object as part of current state
-
 
763
            glUseProgram(0);
-
 
764
            
-
 
765
            
-
 
766
            display_harmonics_diffuse.reg(cs, "display.harmonics.diffuse", "");
-
 
767
            display_harmonics_time.reg(cs, "display.harmonics.time", "");
-
 
768
            display_harmonics_highlight.reg(cs, "display.harmonics.highlight", "");
-
 
769
        }
-
 
770
        draw_adf();
-
 
771
    }
-
 
772
    
-
 
773
    
-
 
774
    void HarmonicsRenderer::parse_key(unsigned char key)
-
 
775
    {
-
 
776
        switch(key) {
-
 
777
            case '+':
-
 
778
                display_harmonics_time = display_harmonics_time+0.001;
-
 
779
                break;
-
 
780
            case '-':
-
 
781
                display_harmonics_time = display_harmonics_time-0.001;
-
 
782
                break;
-
 
783
            case 'd':
-
 
784
                display_harmonics_diffuse = !display_harmonics_diffuse;
-
 
785
                break;
-
 
786
            case 'h':
-
 
787
                display_harmonics_highlight = !display_harmonics_highlight;
-
 
788
                break;
-
 
789
        }
-
 
790
        
-
 
791
    }
-
 
792
    
-
 
793
    
-
 
794
    
-
 
795
    
-
 
796
    void HarmonicsRenderer::draw_adf()
-
 
797
    {
-
 
798
        VertexAttributeVector<double> F;
-
 
799
        double F_max = h->compute_adf(F, display_harmonics_time);
-
 
800
        cout << "F max" <<  F_max << endl;
-
 
801
        
-
 
802
        glNewList(display_list, GL_COMPILE);
-
 
803
        glUseProgram(prog_P0);
-
 
804
        glUniform1f(glGetUniformLocation(prog_P0,"eig_max"),F_max);//2*M_PI);
-
 
805
        glUniform1i(glGetUniformLocation(prog_P0,"do_diffuse"),display_harmonics_diffuse);
-
 
806
        glUniform1i(glGetUniformLocation(prog_P0,"do_highlight"),display_harmonics_highlight);
-
 
807
        GLuint attrib = glGetAttribLocationARB(prog_P0, "eigenvalue");
-
 
808
        
-
 
809
        glFrontFace(GL_CW);
-
 
810
        for(FaceIDIterator f = m->faces_begin(); f != m->faces_end(); ++f){
-
 
811
            glBegin(GL_TRIANGLES);
-
 
812
            for(Walker w = m->walker(*f); !w.full_circle(); w = w.circulate_face_cw()){
-
 
813
                glVertexAttrib1f(attrib,F[w.vertex()]);
-
 
814
                glNormal3dv(normal(*m, w.vertex()).get());
-
 
815
                glVertex3dv(m->pos(w.vertex()).get());
-
 
816
            }
-
 
817
            glEnd();
-
 
818
        }
-
 
819
        glFrontFace(GL_CCW);
-
 
820
        glUseProgram(0);
-
 
821
        glEndList();
-
 
822
    }
-
 
823
    
-
 
824
 
635
    
825
    
636
}
826
}
637
 
827
 
638
 
828