pp sillyness

main
Brett 2024-05-05 02:29:45 -04:00
parent fa2b314453
commit eb761557f0
9 changed files with 39 additions and 20 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
set(BLT_GRAPHICS_VERSION 0.13.4) set(BLT_GRAPHICS_VERSION 0.13.5)
set(BLT_GRAPHICS_TEST_VERSION 0.0.1) set(BLT_GRAPHICS_TEST_VERSION 0.0.1)
project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION})

View File

@ -149,8 +149,7 @@ namespace blt::gfx
class batch_renderer_2d class batch_renderer_2d
{ {
private: private:
std::unique_ptr<pp_engine_t> engine = pp_engine_t::make_multi_pp(std::make_unique<pp_outline_target>(), std::unique_ptr<pp_engine_t> engine;
std::make_unique<pp_outline_step_t>());
template<typename T> template<typename T>
struct render_object_t struct render_object_t
@ -210,8 +209,11 @@ namespace blt::gfx
} }
public: public:
explicit batch_renderer_2d(resource_manager& resources): resources(resources) explicit batch_renderer_2d(resource_manager& resources, matrix_state_manager& state): resources(resources)
{} {
engine = pp_engine_t::make_multi_pp(std::make_unique<pp_outline_target>(),
std::make_unique<pp_outline_step_t>(state));
}
void create(); void create();

View File

@ -23,6 +23,7 @@
#include <blt/gfx/framebuffer.h> #include <blt/gfx/framebuffer.h>
#include <blt/gfx/shader.h> #include <blt/gfx/shader.h>
#include <blt/gfx/model.h> #include <blt/gfx/model.h>
#include <blt/gfx/state.h>
#include <vector> #include <vector>
#include <memory> #include <memory>
@ -95,10 +96,15 @@ namespace blt::gfx
class pp_outline_step_t : public pp_step_t class pp_outline_step_t : public pp_step_t
{ {
public: public:
pp_outline_step_t(matrix_state_manager& manager): manager(manager)
{}
void create() override; void create() override;
void draw(pp_step_t& previous) override; void draw(pp_step_t& previous) override;
private:
matrix_state_manager& manager;
}; };
class pp_engine_t class pp_engine_t

View File

@ -5,7 +5,7 @@ const std::string shader_2d_textured_frag = R"("
precision mediump float; precision mediump float;
layout (location = 0) out vec4 FragColor; layout (location = 0) out vec4 FragColor;
layout (location = 1) out vec4 Mask; layout (location = 1) out vec4 OutMask;
in vec2 uv; in vec2 uv;
in vec2 pos; in vec2 pos;
@ -20,8 +20,8 @@ vec4 linear_iter(vec4 i, vec4 p, float factor){
void main() { void main() {
FragColor = (texture(tex, uv) * use_texture) + color; FragColor = (texture(tex, uv) * use_texture) + color;
Mask = outline_color; OutMask = outline_color;
//Mask.a = FragColor.a; OutMask.a = FragColor.a;
} }
")"; ")";

View File

@ -5,7 +5,7 @@ const std::string shader_2d_textured_cirlce_frag = R"("
precision mediump float; precision mediump float;
layout (location = 0) out vec4 FragColor; layout (location = 0) out vec4 FragColor;
layout (location = 1) out vec4 Mask; layout (location = 1) out vec4 OutMask;
in vec2 uv; in vec2 uv;
in vec2 pos; in vec2 pos;
@ -28,8 +28,8 @@ void main() {
if (ts >= sq) if (ts >= sq)
discard; discard;
FragColor = (texture(tex, uv) * use_texture) + color; FragColor = (texture(tex, uv) * use_texture) + color;
Mask = outline_color; OutMask = outline_color;
//Mask.a = FragColor.a; OutMask.a = FragColor.a;
} }
")"; ")";

View File

