コード例 #1
0
ファイル: volume_renderer.cpp プロジェクト: idvr/schism
bool
volume_renderer::reload_shaders(const gl::render_device_ptr& device)
{
    using namespace scm;
    using namespace scm::gl;
    using namespace scm::math;
    using boost::assign::list_of;

    scm::out() << log::info
               << "volume_renderer::reload_shaders(): "
               << "reloading shader strings." << log::end;

    // ray casting program ////////////////////////////////////////////////////////////////////////
    shader_macro_array sm;
    sm(shader_macro("SCM_TEXT_NV_BINDLESS_TEXTURES", SCM_TEXT_NV_BINDLESS_TEXTURES == 1 ? "1" : "0"));

    program_ptr prog_rcraw  = device->create_program(list_of(device->create_shader_from_file(STAGE_VERTEX_SHADER,   "../../../src/renderer/shader/volume_ray_cast.glslv"))
                                                            (device->create_shader_from_file(STAGE_FRAGMENT_SHADER, "../../../src/renderer/shader/volume_ray_cast.glslf",
                                                                                             sm)),
                                                     "volume_renderer::program");

    if (!prog_rcraw) {
        scm::err() << log::error
                   << "volume_renderer::reload_shaders(): "
                   << "error loading program" << log::end;
        return false;
    }
    else {
        _program = prog_rcraw;
    }

    _program->uniform("volume_raw",     0);
    _program->uniform("color_map",      2);

    _program->uniform_buffer("camera_matrices",     0);
    _program->uniform_buffer("volume_uniform_data", 1);

    return true;
}
コード例 #2
0
ファイル: volume_renderer.cpp プロジェクト: idvr/schism
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");

}
コード例 #3
0
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));
}
コード例 #4
0
ファイル: texture_output.cpp プロジェクト: 4og/schism
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);
}
コード例 #5
0
ファイル: coordinate_cross.cpp プロジェクト: 4og/schism
coordinate_cross::coordinate_cross(const gl::render_device_ptr& device,
                                   const float                  line_length)
{
    using namespace scm;
    using namespace scm::gl;
    using namespace scm::math;
    using boost::assign::list_of;

    size_t  num_vertices = 6 * 2; // 6 lines, 2 vertices each
    
    _vertices = device->create_buffer(BIND_VERTEX_BUFFER, USAGE_STREAM_DRAW, num_vertices * sizeof(vertex), 0);

    render_context_ptr ctx = device->main_context();
    {
        vertex* data = static_cast<vertex*>(ctx->map_buffer(_vertices, ACCESS_WRITE_INVALIDATE_BUFFER));

        if (data) {
            float l = line_length;
            int v = 0;
            // pos x
            data[v].pos = vec3f( 0.0f, 0.0f, 0.0f); data[v].col = vec3f(1.0f, 0.0f, 0.0f); ++v;
            data[v].pos = vec3f( l,    0.0f, 0.0f); data[v].col = vec3f(1.0f, 0.0f, 0.0f); ++v;
            // neg x
            data[v].pos = vec3f( 0.0f, 0.0f, 0.0f); data[v].col = vec3f(0.3f, 0.0f, 0.0f); ++v;
            data[v].pos = vec3f(-l,    0.0f, 0.0f); data[v].col = vec3f(0.3f, 0.0f, 0.0f); ++v;
            // pos y
            data[v].pos = vec3f(0.0f, 0.0f, 0.0f);  data[v].col = vec3f(0.0f, 1.0f, 0.0f); ++v;
            data[v].pos = vec3f(0.0f, l,    0.0f);  data[v].col = vec3f(0.0f, 1.0f, 0.0f); ++v;
            // neg y
            data[v].pos = vec3f(0.0f,  0.0f, 0.0f); data[v].col = vec3f(0.0f, 0.3f, 0.0f); ++v;
            data[v].pos = vec3f(0.0f, -l,    0.0f); data[v].col = vec3f(0.0f, 0.3f, 0.0f); ++v;
            // pos z
            data[v].pos = vec3f(0.0f, 0.0f, 0.0f);  data[v].col = vec3f(0.0f, 0.0f, 1.0f); ++v;
            data[v].pos = vec3f(0.0f, 0.0f, l);     data[v].col = vec3f(0.0f, 0.0f, 1.0f); ++v;
            // neg z
            data[v].pos = vec3f(0.0f, 0.0f,  0.0f); data[v].col = vec3f(0.0f, 0.0f, 0.3f); ++v;
            data[v].pos = vec3f(0.0f, 0.0f, -l);    data[v].col = vec3f(0.0f, 0.0f, 0.3f); ++v;
        }
        else {
            scm::err() << "coordinate_cross::coordinate_cross(): error mapping vertex buffer for vertex update." << log::end;
            throw (std::runtime_error("coordinate_cross::coordinate_cross(): error mapping vertex buffer for vertex update."));
        }

        ctx->unmap_buffer(_vertices);

        _vertex_count  = 12;
        _prim_topology = PRIMITIVE_LINE_LIST;
    }

    _coord_program = device->create_program(list_of(device->create_shader(STAGE_VERTEX_SHADER, wire_v_source))
                                                   (device->create_shader(STAGE_FRAGMENT_SHADER, wire_f_source)));

    _vertex_array = device->create_vertex_array(vertex_format(0, 0, TYPE_VEC3F, sizeof(vertex))  // vertex positions
                                                             (0, 3, TYPE_VEC3F, sizeof(vertex)), // vertex colors
                                                list_of(_vertices));

    if (   !_coord_program) {
        scm::err() << "coordinate_cross::coordinate_cross(): error creating shader programs." << log::end;
        throw (std::runtime_error("coordinate_cross::coordinate_cross(): error creating shader programs."));
    }

    _no_blend       = device->create_blend_state(false, FUNC_ONE, FUNC_ZERO, FUNC_ONE, FUNC_ZERO);
    _dstate_less    = device->create_depth_stencil_state(true, true, COMPARISON_LESS);
    _dstate_overlay = device->create_depth_stencil_state(false, false, COMPARISON_LESS);
    _raster_no_cull = device->create_rasterizer_state(FILL_SOLID, CULL_NONE, ORIENT_CCW, true);

    if (   !_no_blend
        || !_dstate_less
        || !_raster_no_cull) {
        scm::err() << "coordinate_cross::coordinate_cross(): error creating state objects." << log::end;
        throw (std::runtime_error("coordinate_cross::coordinate_cross(): error creating state objects."));
    }
}