Beispiel #1
0
void init()
{
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glShadeModel(GL_SMOOTH);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    glEnable(GL_BLEND);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
 
    glPointSize(1.7f);
    
    srand((unsigned)time(NULL));

    int size = 1600;

    scene_object::color_type color(0.1, 0.5, 1.0, 1.0);

    generate_sphere(g_object_sphere, color, 0.5f, size);
    generate_torus(g_object_torus, color, 0.5f, 0.1f, size);
    generate_cube(g_object_cube, color, 1.0f, size);
    generate_lines(g_object_lines, color, 0.5f, size);
    generate_spiral(g_object_spiral, color, 0.5f, size);
    generate_paraboloid(g_object_paraboloid, color, 0.5f, size);
    generate_chaos(g_object_chaos, color, 0.5f, size);
    
    g_objects.push_back(g_object_sphere);
    g_objects.push_back(g_object_torus);
    g_objects.push_back(g_object_lines);
    g_objects.push_back(g_object_cube);
    g_objects.push_back(g_object_spiral);
    g_objects.push_back(g_object_paraboloid);
    g_objects.push_back(g_object_chaos);

    g_object = g_objects[g_object_index];

    std::cout << "Number of points in the object : " << g_object.points.size() << std::endl;

    g_move_delta = 1.0f / MORPHING_STEPS;
}
Beispiel #2
0
Scene::Scene(Display *disp) : 
    light_number(0), disp(disp), camera_changed(false), 
    octree(Vec3<float>(0,0,0),Vec3<float>(4096,4096,4096))
{
    // program initialisation
    disp->new_program("shaders/default.vert","shaders/default.frag",NULL,NULL,NULL);
    disp->new_program("shaders/fullscreen_draw.vert","shaders/phong.frag",NULL,NULL,NULL,"phong");
    disp->new_program("shaders/blur_vertical.vert","shaders/blur.frag",NULL,NULL,NULL,"vertical_blur");
    disp->new_program("shaders/blur_horizontal.vert","shaders/blur.frag",NULL,NULL,NULL,"horizontal_blur");
    disp->new_program("shaders/pointlight_draw.vert","shaders/phong_pointlight.frag",NULL,NULL,NULL,"phong_pointlight");
    disp->new_program("shaders/pointlight_draw.vert","shaders/depth_creation.frag",NULL,NULL,NULL,"phong_pointlight_stencil");
    disp->new_program("shaders/depth_creation.vert","shaders/depth_creation.frag",NULL,NULL,NULL,"depth_creation");
    disp->new_program("shaders/displaytexture.vert","shaders/displaytexture.frag",NULL,NULL,NULL,"display_texture");
    //disp->new_program("shaders/deferred_tess.vert","shaders/deferred_tess.frag","shaders/terrain_tc.tess","shaders/terrain_te.tess",NULL,"deferred_tess");
    disp->new_program("shaders/deferred.vert","shaders/deferred.frag",NULL,NULL,NULL,"deferred");

    int screen_width=disp->get_width();
    int screen_height=disp->get_height();

    globalvalues=disp->new_uniformblock("GlobalValues");
    disp->link_program_to_uniformblock("default",globalvalues);
    disp->link_program_to_uniformblock("phong",globalvalues);
    disp->link_program_to_uniformblock("phong_pointlight",globalvalues);
    disp->link_program_to_uniformblock("phong_pointlight_stencil",globalvalues);
    disp->link_program_to_uniformblock("depth_creation",globalvalues);
    disp->link_program_to_uniformblock("deferred",globalvalues);
    disp->link_program_to_uniformblock("display_texture",globalvalues);
    disp->link_program_to_uniformblock("vertical_blur",globalvalues);
    disp->link_program_to_uniformblock("horizontal_blur",globalvalues);

    
    Vec2<float> screen_size(screen_width,screen_height);
    globalvalues->set_value(screen_size, "screen_size");

    for(int i=0;i<MAX_LIGHTS;i++) {
        lights[i]=NULL;
    }
    
    if(disp->has_program("phong")) {
        uniform_cascaded_shading_zdelta=disp->new_uniform("cascaded_shading_zdelta",UNIFORM_FLOAT);
        disp->link_program_to_uniform("phong",uniform_cascaded_shading_zdelta);

        uniform_phong_normalmap=disp->new_uniform("normalmap",UNIFORM_SAMPLER);
        disp->link_program_to_uniform("phong",uniform_phong_normalmap);

        uniform_phong_depthmap=disp->new_uniform("depthmap",UNIFORM_SAMPLER);
        disp->link_program_to_uniform("phong",uniform_phong_depthmap);

        uniform_phong_colormap=disp->new_uniform("colormap",UNIFORM_SAMPLER);
        disp->link_program_to_uniform("phong",uniform_phong_colormap);

        uniform_phong_texcoordmap=disp->new_uniform("texcoordmap",UNIFORM_SAMPLER);
        disp->link_program_to_uniform("phong",uniform_phong_texcoordmap);

        uniform_light=disp->new_uniformblock("Light");
        disp->link_program_to_uniformblock("phong",uniform_light);
        
        uniform_light_sampler=disp->new_uniform("shadowmap",UNIFORM_SAMPLER);
        disp->link_program_to_uniform("phong",uniform_light_sampler);

            //uniform_name.str("");
            //uniform_name<<"shadowcubemap["<<i<<"]";
            //uniform_light_samplercube[i]=disp->new_uniform(uniform_name.str(),UNIFORM_SAMPLER);
            //disp->link_program_to_uniform("phong",uniform_light_samplercube[i]);
        

    }
    if(disp->has_program("phong_pointlight")) {
        disp->link_program_to_uniform("phong_pointlight",uniform_phong_normalmap);
        disp->link_program_to_uniform("phong_pointlight",uniform_phong_depthmap);
        disp->link_program_to_uniform("phong_pointlight",uniform_phong_colormap);
        disp->link_program_to_uniformblock("phong_pointlight",uniform_light);
    }
    if(disp->has_program("vertical_blur")) {
        uniform_postprocess_colormap=disp->new_uniform("deferred_colormap",UNIFORM_SAMPLER);

        //disp->link_program_to_uniform("blur_vertical",uniform_phong_normalmap);
        //disp->link_program_to_uniform("blur_vertical",uniform_phong_depthmap);
        disp->link_program_to_uniform("vertical_blur",uniform_postprocess_colormap);
    }
    if(disp->has_program("horizontal_blur")) {
        //disp->link_program_to_uniform("blur_horizontal",uniform_phong_normalmap);
        //disp->link_program_to_uniform("blur_horizontal",uniform_phong_depthmap);
        disp->link_program_to_uniform("horizontal_blur",uniform_postprocess_colormap);
    }
    if(disp->has_program("depth_creation")) {
        uniform_light_projection=disp->new_uniformblock("Light_properties");
        disp->link_program_to_uniformblock("depth_creation",uniform_light_projection);
    }
    if(disp->has_program("display_texture")) {
        uniform_displaytex_tex = disp->new_uniform("tex",UNIFORM_SAMPLER);
        uniform_displaytex_arraytex = disp->new_uniform("arraytex",UNIFORM_SAMPLER);
        uniform_displaytex_choice = disp->new_uniform("choice",UNIFORM_INT);
        disp->link_program_to_uniform("display_texture",uniform_displaytex_tex);
        disp->link_program_to_uniform("display_texture",uniform_displaytex_arraytex);
        disp->link_program_to_uniform("display_texture",uniform_displaytex_choice);
    }

    generate_fullscreen_quad();
    generate_cube(); //cube centered at 0,0,0 and of size 2 (-1 to 1)
    
    // textures initialization
    null_colortex=new Texture(DEPTH_TEXTURE_SIZE,DEPTH_TEXTURE_SIZE,TEXTURE_RGBA);
    deferred_colormap=new Texture(screen_width,screen_height,TEXTURE_RGBA);
    deferred_normalmap=new Texture(screen_width,screen_height,TEXTURE_RGBA);
    deferred_texcoordmap=new Texture(screen_width,screen_height,TEXTURE_RGBA);
    deferred_depthmap=new Texture(screen_width,screen_height,TEXTURE_DEPTH);
    deferred_result=new Texture(screen_width,screen_height,TEXTURE_RGBA);
    postprocess_flip1=new Texture(screen_width,screen_height,TEXTURE_RGBA);
    postprocess_flip2=new Texture(screen_width,screen_height,TEXTURE_RGBA);

    // uniform setting
    uniform_phong_normalmap->set_value(deferred_normalmap);
    uniform_phong_colormap->set_value(deferred_colormap);
    uniform_phong_texcoordmap->set_value(deferred_texcoordmap);
    uniform_phong_depthmap->set_value(deferred_depthmap);

    uniform_displaytex_tex->set_value(postprocess_flip2);
    uniform_displaytex_choice->set_value(-1);
    
    //rendering FBOs initialization
    fbo_shadows.attach_texture(null_colortex,FBO_COLOR0);
    
    fbo_deferred_phong.attach_texture(deferred_result,FBO_COLOR0);
    fbo_deferred_phong.attach_texture(deferred_depthmap,FBO_DEPTH);
    
    fbo_deferred.attach_texture(deferred_normalmap,FBO_COLOR0);
    fbo_deferred.attach_texture(deferred_colormap,FBO_COLOR1);
    fbo_deferred.attach_texture(deferred_texcoordmap,FBO_COLOR2);
    fbo_deferred.attach_texture(deferred_depthmap,FBO_DEPTH);
}