[update] Implemented a raster post effect.

This commit is contained in:
falsycat 2019-10-10 00:00:00 +00:00
parent 4cd1f578d2
commit 4ea0041c54
2 changed files with 19 additions and 1 deletions

View File

@ -11,6 +11,11 @@ class PostEffect {
/// ///
struct Instance { struct Instance {
public: public:
///
align(1) float raster_fineness = 0;
///
align(1) float raster_width = 0;
/// ///
align(1) vec2 clip_lefttop = vec2(0, 0); align(1) vec2 clip_lefttop = vec2(0, 0);
/// ///
@ -102,6 +107,9 @@ class PostEffectProgram {
layout(location = 1) uniform ivec2 fb_size; layout(location = 1) uniform ivec2 fb_size;
layout(std140) uniform Instance { layout(std140) uniform Instance {
float raster_fineness;
float raster_width;
vec2 clip_lefttop; vec2 clip_lefttop;
vec2 clip_rightbottom; vec2 clip_rightbottom;
} instance; } instance;
@ -111,9 +119,16 @@ class PostEffectProgram {
out vec4 pixel_; out vec4 pixel_;
void main() { void main() {
vec2 tex_uv = (uv_ + vec2(1, 1)) / 2; vec2 uv = uv_;
// raster
uv.x += sin(uv.y*instance.raster_fineness) * instance.raster_width;
// getting texel
vec2 tex_uv = (uv + vec2(1, 1)) / 2;
pixel_ = texture(fb, fb_size * tex_uv); pixel_ = texture(fb, fb_size * tex_uv);
// clipping
pixel_.a *= pixel_.a *=
step(-1+instance.clip_lefttop.x, uv_.x) * step(-1+instance.clip_lefttop.x, uv_.x) *
(1-step(1-instance.clip_rightbottom.x, uv_.x)) * (1-step(1-instance.clip_rightbottom.x, uv_.x)) *

View File

@ -36,6 +36,9 @@ class PostEffectController : PostEffectScheduledController, PostEffectController
private alias PostEffectScheduledController = ScheduledController!( private alias PostEffectScheduledController = ScheduledController!(
PostEffect, PostEffect,
[ [
"raster_fineness": "raster_fineness",
"raster_width": "raster_width",
"clip_left": "clip_lefttop.x", "clip_left": "clip_lefttop.x",
"clip_top": "clip_lefttop.y", "clip_top": "clip_lefttop.y",
"clip_right": "clip_rightbottom.x", "clip_right": "clip_rightbottom.x",