Beispiel #1
0
volume_renderer::volume_renderer(const gl::render_device_ptr& device)
{
    using namespace scm;
    using namespace scm::gl;
    using namespace scm::math;
    using boost::assign::list_of;

    camera_uniform_block::add_block_include_string(device);

    _camera_block.reset(new gl::camera_uniform_block(device));

    // state objects //////////////////////////////////////////////////////////////////////////////
    //_bstate = device->create_blend_state(false, FUNC_ONE, FUNC_ZERO, FUNC_ONE, FUNC_ZERO);
    _bstate = device->create_blend_state(true, FUNC_SRC_ALPHA, FUNC_ONE_MINUS_SRC_ALPHA, FUNC_ONE, FUNC_ZERO);
    _dstate = device->create_depth_stencil_state(true, true, COMPARISON_LESS);
    _rstate = device->create_rasterizer_state(FILL_SOLID, CULL_BACK, ORIENT_CCW, true);
    _sstate_nearest = device->create_sampler_state(FILTER_MIN_MAG_NEAREST, WRAP_CLAMP_TO_EDGE);
    _sstate_lin = device->create_sampler_state(FILTER_MIN_MAG_LINEAR, WRAP_CLAMP_TO_EDGE);
    _sstate_lin_mip = device->create_sampler_state(FILTER_MIN_MAG_MIP_LINEAR, WRAP_CLAMP_TO_EDGE);

    if (   !_bstate
        || !_dstate
        || !_rstate
        || !_sstate_nearest
        || !_sstate_lin
        || !_sstate_lin_mip) {
        throw (std::runtime_error("volume_renderer::volume_renderer(): error creating state objects"));
    }

    if (!reload_shaders(device)) {
        throw std::runtime_error("volume_renderer::volume_renderer(): error loading shader programs.");
    }

    //_vtexture_program->uniform("model_matrix", model_matrix);
    //_vtexture_program->uniform_buffer("camera_matrices", 0);
    //_vtexture_program->uniform_subroutine(STAGE_FRAGMENT_SHADER, "out_color_gen", "draw_vtexture");
    //_vtexture_program->uniform_subroutine(STAGE_FRAGMENT_SHADER, "out_color_gen", "draw_debug_atlas");
    //_vtexture_program->uniform_subroutine(STAGE_FRAGMENT_SHADER, "out_color_gen", "draw_atlas");
    //_vtexture_program->uniform_subroutine(STAGE_FRAGMENT_SHADER, "out_color_gen", "visualize_normal");
    //_vtexture_program->uniform_subroutine(STAGE_FRAGMENT_SHADER, "out_color_gen", "visualize_texcoord");

}
Beispiel #2
0
texture_output::texture_output(const gl::render_device_ptr& device)
{
    using namespace scm::gl;
    using namespace scm::math;
    using boost::assign::list_of;

    mat4f pass_mvp = mat4f::identity();
    ortho_matrix(pass_mvp, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);

    // for fs-quad
    _quad_geom = make_shared<quad_geometry>(device, vec2f(0.0f, 0.0f), vec2f(1.0f, 1.0f));

    _fs_program_color = device->create_program(list_of(device->create_shader(scm::gl::STAGE_VERTEX_SHADER,   fs_vsrc,       "texture_output::fs_vsrc"))
                                                      (device->create_shader(scm::gl::STAGE_FRAGMENT_SHADER, fs_color_fsrc, "texture_output::fs_color_fsrc")),
                                               "texture_output::fs_program_color");

    if(!_fs_program_color) {
        throw (std::runtime_error("texture_output::texture_output(): error generating _fs_program_color program"));
    }
    _fs_program_color->uniform_sampler("in_texture", 0);
    _fs_program_color->uniform("mvp", pass_mvp);

    _fs_program_color_uint = device->create_program(list_of(device->create_shader(scm::gl::STAGE_VERTEX_SHADER,   fs_vsrc,            "texture_output::fs_vsrc"))
                                                           (device->create_shader(scm::gl::STAGE_FRAGMENT_SHADER, fs_color_uint_fsrc, "texture_output::fs_color_uint")),
                                               "texture_output::fs_program_color_uint");

    if(!_fs_program_color_uint) {
        throw (std::runtime_error("texture_output::texture_output(): error generating _fs_program_color_uint program"));
    }
    _fs_program_color_uint->uniform_sampler("in_texture", 0);
    _fs_program_color_uint->uniform("mvp", pass_mvp);

    _fs_program_color_uint8_bit_rev = device->create_program(list_of(device->create_shader(scm::gl::STAGE_VERTEX_SHADER,   fs_vsrc,                     "texture_output::fs_vsrc"))
                                                                    (device->create_shader(scm::gl::STAGE_FRAGMENT_SHADER, fs_color_uint8_bit_rev_fsrc, "texture_output::fs_color_uint8_bit_rev_fsrc")),
                                               "texture_output::fs_program_color_uint8_bit_rev");

    if(!_fs_program_color_uint8_bit_rev) {
        throw (std::runtime_error("texture_output::texture_output(): error generating _fs_program_color_uint8_bit_rev program"));
    }
    _fs_program_color_uint8_bit_rev->uniform_sampler("in_texture", 0);
    _fs_program_color_uint8_bit_rev->uniform("mvp", pass_mvp);
    _fs_program_color_uint8_bit_rev->uniform("in_scale", vec4f(1.0f / 255.0f));

    _fs_program_gray = device->create_program(list_of(device->create_shader(scm::gl::STAGE_VERTEX_SHADER,   fs_vsrc,      "texture_output::fs_vsrc"))
                                                     (device->create_shader(scm::gl::STAGE_FRAGMENT_SHADER, fs_gray_fsrc, "texture_output::fs_gray_fsrc")),
                                               "texture_output::fs_program_gray");

    if(!_fs_program_gray) {
        throw (std::runtime_error("texture_output::texture_output(): error generating _fs_program_gray program"));
    }
    _fs_program_gray->uniform_sampler("in_texture", 0);
    _fs_program_gray->uniform("mvp", pass_mvp);

    _fs_program_gray_uint = device->create_program(list_of(device->create_shader(scm::gl::STAGE_VERTEX_SHADER,   fs_vsrc,           "texture_output::fs_vsrc"))
                                                          (device->create_shader(scm::gl::STAGE_FRAGMENT_SHADER, fs_gray_uint_fsrc, "texture_output::fs_gray_uint_fsrc")),
                                               "texture_output::fs_program_gray_uint");

    if(!_fs_program_gray_uint) {
        throw (std::runtime_error("texture_output::texture_output(): error generating _fs_program_gray_uint program"));
    }
    _fs_program_gray_uint->uniform_sampler("in_texture", 0);
    _fs_program_gray_uint->uniform("mvp", pass_mvp);

    _fs_program_gray_uint8_bit_rev = device->create_program(list_of(device->create_shader(scm::gl::STAGE_VERTEX_SHADER,   fs_vsrc,                    "texture_output::fs_vsrc"))
                                                                   (device->create_shader(scm::gl::STAGE_FRAGMENT_SHADER, fs_gray_uint8_bit_rev_fsrc, "texture_output::fs_gray_uint8_bit_rev_fsrc")),
                                               "texture_output::fs_program_gray_uint8_bit_rev");

    if(!_fs_program_gray_uint8_bit_rev) {
        throw (std::runtime_error("texture_output::texture_output(): error generating _fs_program_gray_uint8_bit_rev program"));
    }
    _fs_program_gray_uint8_bit_rev->uniform_sampler("in_texture", 0);
    _fs_program_gray_uint8_bit_rev->uniform("mvp", pass_mvp);
    _fs_program_gray_uint8_bit_rev->uniform("in_scale", vec4f(1.0f / 255.0f));

    _filter_nearest    = device->create_sampler_state(FILTER_MIN_MAG_NEAREST, WRAP_CLAMP_TO_EDGE);
    _dstate_no_z_write = device->create_depth_stencil_state(false, false);
    _rstate_cull_back  = device->create_rasterizer_state(FILL_SOLID, CULL_BACK);
    _bstate_no_blend   = device->create_blend_state(false, FUNC_ONE, FUNC_ZERO, FUNC_ONE, FUNC_ZERO);
}
height_field_tessellator::height_field_tessellator(const gl::render_device_ptr& device)
    : _pixel_tolerance(4.0f)
{
    using namespace scm;
    using namespace scm::gl;
    using namespace scm::math;
    using boost::assign::list_of;

    // state objects //////////////////////////////////////////////////////////////////////////////
    _bstate_no_blend     = device->create_blend_state(false, FUNC_ONE, FUNC_ZERO, FUNC_ONE, FUNC_ZERO);
    _bstate_omsa         = device->create_blend_state(true, FUNC_SRC_ALPHA, FUNC_ONE_MINUS_SRC_ALPHA, FUNC_ONE, FUNC_ZERO);
    _dstate_less         = device->create_depth_stencil_state(true, true, COMPARISON_LESS);

    _rstate_ms_wire      = device->create_rasterizer_state(FILL_WIREFRAME, CULL_NONE, ORIENT_CCW, true);
    _rstate_ms_solid     = device->create_rasterizer_state(FILL_SOLID, CULL_NONE, ORIENT_CCW, true);
    _rstate_ms_solid_ss  = device->create_rasterizer_state(FILL_SOLID, CULL_NONE, ORIENT_CCW, true, true, 1.0f);
    //_rstate_ms_wire      = device->create_rasterizer_state(FILL_WIREFRAME, CULL_BACK, ORIENT_CCW, true);
    //_rstate_ms_solid     = device->create_rasterizer_state(FILL_SOLID, CULL_BACK, ORIENT_CCW, true);

    _sstate_nearest      = device->create_sampler_state(FILTER_MIN_MAG_NEAREST, WRAP_CLAMP_TO_EDGE);
    _sstate_linear       = device->create_sampler_state(FILTER_MIN_MAG_LINEAR, WRAP_CLAMP_TO_EDGE);
    _sstate_linear_mip   = device->create_sampler_state(FILTER_MIN_MAG_MIP_LINEAR, WRAP_CLAMP_TO_EDGE);

    if (   !_bstate_no_blend
            || !_bstate_omsa
            || !_dstate_less
            || !_rstate_ms_wire
            || !_rstate_ms_solid
            || !_sstate_nearest
            || !_sstate_linear
            || !_sstate_linear_mip) {
        throw (std::runtime_error("height_field_tessellator::height_field_tessellator(): error creating state objects"));
    }

    gl::camera_uniform_block::add_block_include_string(device);
    device->add_include_files("./../../../src/renderers/shaders", "/scm/data");

    // ray casting program ////////////////////////////////////////////////////////////////////////
    _hf_quad_tessellation_program = device->create_program(
                                        list_of(device->create_shader_from_file(STAGE_VERTEX_SHADER,          "../../../src/renderers/shaders/height_field/tessellate.glslv"))
                                        (device->create_shader_from_file(STAGE_TESS_CONTROL_SHADER,    "../../../src/renderers/shaders/height_field/tessellate_quad.glsltc"))
                                        (device->create_shader_from_file(STAGE_TESS_EVALUATION_SHADER, "../../../src/renderers/shaders/height_field/tessellate_quad.glslte"))
                                        (device->create_shader_from_file(STAGE_GEOMETRY_SHADER,        "../../../src/renderers/shaders/height_field/tessellate.glslg"))
                                        (device->create_shader_from_file(STAGE_FRAGMENT_SHADER,        "../../../src/renderers/shaders/height_field/tessellate.glslf")),
                                        "height_field_tessellator::hf_quad_tessellation_program");
    _hf_triangle_tessellation_program = device->create_program(
                                            list_of(device->create_shader_from_file(STAGE_VERTEX_SHADER,          "../../../src/renderers/shaders/height_field/tessellate.glslv"))
                                            (device->create_shader_from_file(STAGE_TESS_CONTROL_SHADER,    "../../../src/renderers/shaders/height_field/tessellate_tri.glsltc", shader_macro("PRIMITIVE_ID_REPRO", "0")))
                                            (device->create_shader_from_file(STAGE_TESS_EVALUATION_SHADER, "../../../src/renderers/shaders/height_field/tessellate_tri.glslte"))
                                            (device->create_shader_from_file(STAGE_GEOMETRY_SHADER,        "../../../src/renderers/shaders/height_field/tessellate.glslg"))
                                            (device->create_shader_from_file(STAGE_FRAGMENT_SHADER,        "../../../src/renderers/shaders/height_field/tessellate.glslf")),
                                            //separate_stream_capture("per_vertex.vertex.ws_position"),
                                            //interleaved_stream_capture("per_vertex.vertex.ws_position")("per_vertex.vertex.texcoord_hm"),
                                            //interleaved_stream_capture("per_vertex.vertex.ws_position")("per_vertex.vertex.texcoord_hm")(stream_capture::skip_4_float), // GL4+ only
                                            //stream_capture_array("per_vertex.vertex.ws_position")
                                            //stream_capture_array("per_vertex.vertex.ws_position")("per_vertex.vertex.texcoord_hm")("per_vertex.vertex.texcoord_dm"),
                                            //stream_capture_array(interleaved_stream_capture("per_vertex.vertex.ws_position")("per_vertex.vertex.texcoord_hm"))
                                            //                    (separate_stream_capture("per_vertex.vertex.texcoord_dm")),
                                            //stream_capture_array(interleaved_stream_capture("per_vertex.vertex.ws_position")("per_vertex.vertex.texcoord_hm")(stream_capture::skip_4_float))
                                            //                    (separate_stream_capture("per_vertex.vertex.texcoord_dm")),
                                            "height_field_tessellator::hf_triangle_tessellation_program");

    if (   !_hf_quad_tessellation_program
            || !_hf_triangle_tessellation_program) {
        throw (std::runtime_error("height_field_ray_caster::height_field_ray_caster(): error creating quad or triangle program"));
    }

    // set default uniforms
    _hf_quad_tessellation_program->uniform_buffer("camera_matrices", 0);
    _hf_quad_tessellation_program->uniform_sampler("height_map",          0);
    _hf_quad_tessellation_program->uniform_sampler("height_map_nearest",  1);
    _hf_quad_tessellation_program->uniform_sampler("density_map",         2);
    _hf_quad_tessellation_program->uniform_sampler("color_map",           3);

    // set default uniforms
    _hf_triangle_tessellation_program->uniform_buffer("camera_matrices", 0);
    _hf_triangle_tessellation_program->uniform_sampler("height_map",         0);
    _hf_triangle_tessellation_program->uniform_sampler("height_map_nearest", 1);
    _hf_triangle_tessellation_program->uniform_sampler("density_map",        2);
    _hf_triangle_tessellation_program->uniform_sampler("color_map",          3);
    _hf_triangle_tessellation_program->uniform_sampler("edge_densities",     4);

    _main_camera_block.reset(new gl::camera_uniform_block(device));
}