]> git.tdb.fi Git - r2c2.git/blobdiff - source/3d/view.cpp
Improve graphics quality with some shaders and effects
[r2c2.git] / source / 3d / view.cpp
index ef03c4b7139f42cdb7d357c7310c8d6fc09f85dd..69049e0b3e8e2232277ad4d0ee0f93e374424075 100644 (file)
@@ -14,11 +14,14 @@ View3D::View3D(Layout3D &l, unsigned w, unsigned h):
        width(w),
        height(h),
        pipeline(w, h),
-       sky(layout.get_catalogue())
+       sky(layout.get_catalogue()),
+       shadow(4096, layout.get_scene(), layout.get_sun()),
+       ambient_occlusion(w, h, 100)
 {
+       pipeline.set_hdr(true);
        pipeline.set_camera(&camera);
        pipeline.add_renderable(sky);
-       pipeline.add_renderable_for_pass(layout.get_scene(), 0);
+       pipeline.add_renderable_for_pass(shadow, 0);
        pipeline.add_renderable_for_pass(layout.get_scene(), "translucent");
 
        GL::Pipeline::Pass *pass = &pipeline.add_pass("sky");
@@ -32,6 +35,13 @@ View3D::View3D(Layout3D &l, unsigned w, unsigned h):
        pass->set_depth_test(&GL::DepthTest::lequal());
        pass->set_blend(&GL::Blend::alpha());
 
+       pipeline.add_postprocessor(ambient_occlusion);
+       colorcurve.set_srgb();
+       pipeline.add_postprocessor(colorcurve);
+
+       update_shadow_area();
+       layout.get_layout().signal_object_added.connect(sigc::hide(sigc::mem_fun(this, &View3D::update_shadow_area)));
+
        camera.set_up_direction(GL::Vector3(0, 0, 1));
        // Y+, 60° down
        camera.set_look_direction(GL::Vector3(0, 0.5, -0.866));
@@ -52,15 +62,21 @@ Ray View3D::create_ray(float x, float y) const
        return Ray(start, Vector(ray));
 }
 
-void View3D::view_all(bool tight)
+void View3D::compute_bounds(Vector &minp, Vector &maxp)
 {
-       const set<Track *> &tracks = layout.get_layout().get_all<Track>();
+       const set<Object *> &objects = layout.get_layout().get_all<Object>();
        Geometry::BoundingBox<float, 3> bbox;
-       for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
+       for(set<Object *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
                bbox = bbox|(*i)->get_bounding_box();
 
-       const Vector &minp = bbox.get_minimum_point();
-       const Vector &maxp = bbox.get_maximum_point();
+       minp = bbox.get_minimum_point();
+       maxp = bbox.get_maximum_point();
+}
+
+void View3D::view_all(bool tight)
+{
+       Vector minp, maxp;
+       compute_bounds(minp, maxp);
 
        float t = tan(camera.get_field_of_view()/2.0f)*2.0f;
        float size = max((maxp.y-minp.y+0.1), (maxp.x-minp.x+0.1)/camera.get_aspect());
@@ -78,4 +94,11 @@ void View3D::render()
        pipeline.render();
 }
 
+void View3D::update_shadow_area()
+{
+       Vector minp, maxp;
+       compute_bounds(minp, maxp);
+       shadow.set_target((minp+maxp)/2.0f, (maxp-minp).norm()/2.0f);
+}
+
 } // namespace R2C2