pp sillyness
parent
fa2b314453
commit
eb761557f0
|
@ -1,6 +1,6 @@
|
|||
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)
|
||||
|
||||
project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION})
|
||||
|
|
|
@ -149,8 +149,7 @@ namespace blt::gfx
|
|||
class batch_renderer_2d
|
||||
{
|
||||
private:
|
||||
std::unique_ptr<pp_engine_t> engine = pp_engine_t::make_multi_pp(std::make_unique<pp_outline_target>(),
|
||||
std::make_unique<pp_outline_step_t>());
|
||||
std::unique_ptr<pp_engine_t> engine;
|
||||
|
||||
template<typename T>
|
||||
struct render_object_t
|
||||
|
@ -210,8 +209,11 @@ namespace blt::gfx
|
|||
}
|
||||
|
||||
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();
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <blt/gfx/framebuffer.h>
|
||||
#include <blt/gfx/shader.h>
|
||||
#include <blt/gfx/model.h>
|
||||
#include <blt/gfx/state.h>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
|
@ -95,10 +96,15 @@ namespace blt::gfx
|
|||
class pp_outline_step_t : public pp_step_t
|
||||
{
|
||||
public:
|
||||
pp_outline_step_t(matrix_state_manager& manager): manager(manager)
|
||||
{}
|
||||
|
||||
void create() override;
|
||||
|
||||
void draw(pp_step_t& previous) override;
|
||||
|
||||
private:
|
||||
matrix_state_manager& manager;
|
||||
};
|
||||
|
||||
class pp_engine_t
|
||||
|
|
|
@ -5,7 +5,7 @@ const std::string shader_2d_textured_frag = R"("
|
|||
precision mediump float;
|
||||
|
||||
layout (location = 0) out vec4 FragColor;
|
||||
layout (location = 1) out vec4 Mask;
|
||||
layout (location = 1) out vec4 OutMask;
|
||||
in vec2 uv;
|
||||
in vec2 pos;
|
||||
|
||||
|
@ -20,8 +20,8 @@ vec4 linear_iter(vec4 i, vec4 p, float factor){
|
|||
|
||||
void main() {
|
||||
FragColor = (texture(tex, uv) * use_texture) + color;
|
||||
Mask = outline_color;
|
||||
//Mask.a = FragColor.a;
|
||||
OutMask = outline_color;
|
||||
OutMask.a = FragColor.a;
|
||||
}
|
||||
|
||||
")";
|
||||
|
|
|
@ -5,7 +5,7 @@ const std::string shader_2d_textured_cirlce_frag = R"("
|
|||
precision mediump float;
|
||||
|
||||
layout (location = 0) out vec4 FragColor;
|
||||
layout (location = 1) out vec4 Mask;
|
||||
layout (location = 1) out vec4 OutMask;
|
||||
in vec2 uv;
|
||||
in vec2 pos;
|
||||
|
||||
|
@ -28,8 +28,8 @@ void main() {
|
|||
if (ts >= sq)
|
||||
discard;
|
||||
FragColor = (texture(tex, uv) * use_texture) + color;
|
||||
Mask = outline_color;
|
||||
//Mask.a = FragColor.a;
|
||||
OutMask = outline_color;
|
||||
OutMask.a = FragColor.a;
|
||||
}
|
||||
|
||||
")";
|
||||
|
|
|
@ -13,6 +13,12 @@ uniform vec2 viewportSize;
|
|||
uniform sampler2D albedo;
|
||||
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
|
||||
|
||||
void main() {
|
||||
|
@ -24,16 +30,16 @@ void main() {
|
|||
vec2 uvTop = vec2(uvCenter.x, uvCenter.y - dx);
|
||||
vec2 uvTopRight = vec2(uvCenter.x + dx, uvCenter.y - dx);
|
||||
|
||||
float mCenter = texture(mask, uvCenter).r;
|
||||
float mTop = texture(mask, uvTop).r;
|
||||
float mRight = texture(mask, uvRight).r;
|
||||
float mTopRight = texture(mask, uvTopRight).r;
|
||||
float mCenter = longest(texture(mask, uvCenter).rgb);
|
||||
float mTop = longest(texture(mask, uvTop).rgb);
|
||||
float mRight = longest(texture(mask, uvRight).rgb);
|
||||
float mTopRight = longest(texture(mask, uvTopRight).rgb);
|
||||
|
||||
float dT = abs(mCenter - mTop);
|
||||
float dR = abs(mCenter - mRight);
|
||||
float dTR = abs(mCenter - mTopRight);
|
||||
|
||||
float delta = 0.0;
|
||||
float delta = 0.0f;
|
||||
delta = max(delta, dT);
|
||||
delta = max(delta, dR);
|
||||
delta = max(delta, dTR);
|
||||
|
@ -41,7 +47,10 @@ void main() {
|
|||
vec4 outline = vec4(delta, delta, delta, 1.0);
|
||||
vec4 albedo = texture(albedo, uv);
|
||||
|
||||
FragColor = albedo - outline;
|
||||
if (delta <= 0.001)
|
||||
FragColor = albedo;
|
||||
else
|
||||
FragColor = outline_color;
|
||||
}
|
||||
|
||||
")";
|
||||
|
|
|
@ -184,6 +184,8 @@ namespace blt::gfx
|
|||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
engine->bind();
|
||||
const GLenum buffers[]{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
|
||||
glDrawBuffers(2, buffers);
|
||||
draw_objects();
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
|
|
@ -156,8 +156,6 @@ namespace blt::gfx
|
|||
void pp_outline_target::draw()
|
||||
{
|
||||
draw_buffer.updateBuffersStorage(getWindowWidth(), getWindowHeight());
|
||||
glEnable(GL_TEXTURE0);
|
||||
glEnable(GL_TEXTURE1);
|
||||
}
|
||||
|
||||
void pp_outline_step_t::create()
|
||||
|
@ -176,6 +174,7 @@ namespace blt::gfx
|
|||
glActiveTexture(GL_TEXTURE1);
|
||||
previous.getBuffer().getTexture(frame_buffer_t::attachment_t::COLOR1).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()));
|
||||
}
|
||||
}
|
|
@ -168,6 +168,7 @@ namespace blt::gfx
|
|||
BLT_ERROR("I have an log of %d length", log_length);
|
||||
BLT_ERROR(infoLog.data());
|
||||
BLT_ERROR("--- --- --- --- --- --- --- --- ---");
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
glValidateProgram(programID);
|
||||
|
|
Loading…
Reference in New Issue