@ -13,6 +13,12 @@ uniform vec2 viewportSize;
uniform sampler2D albedo; uniform sampler2D albedo;
uniform sampler2D mask; uniform sampler2D mask;
vec4 outline_color = vec4(1.0f, 0.0f, 0.0f, 1.0f);
float longest(vec3 v){
return max(v.r, max(v.b, v.g));
}
#define LINE_WEIGHT 3.0 #define LINE_WEIGHT 3.0
void main() { void main() {
@ -24,16 +30,16 @@ void main() {
vec2 uvTop = vec2(uvCenter.x, uvCenter.y - dx); vec2 uvTop = vec2(uvCenter.x, uvCenter.y - dx);
vec2 uvTopRight = vec2(uvCenter.x + dx, uvCenter.y - dx); vec2 uvTopRight = vec2(uvCenter.x + dx, uvCenter.y - dx);
float mCenter = texture(mask, uvCenter).r; float mCenter = longest(texture(mask, uvCenter).rgb);
float mTop = texture(mask, uvTop).r; float mTop = longest(texture(mask, uvTop).rgb);
float mRight = texture(mask, uvRight).r; float mRight = longest(texture(mask, uvRight).rgb);
float mTopRight = texture(mask, uvTopRight).r; float mTopRight = longest(texture(mask, uvTopRight).rgb);
float dT = abs(mCenter - mTop); float dT = abs(mCenter - mTop);
float dR = abs(mCenter - mRight); float dR = abs(mCenter - mRight);
float dTR = abs(mCenter - mTopRight); float dTR = abs(mCenter - mTopRight);
float delta = 0.0; float delta = 0.0f;
delta = max(delta, dT); delta = max(delta, dT);
delta = max(delta, dR); delta = max(delta, dR);
delta = max(delta, dTR); delta = max(delta, dTR);
@ -41,7 +47,10 @@ void main() {
vec4 outline = vec4(delta, delta, delta, 1.0); vec4 outline = vec4(delta, delta, delta, 1.0);
vec4 albedo = texture(albedo, uv); vec4 albedo = texture(albedo, uv);
FragColor = albedo - outline; if (delta <= 0.001)
FragColor = albedo;
else
FragColor = outline_color;
} }
")"; ")";

View File

@ -184,6 +184,8 @@ namespace blt::gfx
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
engine->bind(); engine->bind();
const GLenum buffers[]{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
glDrawBuffers(2, buffers);
draw_objects(); draw_objects();
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);

View File

@ -156,8 +156,6 @@ namespace blt::gfx
void pp_outline_target::draw() void pp_outline_target::draw()
{ {
draw_buffer.updateBuffersStorage(getWindowWidth(), getWindowHeight()); draw_buffer.updateBuffersStorage(getWindowWidth(), getWindowHeight());
glEnable(GL_TEXTURE0);
glEnable(GL_TEXTURE1);
} }
void pp_outline_step_t::create() void pp_outline_step_t::create()
@ -176,6 +174,7 @@ namespace blt::gfx
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
previous.getBuffer().getTexture(frame_buffer_t::attachment_t::COLOR1).bind(); previous.getBuffer().getTexture(frame_buffer_t::attachment_t::COLOR1).bind();
shader->bind(); shader->bind();
shader->setVec2("viewportSize", static_cast<f32>(getWindowWidth()), static_cast<f32>(getWindowHeight())); auto v = manager.getScale2D();
shader->setVec2("viewportSize", static_cast<f32>(getWindowWidth()) * (1.0f/v.x()), static_cast<f32>(getWindowHeight()) * (1.0f / v.y()));
} }
} }

View File

@ -168,6 +168,7 @@ namespace blt::gfx
BLT_ERROR("I have an log of %d length", log_length); BLT_ERROR("I have an log of %d length", log_length);
BLT_ERROR(infoLog.data()); BLT_ERROR(infoLog.data());
BLT_ERROR("--- --- --- --- --- --- --- --- ---"); BLT_ERROR("--- --- --- --- --- --- --- --- ---");
std::exit(0);
} }
glValidateProgram(programID); glValidateProgram(programID);