Line 20... |
Line 20... |
20 |
|
20 |
|
21 |
using namespace GLGraphics;
|
21 |
using namespace GLGraphics;
|
22 |
using namespace CGLA;
|
22 |
using namespace CGLA;
|
23 |
using namespace HMesh;
|
23 |
using namespace HMesh;
|
24 |
using namespace std;
|
24 |
using namespace std;
|
- |
|
25 |
using namespace CVarUtils;
|
25 |
|
26 |
|
26 |
GLuint get_noise_texture_id()
|
27 |
GLuint get_noise_texture_id()
|
27 |
{
|
28 |
{
|
28 |
static GLuint texname=0;
|
29 |
static GLuint texname=0;
|
29 |
static bool was_here = false;
|
30 |
static bool was_here = false;
|
Line 35... |
Line 36... |
35 |
int height = 32;
|
36 |
int height = 32;
|
36 |
int depth = 32;
|
37 |
int depth = 32;
|
37 |
vector<unsigned char> texels(width*height*depth);
|
38 |
vector<unsigned char> texels(width*height*depth);
|
38 |
for (int i = 0; i < width*height*depth; ++i)
|
39 |
for (int i = 0; i < width*height*depth; ++i)
|
39 |
{
|
40 |
{
|
40 |
int intensity = 255.0 * (float(rand()) / RAND_MAX);
|
41 |
int intensity = 255.0 * (float(random()) / RAND_MAX);
|
41 |
texels[i] = (unsigned char) intensity;
|
42 |
texels[i] = (unsigned char) intensity;
|
42 |
}
|
43 |
}
|
43 |
|
44 |
|
44 |
glGenTextures(1, &texname);
|
45 |
glGenTextures(1, &texname);
|
45 |
glBindTexture(GL_TEXTURE_3D, texname);
|
46 |
glBindTexture(GL_TEXTURE_3D, texname);
|
Line 326... |
Line 327... |
326 |
glUseProgram(prog);
|
327 |
glUseProgram(prog);
|
327 |
|
328 |
|
328 |
GLuint scalar_attrib = glGetAttribLocation(prog, "scalar");
|
329 |
GLuint scalar_attrib = glGetAttribLocation(prog, "scalar");
|
329 |
glUniform1fARB(glGetUniformLocationARB(prog, "scalar_max"), max_val);
|
330 |
glUniform1fARB(glGetUniformLocationARB(prog, "scalar_max"), max_val);
|
330 |
|
331 |
|
331 |
static CVar<float> gamma("display.scalar_field_renderer.gamma",2.2f);
|
332 |
static float& gamma = CreateCVar("display.scalar_field_renderer.gamma",2.2f);
|
332 |
glUniform1fARB(glGetUniformLocationARB(prog, "gamma"), gamma);
|
333 |
glUniform1fARB(glGetUniformLocationARB(prog, "gamma"), gamma);
|
333 |
glNewList(display_list,GL_COMPILE);
|
334 |
glNewList(display_list,GL_COMPILE);
|
334 |
|
335 |
|
335 |
for(FaceIter f=m.faces_begin(); f != m.faces_end(); ++f)
|
336 |
for(FaceIter f=m.faces_begin(); f != m.faces_end(); ++f)
|
336 |
{
|
337 |
{
|
Line 401... |
Line 402... |
401 |
glUseProgram(prog);
|
402 |
glUseProgram(prog);
|
402 |
|
403 |
|
403 |
GLuint scalar_attrib = glGetAttribLocation(prog, "scalar");
|
404 |
GLuint scalar_attrib = glGetAttribLocation(prog, "scalar");
|
404 |
glUniform1fARB(glGetUniformLocationARB(prog, "scalar_max"), max_val);
|
405 |
glUniform1fARB(glGetUniformLocationARB(prog, "scalar_max"), max_val);
|
405 |
|
406 |
|
406 |
static CVar<float> gamma("display.ambient_occlusion_renderer.gamma",1.5);
|
407 |
static float& gamma = CreateCVar("display.ambient_occlusion_renderer.gamma",1.5f);
|
407 |
glUniform1fARB(glGetUniformLocationARB(prog, "gamma"), gamma);
|
408 |
glUniform1fARB(glGetUniformLocationARB(prog, "gamma"), gamma);
|
408 |
static CVar<int> lighton("display.ambient_occlusion_renderer.light",1);
|
409 |
static int& lighton = CreateCVar("display.ambient_occlusion_renderer.light",1);
|
409 |
glUniform1iARB(glGetUniformLocationARB(prog, "lighton"), lighton);
|
410 |
glUniform1iARB(glGetUniformLocationARB(prog, "lighton"), lighton);
|
410 |
glNewList(display_list,GL_COMPILE);
|
411 |
glNewList(display_list,GL_COMPILE);
|
411 |
|
412 |
|
412 |
for(FaceIter f=m.faces_begin(); f != m.faces_end(); ++f)
|
413 |
for(FaceIter f=m.faces_begin(); f != m.faces_end(); ++f)
|
413 |
{
|
414 |
{
|
Line 486... |
Line 487... |
486 |
glUseProgram(prog);
|
487 |
glUseProgram(prog);
|
487 |
|
488 |
|
488 |
GLuint scalar_attrib = glGetAttribLocation(prog, "scalar");
|
489 |
GLuint scalar_attrib = glGetAttribLocation(prog, "scalar");
|
489 |
glUniform1fARB(glGetUniformLocationARB(prog, "scalar_max"), max_val);
|
490 |
glUniform1fARB(glGetUniformLocationARB(prog, "scalar_max"), max_val);
|
490 |
|
491 |
|
491 |
static CVar<float> gamma("display.patina_renderer.gamma",1.5);
|
492 |
static float& gamma = CreateCVar("display.patina_renderer.gamma",1.5f);
|
492 |
glUniform1fARB(glGetUniformLocationARB(prog, "gamma"), gamma);
|
493 |
glUniform1fARB(glGetUniformLocationARB(prog, "gamma"), gamma);
|
493 |
static CVar<int> lighton("display.patina_renderer.light",1);
|
494 |
static int& lighton = CreateCVar("display.patina_renderer.light",1);
|
494 |
glUniform1iARB(glGetUniformLocationARB(prog, "lighton"), lighton);
|
495 |
glUniform1iARB(glGetUniformLocationARB(prog, "lighton"), lighton);
|
495 |
glUniform1iARB(glGetUniformLocationARB(prog, "noise_tex"),0);
|
496 |
glUniform1iARB(glGetUniformLocationARB(prog, "noise_tex"),0);
|
496 |
glUniform1fARB(glGetUniformLocationARB(prog, "noise_scale"),12.0/bsphere_rad);
|
497 |
glUniform1fARB(glGetUniformLocationARB(prog, "noise_scale"),12.0/bsphere_rad);
|
497 |
|
498 |
|
498 |
glNewList(display_list,GL_COMPILE);
|
499 |
glNewList(display_list,GL_COMPILE);
|
Line 537... |
Line 538... |
537 |
SimpleShaderRenderer(vss,fss), r(_r)
|
538 |
SimpleShaderRenderer(vss,fss), r(_r)
|
538 |
{
|
539 |
{
|
539 |
GLint old_prog;
|
540 |
GLint old_prog;
|
540 |
glGetIntegerv(GL_CURRENT_PROGRAM, &old_prog);
|
541 |
glGetIntegerv(GL_CURRENT_PROGRAM, &old_prog);
|
541 |
glUseProgram(prog);
|
542 |
glUseProgram(prog);
|
542 |
static CVar<float> curvature_lines_scale("display.line_field_renderer.line_length", .015f);
|
543 |
static float& curvature_lines_scale = CreateCVar("display.line_field_renderer.line_length", .015f);
|
543 |
static CVar<float> noise_scale("display.line_field_renderer.noise_scale", 12.0f/r);
|
544 |
static float& noise_scale = CreateCVar("display.line_field_renderer.noise_scale", 12.0f/r);
|
544 |
static CVar<float> noise_amplitude("display.line_field_renderer.noise_amplitude", .06f);
|
545 |
static float& noise_amplitude = CreateCVar("display.line_field_renderer.noise_amplitude", .06f);
|
545 |
glUniform1fARB(glGetUniformLocationARB(prog, "scale_line"),curvature_lines_scale);
|
546 |
glUniform1fARB(glGetUniformLocationARB(prog, "scale_line"),curvature_lines_scale);
|
546 |
glUniform1fARB(glGetUniformLocationARB(prog, "noise_scale"),noise_scale);
|
547 |
glUniform1fARB(glGetUniformLocationARB(prog, "noise_scale"),noise_scale);
|
547 |
glUniform1fARB(glGetUniformLocationARB(prog, "noise_amplitude"),noise_amplitude);
|
548 |
glUniform1fARB(glGetUniformLocationARB(prog, "noise_amplitude"),noise_amplitude);
|
548 |
glUniform1iARB(glGetUniformLocationARB(prog, "noise_tex"),0);
|
549 |
glUniform1iARB(glGetUniformLocationARB(prog, "noise_tex"),0);
|
549 |
GLuint direction = glGetAttribLocation(prog, "direction");
|
550 |
GLuint direction = glGetAttribLocation(prog, "direction");
|
Line 610... |
Line 611... |
610 |
"uniform float noise_scale;\n"
|
611 |
"uniform float noise_scale;\n"
|
611 |
"varying vec3 n;\n"
|
612 |
"varying vec3 n;\n"
|
612 |
"varying vec3 dir_obj;\n"
|
613 |
"varying vec3 dir_obj;\n"
|
613 |
"varying vec3 v_obj;\n"
|
614 |
"varying vec3 v_obj;\n"
|
614 |
"\n"
|
615 |
"\n"
|
615 |
"float tex(vec3 p) {return smoothstep(0.25,0.5,texture3D(noise_tex, p).x);}\n"
|
616 |
"float tex(vec3 p) {return smoothstep(0.23,0.25,texture3D(noise_tex, p).x);}\n"
|
616 |
"void main(void)\n"
|
617 |
"void main(void)\n"
|
617 |
"{\n"
|
618 |
"{\n"
|
618 |
" float I = "
|
619 |
" float I = "
|
619 |
" tex(noise_scale*v_obj + 6.0*scale_line*dir_obj) + \n"
|
620 |
" tex(noise_scale*v_obj + 6.0*scale_line*dir_obj) + \n"
|
620 |
" tex(noise_scale*v_obj - 6.0*scale_line*dir_obj) + \n"
|
621 |
" tex(noise_scale*v_obj - 6.0*scale_line*dir_obj) + \n"
|
Line 629... |
Line 630... |
629 |
" tex(noise_scale*v_obj + 1.0*scale_line*dir_obj) + \n"
|
630 |
" tex(noise_scale*v_obj + 1.0*scale_line*dir_obj) + \n"
|
630 |
" tex(noise_scale*v_obj - 1.0*scale_line*dir_obj) + \n"
|
631 |
" tex(noise_scale*v_obj - 1.0*scale_line*dir_obj) + \n"
|
631 |
" tex(noise_scale*v_obj); \n"
|
632 |
" tex(noise_scale*v_obj); \n"
|
632 |
" \n"
|
633 |
" \n"
|
633 |
" float diff = max(0.0,dot(n,vec3(0.0, 0.0, 1.0)));\n"
|
634 |
" float diff = max(0.0,dot(n,vec3(0.0, 0.0, 1.0)));\n"
|
634 |
" gl_FragColor.rgb = vec3(1)*diff*I*noise_amplitude;\n"
|
635 |
" gl_FragColor.rgb = vec3(1)*diff*I*(1.0/13.0);\n"
|
635 |
" gl_FragColor.a = 1.0;\n"
|
636 |
" gl_FragColor.a = 1.0;\n"
|
636 |
"}\n";
|
637 |
"}\n";
|