Subversion Repositories gelsvn

Rev

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

Rev 630 Rev 631
Line 343... Line 343...
343
    "       vec3 normal = normalize(_normal);\n"
343
    "       vec3 normal = normalize(_normal);\n"
344
    "		float dot_ln = max(0.0,dot(light_dir, normal));\n"
344
    "		float dot_ln = max(0.0,dot(light_dir, normal));\n"
345
    "		\n"
345
    "		\n"
346
    "		float s_norm = s/scalar_max;\n"
346
    "		float s_norm = s/scalar_max;\n"
347
    "		float stripe_signal = 100.0 * s_norm;\n"
347
    "		float stripe_signal = 100.0 * s_norm;\n"
348
    "		vec4 stripe_col = abs(stripe_signal) < 3.14 ? vec4(0,0,0,0) : vec4(.1,.1,.1,0);\n"
348
    "		vec4 stripe_col = abs(stripe_signal) < 3.14 ? vec4(-1.0,0,0,0) : vec4(.9,.9,.9,0);\n"
349
    "		\n"
349
    "		\n"
350
    "		gl_FragColor = s_norm * vec4(-1,0,1,0);\n"
350
    "		gl_FragColor = s_norm * vec4(-1,0,1,0);\n"
351
    "       gl_FragColor *= dot_ln;\n"
351
    "       gl_FragColor *= dot_ln;\n"
352
    "       gl_FragColor.r = pow(gl_FragColor.r, 1.0/gamma);\n"
352
    "       gl_FragColor.r = pow(gl_FragColor.r, 1.0/gamma);\n"
353
    "       gl_FragColor.g = pow(gl_FragColor.g, 1.0/gamma);\n"
353
    "       gl_FragColor.g = pow(gl_FragColor.g, 1.0/gamma);\n"
Line 461... Line 461...
461
        }
461
        }
462
        glEndList();	
462
        glEndList();	
463
        glUseProgram(old_prog);
463
        glUseProgram(old_prog);
464
        
464
        
465
    }
465
    }
-
 
466
    
-
 
467
    const string CircleFieldRenderer::vss =
-
 
468
    "	attribute vec2 circlepos;\n"
-
 
469
    "	varying vec3 _normal;\n"
-
 
470
    "	varying vec2 s;\n"
-
 
471
    "	\n"
-
 
472
    "	void main(void)\n"
-
 
473
    "	{\n"
-
 
474
    "		gl_Position =  ftransform();\n"
-
 
475
    "		_normal = normalize(gl_NormalMatrix * gl_Normal);\n"
-
 
476
    "		s=circlepos;\n"
-
 
477
    "	}\n";
-
 
478
    
-
 
479
    const string CircleFieldRenderer::fss =
-
 
480
    "	varying vec3 _normal;\n"
-
 
481
    "	varying vec2 s;\n"
-
 
482
    "   uniform float gamma;\n"
-
 
483
    "	const vec3 light_dir = vec3(0,0,1);\n"
-
 
484
    "	\n"
-
 
485
    "	void main()\n"
-
 
486
    "	{\n"
-
 
487
    "       vec3 normal = normalize(_normal);\n"
-
 
488
    "		float dot_ln = max(0.0,dot(light_dir, normal));\n"
-
 
489
    "		\n"
-
 
490
    "       vec2 _s = normalize(s);\n"
-
 
491
    "       float a = atan(_s.y,_s.x);\n"
-
 
492
    "		gl_FragColor = sin(32.0*a) * vec4(-.7,0,.7,0)+vec4(0.3);\n"
-
 
493
    "       gl_FragColor *= dot_ln*length(s);\n"
-
 
494
    "       gl_FragColor.r = pow(gl_FragColor.r, 1.0/gamma);\n"
-
 
495
    "       gl_FragColor.g = pow(gl_FragColor.g, 1.0/gamma);\n"
-
 
496
    "       gl_FragColor.b = pow(gl_FragColor.b, 1.0/gamma);\n"
-
 
497
    "	}\n";
-
 
498
    
-
 
499
    CircleFieldRenderer::CircleFieldRenderer(const Manifold& m,
-
 
500
                                                             bool smooth,
-
 
501
                                                             VertexAttributeVector<Vec2d>& field,
-
 
502
                                                             float gamma): SimpleShaderRenderer(vss, fss)
-
 
503
    {
-
 
504
        
-
 
505
        GLint old_prog;
-
 
506
        glGetIntegerv(GL_CURRENT_PROGRAM, &old_prog);
-
 
507
        glUseProgram(prog);
-
 
508
        
-
 
509
        GLuint scalar_attrib = glGetAttribLocation(prog, "circlepos");
-
 
510
        
-
 
511
        //    static float& gamma = CreateCVar("display.scalar_field_renderer.gamma",2.2f);
-
 
512
        glUniform1fARB(glGetUniformLocationARB(prog, "gamma"), gamma);
-
 
513
        glNewList(display_list,GL_COMPILE);
-
 
514
        
-
 
515
        for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f){
-
 
516
            if(!smooth)
-
 
517
                glNormal3dv(normal(m, *f).get());
-
 
518
            if(no_edges(m, *f)== 3)
-
 
519
                glBegin(GL_TRIANGLES);
-
 
520
            else
-
 
521
                glBegin(GL_POLYGON);
-
 
522
            
-
 
523
            
-
 
524
            for(Walker w = m.walker(*f); !w.full_circle(); w = w.circulate_face_ccw()){
-
 
525
                Vec3d n(normal(m, w.vertex()));
-
 
526
                if(smooth)
-
 
527
                    glNormal3dv(n.get());
-
 
528
                glVertexAttrib2dv(scalar_attrib, field[w.vertex()].get());
-
 
529
                glVertex3dv(m.pos(w.vertex()).get());
-
 
530
            }
-
 
531
            glEnd();
-
 
532
        }
-
 
533
        glEndList();
-
 
534
        glUseProgram(old_prog);
-
 
535
        
-
 
536
    }
-
 
537
 
466
 
538
 
467
    const string AmbientOcclusionRenderer::vss =
539
    const string AmbientOcclusionRenderer::vss =
468
    "	attribute float scalar;\n"
540
    "	attribute float scalar;\n"
469
    "	varying vec3 _normal;\n"
541
    "	varying vec3 _normal;\n"
470
    "	varying float s;\n"
542
    "	varying float s;\n"