Example #1
0
texture_2d fdog_filter(const texture_2d& src, 
                       const texture_2d& tfm,
                       int n,
                       float sigma_e,
                       float sigma_r,
                       float tau,
                       float sigma_m,
                       float phi) 
{
    texture_2d tmp(src.clone_format());
    texture_2d dst(src.clone_format());

    for (int i = 0; i < n; ++i) {
        texture_2d img = (i == 0)? src : overlay(dst, src);
        glsl_program fdog0("fdog0_fs.glsl");
        fdog0.use();
        fdog0.bind_sampler("img", img, GL_LINEAR);
        fdog0.bind_sampler("tfm", tfm, GL_NEAREST);
        fdog0.set_uniform_1f("sigma_e", sigma_e);
        fdog0.set_uniform_1f("sigma_r", sigma_r);
        fdog0.set_uniform_1f("tau", tau);
        fdog0.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height());
        fdog0.draw(&tmp);

        glsl_program fdog1("fdog1_fs.glsl");
        fdog1.use();
        fdog1.bind_sampler("img", tmp, GL_LINEAR);
        fdog1.bind_sampler("tfm", tfm, GL_NEAREST);
        fdog1.set_uniform_1f("sigma_m", sigma_m);
        fdog1.set_uniform_1f("phi", phi);
        fdog1.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height());
        fdog0.draw(&dst);
    }
    return dst;
}
Example #2
0
texture_2d tangent_flow_map(const texture_2d& src, float sigma) {
    texture_2d tmp0(src.clone_format());
    texture_2d tmp1(src.clone_format());
    texture_2d dst(src.clone_format());
    
    glsl_program sst("sst_fs.glsl");
    sst.use();
    sst.bind_sampler("img", src);
    sst.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height());
    sst.draw(&tmp0);

    glsl_program gauss("gauss_fs.glsl");
    gauss.use();
    gauss.bind_sampler("img", tmp0);
    gauss.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height());
    gauss.set_uniform_1f("sigma", sigma);
    gauss.draw(&tmp1);                  

    glsl_program tfm("tfm_fs.glsl");
    tfm.use();
    tfm.bind_sampler("img", tmp1);
    tfm.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height());
    tfm.draw(&dst);

    return dst;
}
Example #3
0
texture_2d orientation_aligned_bilateral_filter(const texture_2d& src,
                                                const texture_2d& tfm, 
                                                int n, 
                                                float sigma_d,     
                                                float sigma_r) 
{
    texture_2d tmp(src.clone_format());
    texture_2d dst(src.clone_format());

    glsl_program glsl("bf_fs.glsl");
    glsl.use();
    glsl.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height());
    glsl.set_uniform_1f("sigma_d", sigma_d);
    glsl.set_uniform_1f("sigma_r", sigma_r);
    glsl.bind_sampler("tfm", tfm);

    for (int i = 0; i < n; ++i) {
        glsl.bind_sampler("img", (i == 0)? src : dst, GL_LINEAR);
        glsl.set_uniform_1i("pass", 0);
        glsl.draw(&tmp);

        glsl.bind_sampler("img", tmp, GL_LINEAR);
        glsl.set_uniform_1i("pass", 1);
        glsl.draw(&dst);
    }

    return dst;
}
Example #4
0
texture_2d lab2rgb(const texture_2d& src) {
    glsl_program glsl("lab2rgb_fs.glsl");
    texture_2d dst(src.clone_format());
    
    glsl.use();
    glsl.bind_sampler("img", src);
    glsl.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height());
    glsl.draw(&dst);
    return dst;
}
Example #5
0
texture_2d gauss_filter(const texture_2d& src, 
                        float sigma) 
{
    glsl_program glsl("gauss_fs.glsl");
    texture_2d dst(src.clone_format());
    
    glsl.use();
    glsl.bind_sampler("img", src);
    glsl.set_uniform_1f("sigma", sigma);
    glsl.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height());
    glsl.draw(&dst);
    return dst;
}
Example #6
0
texture_2d dog_filter(const texture_2d& src, 
					   int n,
					   float sigma_e,
					   float sigma_r,
					   float tau,
					   float phi) 
{
	texture_2d tmp(src.clone_format());
	//texture_2d dst(src.clone_format());

	for (int i = 0; i < n; ++i) {
		texture_2d img = (i == 0)? src : overlay(tmp, src);
		glsl_program dog("dog_fs.glsl");
		dog.use();
		dog.bind_sampler("img", img, GL_NEAREST);
		dog.set_uniform_1f("sigma_e", sigma_e);
		dog.set_uniform_1f("sigma_r", sigma_r);
		dog.set_uniform_1f("tau", tau);
		dog.set_uniform_1f("phi", phi);
		dog.set_uniform_2f("img_size", (float)src.get_width(), (float)src.get_height());
		dog.draw(&tmp);
	}
	return tmp;
}
Example #7
0
void init_scene()
  {
    unsigned int i;

    srand(1000);

    // load textures:
    terrain_heightmap.load_ppm("terrain_heightmap.ppm");
    terrain_texturemap.load_ppm("terrain_texturemap.ppm");
    water_texture.load_ppm("water.ppm");
    grass_texture.load_ppm("grass.ppm");
    sand_texture.load_ppm("sand.ppm");
    sky_texture.load_ppm("sky.ppm");
    rock_texture.load_ppm("rock.ppm");
    tree_texture.load_ppm("tree.ppm");
    tree_texture.set_transparency(true);
    tree_texture.set_transparent_color(255,0,0);

    // make the sun:
    sun = make_sphere(50,10,10);
    sun->set_render_mode(RENDER_MODE_NO_LIGHT);
    sun->set_color(250,250,220);
    sun->set_position(-400,100,-400);

    // make the terrain:
    terrain = make_terrain(50,50,TERRAIN_HEIGHT,100,100,&terrain_heightmap);
    terrain->texture_map_plane(DIRECTION_DOWN,TERRAIN_TILE_FACTOR,TERRAIN_TILE_FACTOR);
    terrain->texture_map_layer_mask(&terrain_texturemap);
    terrain->set_lighting_properties(0.3,0.7,0.3,1.5);
    terrain->set_texture(&grass_texture);
    terrain->set_texture2(&sand_texture);

    // make the water animation of two frames:
    water_frame_0 = make_terrain(300,300,1,18,18,NULL);
    water_frame_0->texture_map_plane(DIRECTION_DOWN,20,20);

    water_frame_1 = new mesh_3d_static(water_frame_0);
    water_frame_1->update();

    for (i = 0; i < water_frame_0->vertex_count(); i++)    // deform the surface randomly so the water will move a little
      {
        water_frame_0->vertices[i].position.y += (rand() % 100) * 0.03;
        water_frame_1->vertices[i].position.y += (rand() % 100) * 0.03;
        water_frame_1->vertices[i].texture_coordinate[0] += (rand() % 10 - 5) * 0.02;
        water_frame_1->vertices[i].texture_coordinate[1] += (rand() % 10 - 5) * 0.02;
      }

    water_frame_0->update();
    water_frame_1->update();

    water = new mesh_3d_animated();

    water->add_frame(water_frame_0,2000);
    water->set_texture(&water_texture);
    water->add_frame(water_frame_1,2000);
    water->set_position(0,1,0);
    water->set_render_mode(RENDER_MODE_SHADED_GORAUD);
    water->set_lighting_properties(0.6,0.2,0.9,5);
    water->update();             // upload the animation data to GPU

    water->set_playing(true);    // play the animation

    water_static = make_plane(1000,1000,10,10);
    water_static->set_rotation(-90,0,0);
    water_static->set_position(0,-0.2,0);
    water_static->texture_map_plane(DIRECTION_FORWARD,50,50);
    water_static->set_texture(&water_texture);
    water_static->set_lighting_properties(0.6,0.2,0.9,5);

    // make the skybox:
    skybox = make_sphere(800,15,15);
    skybox->texture_map_plane(DIRECTION_FORWARD,3,3);
    skybox->flip_triangles();    // flip the sphere inside out as the camera will be inside
    skybox->set_render_mode(RENDER_MODE_NO_LIGHT);  // no shading for the sky
    skybox->set_texture(&sky_texture);

    camera.set_skybox(skybox);   // the skybox will follow camera movement now

    // make rocks:
    rock1 = new mesh_3d_static();
    rock1->load_obj("rock1.obj");

    for (i = 0; i < 3; i++)
      {
        rock1_instances[i] = new mesh_3d_static();
        rock1_instances[i]->set_render_mode(RENDER_MODE_SHADED_PHONG);
        rock1_instances[i]->set_texture(&rock_texture);
        rock1_instances[i]->make_instance_of(rock1);
        rock1_instances[i]->set_lighting_properties(0.6,0.6,0.3,1.2);
      }

    rock1_instances[0]->set_position(16,0,3);
    rock1_instances[0]->set_scale(0.3);
    rock1_instances[0]->set_rotation(0,10,3);

    rock1_instances[1]->set_position(5,0,22);
    rock1_instances[1]->set_scale(0.2);
    rock1_instances[1]->set_rotation(5,90,-3);

    rock1_instances[2]->set_position(-28,0,-14);
    rock1_instances[2]->set_scale(0.25);

    rock2 = new mesh_3d_static();
    rock2->load_obj("rock2.obj");

    for (i = 0; i < 5; i++)
      {
        rock2_instances[i] = new mesh_3d_static();
        rock2_instances[i]->set_render_mode(RENDER_MODE_SHADED_PHONG);
        rock2_instances[i]->set_texture(&rock_texture);
        rock2_instances[i]->make_instance_of(rock2);
        rock2_instances[i]->set_lighting_properties(0.6,0.6,0.3,1.2);
        rock2_instances[i]->set_scale(0.08);
      }

    rock2_instances[0]->set_position(14,2.5,-14);
    rock2_instances[1]->set_position(2,8.5,4);
    rock2_instances[1]->set_scale(0.12);

    rock2_instances[2]->set_position(-11,5,-11);
    rock2_instances[2]->set_rotation(0,20,0);
    rock2_instances[2]->set_scale(0.1);

    rock2_instances[2]->set_position(-2,9,-5);
    rock2_instances[2]->set_scale(0.2);

    rock2_instances[3]->set_position(-7,2,20);
    rock2_instances[3]->set_rotation(0,122,0);
    rock2_instances[3]->set_scale(0.15);

    rock2_instances[4]->set_position(-15,2,21);
    rock2_instances[4]->set_rotation(0,5,0);
    rock2_instances[4]->set_scale(0.12);

    // make trees:
    tree_low = new mesh_3d_static();
    tree_low->load_obj("tree_low.obj");
    tree_low->set_texture(&tree_texture);

    tree = new mesh_3d_static();
    tree->load_obj("tree.obj");

    tree->set_scale(0.1);
    tree->set_texture(&tree_texture);

    float x0,y0,z0,x1,y1,z1,island_width,island_height,position_x,position_y,height;
    unsigned char r,g,b;
    terrain->get_bounding_box(&x0,&y0,&z0,&x1,&y1,&z1);

    island_width = x1 - x0;
    island_height = z1 - z0;

    for (i = 0; i < NUMBER_OF_TREES; i++)       // make trees
      {
        position_x = ((rand() % 100) * 0.01 - 0.5) * 0.8 + 0.5;
        position_y = ((rand() % 100) * 0.01 - 0.5) * 0.8 + 0.5;

        terrain->add_shadow((1 - position_x) * TERRAIN_TILE_FACTOR,(1 - position_y) * TERRAIN_TILE_FACTOR,0.25,-0.1);

        terrain_heightmap.get_pixel(position_x * terrain_heightmap.get_width(),position_y * terrain_heightmap.get_height(),&r,&g,&b);
        height = r / 255.0 * TERRAIN_HEIGHT - 0.7;

        position_x *= island_width;             // transform from normalised to world coords
        position_y *= island_height;

        position_x -= island_width / 2.0;
        position_y -= island_height / 2.0;

        trees[i] = new mesh_3d_lod(true,true);
        trees[i]->add_detail_mesh(tree,10);
        trees[i]->add_detail_mesh(tree_low,100);
        trees[i]->set_lighting_properties(0.4,0.3,0.0,1);
        trees[i]->set_scale(0.1 + (rand() % 10) * 0.005);
        trees[i]->set_rotation(rand() % 100 * 0.15,rand() % 1000 * 0.360,rand() % 10 * 0.15);

        trees[i]->set_position(position_x,height,position_y);
      }
  }