highligher
parent
a6853e6ff7
commit
922de9d242
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 3.25)
|
||||
|
||||
set(BLT_GRAPHICS_VERSION 0.13.11)
|
||||
set(BLT_GRAPHICS_VERSION 0.13.12)
|
||||
set(BLT_GRAPHICS_TEST_VERSION 0.0.1)
|
||||
|
||||
project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION})
|
||||
|
|
|
@ -213,10 +213,11 @@ namespace blt::gfx
|
|||
explicit batch_renderer_2d(resource_manager& resources, matrix_state_manager& state): resources(resources), state(state)
|
||||
{
|
||||
engine = pp_engine_t::make_multi_pp(std::make_unique<pp_outline_target_t>(),
|
||||
std::make_unique<pp_blur_step_inplace_t>(state, frame_buffer_t::attachment_t::COLOR1),
|
||||
std::make_unique<pp_expansion_step_inplace_t>(frame_buffer_t::attachment_t::COLOR1,
|
||||
vec4{4, 4, 4, 1}),
|
||||
std::make_unique<pp_overlay_blur_step_t>(frame_buffer_t::attachment_t::COLOR1, 2, 2),
|
||||
std::make_unique<pp_mouse_highlight_step_t>(frame_buffer_t::attachment_t::COLOR1),
|
||||
//std::make_unique<pp_blur_step_inplace_t>(state, frame_buffer_t::attachment_t::COLOR1),
|
||||
//std::make_unique<pp_multiplier_step_inplace_t>(frame_buffer_t::attachment_t::COLOR1,
|
||||
// vec4{4, 4, 4, 1}),
|
||||
//std::make_unique<pp_overlay_blur_step_t>(frame_buffer_t::attachment_t::COLOR1, 2, 2),
|
||||
std::make_unique<pp_outline_step_t>(state)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -165,7 +165,7 @@ namespace blt::gfx
|
|||
|
||||
void create() override;
|
||||
|
||||
void draw(frame_buffer_t& previous);
|
||||
void draw(frame_buffer_t& previous) override;
|
||||
|
||||
private:
|
||||
matrix_state_manager& manager;
|
||||
|
@ -187,33 +187,43 @@ namespace blt::gfx
|
|||
|
||||
void create() override;
|
||||
|
||||
void draw(frame_buffer_t& previous);
|
||||
void draw(frame_buffer_t& previous) override;
|
||||
|
||||
private:
|
||||
i32 x_blur;
|
||||
i32 y_blur;
|
||||
};
|
||||
|
||||
class pp_expansion_step_inplace_t : public pp_in_place_t
|
||||
class pp_multiplier_step_inplace_t : public pp_in_place_t
|
||||
{
|
||||
public:
|
||||
pp_expansion_step_inplace_t(frame_buffer_t::attachment_t from, const vec4& multiplier = vec4{2, 2, 2, 2}):
|
||||
pp_multiplier_step_inplace_t(frame_buffer_t::attachment_t from, const vec4& multiplier = vec4{2, 2, 2, 2}):
|
||||
pp_in_place_t(from), multiplier(multiplier)
|
||||
{}
|
||||
|
||||
pp_expansion_step_inplace_t(frame_buffer_t::attachment_t from, frame_buffer_t::attachment_t to,
|
||||
pp_multiplier_step_inplace_t(frame_buffer_t::attachment_t from, frame_buffer_t::attachment_t to,
|
||||
const vec4& multiplier = vec4{2, 2, 2, 2}):
|
||||
pp_in_place_t(from, to), multiplier(multiplier)
|
||||
{}
|
||||
|
||||
void create() override;
|
||||
|
||||
void draw(frame_buffer_t& previous);
|
||||
void draw(frame_buffer_t& previous) override;
|
||||
|
||||
private:
|
||||
vec4 multiplier;
|
||||
};
|
||||
|
||||
class pp_mouse_highlight_step_t : public pp_in_place_t
|
||||
{
|
||||
public:
|
||||
using pp_in_place_t::pp_in_place_t;
|
||||
|
||||
void create() override;
|
||||
|
||||
void draw(frame_buffer_t& previous) override;
|
||||
};
|
||||
|
||||
class pp_engine_t
|
||||
{
|
||||
public:
|
||||
|
@ -230,7 +240,8 @@ namespace blt::gfx
|
|||
steps.emplace_back(std::move(step));
|
||||
}
|
||||
|
||||
static std::unique_ptr<shader_t> createShader(std::string_view fragment, std::optional<std::reference_wrapper<template_engine_t>> engine = {});
|
||||
static std::unique_ptr<shader_t> createShader(std::string_view fragment,
|
||||
std::optional<std::reference_wrapper<template_engine_t>> engine = {});
|
||||
|
||||
static std::unique_ptr<pp_engine_t> make_basic_pp()
|
||||
{
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
#ifdef __cplusplus
|
||||
#include <string>
|
||||
const std::string shader_highlight_frag = R"("
|
||||
#version 300 es
|
||||
precision mediump float;
|
||||
|
||||
out vec4 FragColor;
|
||||
in vec2 uv;
|
||||
in vec2 pos;
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform ivec4 size;
|
||||
uniform vec4 mousePos;
|
||||
|
||||
void main() {
|
||||
vec2 texelSize = 1.0 / vec2(float(size.x), float(size.y));
|
||||
vec4 result = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for (int x = -size.z; x <= size.z; ++x) {
|
||||
for (int y = -size.w; y <= size.w; ++y) {
|
||||
vec2 offset = (vec2(float(x), float(y)) * texelSize);
|
||||
result += texture(tex, uv + offset);
|
||||
}
|
||||
}
|
||||
|
||||
float px = mousePos.x / float(size.x);
|
||||
float py = mousePos.y / float(size.y);
|
||||
|
||||
float dx = (gl_FragCoord.x - mousePos.x) / float(size.x);
|
||||
float dy = (gl_FragCoord.y - mousePos.y) / float(size.y);
|
||||
|
||||
float distx = sqrt(dx * dx);
|
||||
float disty = sqrt(dy * dy);
|
||||
|
||||
vec4 n_color = result / vec4((float(size.z) * 2.0 + 1.0) * (float(size.w) * 2.0 + 1.0));
|
||||
|
||||
FragColor = vec4(distx, disty, 0.0, 1.0);
|
||||
|
||||
//FragColor = ;
|
||||
}
|
||||
|
||||
")";
|
||||
#endif
|
|
@ -1 +1 @@
|
|||
Subproject commit f228cfbbe31538731a2ef1bd990d41c99562c4d3
|
||||
Subproject commit 9c0fc819690a99cbf8cdf923f1aeda22ff57ae9b
|
|
@ -1 +1 @@
|
|||
Subproject commit 231cbee0fc4f59dbe5b8b853a11b08dc84e57c65
|
||||
Subproject commit a1b06823fe2d964a62fda99385499b218cf5cea5
|
|
@ -1 +1 @@
|
|||
Subproject commit 111397c71a5f1c2c88e05da9c84edfdba2e472a4
|
||||
Subproject commit 6675317107257c2cc16c947b359d557821d85bf2
|
|
@ -72,8 +72,8 @@ namespace blt::gfx
|
|||
vertices_vbo.create();
|
||||
indices_vbo.create();
|
||||
|
||||
vertices_vbo.allocate(sizeof(line_vertices), line_vertices);
|
||||
indices_vbo.allocate(sizeof(square_indices), square_indices);
|
||||
vertices_vbo.allocate(sizeof(line_vertices), line_vertices, GL_DYNAMIC_DRAW);
|
||||
indices_vbo.allocate(sizeof(square_indices), square_indices, GL_DYNAMIC_DRAW);
|
||||
|
||||
line_vao = new vertex_array_t();
|
||||
auto tb = line_vao->bindVBO(vertices_vbo, 0, 3, GL_FLOAT, 5 * sizeof(float), 0);
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <blt/gfx/renderer/shaders/pp_gaussian_blur.frag>
|
||||
#include <blt/gfx/renderer/shaders/pp_overlay_blur.frag>
|
||||
#include <blt/gfx/renderer/shaders/pp_multiplier.frag>
|
||||
#include <blt/gfx/renderer/shaders/pp_highlight.frag>
|
||||
#include <blt/std/ranges.h>
|
||||
#include <blt/math/log_util.h>
|
||||
|
||||
|
@ -275,13 +276,13 @@ namespace blt::gfx
|
|||
shader->setVec4i("size", {static_cast<i32>(v.x()), static_cast<i32>(v.y()), x_blur, y_blur});
|
||||
}
|
||||
|
||||
void pp_expansion_step_inplace_t::create()
|
||||
void pp_multiplier_step_inplace_t::create()
|
||||
{
|
||||
pp_in_place_t::create();
|
||||
shader = pp_engine_t::createShader(shader_multiplier_frag);
|
||||
}
|
||||
|
||||
void pp_expansion_step_inplace_t::draw(frame_buffer_t& previous)
|
||||
void pp_multiplier_step_inplace_t::draw(frame_buffer_t& previous)
|
||||
{
|
||||
pp_in_place_t::draw(previous);
|
||||
shader->bind();
|
||||
|
@ -301,4 +302,19 @@ namespace blt::gfx
|
|||
auto v = vec2(getWindowWidth(), getWindowHeight());
|
||||
shader->setVec4i("size", {static_cast<i32>(v.x()), static_cast<i32>(v.y()), x_blur, y_blur});
|
||||
}
|
||||
|
||||
void pp_mouse_highlight_step_t::create()
|
||||
{
|
||||
pp_in_place_t::create();
|
||||
shader = pp_engine_t::createShader(shader_highlight_frag);
|
||||
}
|
||||
|
||||
void pp_mouse_highlight_step_t::draw(frame_buffer_t& previous)
|
||||
{
|
||||
pp_in_place_t::draw(previous);
|
||||
shader->bind();
|
||||
auto v = vec2(getWindowWidth(), getWindowHeight());
|
||||
shader->setVec4("mousePos", blt::make_vec4(blt::vec2{getMouseX(), v.y() - getMouseY()}));
|
||||
shader->setVec4i("size", {static_cast<i32>(v.x()), static_cast<i32>(v.y()), 2, 2});
|
||||
}
|
||||
}
|
|
@ -30,7 +30,7 @@ void error_callback(int error, const char* description)
|
|||
void gl_error_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei, const GLchar* message, const void*)
|
||||
{
|
||||
// do not log performance concerns
|
||||
if (type == GL_DEBUG_TYPE_PERFORMANCE || type == GL_DEBUG_TYPE_OTHER)
|
||||
if (type == GL_DEBUG_TYPE_OTHER)
|
||||
return;
|
||||
if (type == GL_DEBUG_TYPE_ERROR)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue