From 87b4d5af07ddd2987d9757473de8d5388164b7de Mon Sep 17 00:00:00 2001 From: falsycat Date: Wed, 16 Oct 2019 00:00:00 +0000 Subject: [PATCH] [update] Implemented a contrast posteffect. --- sjplayer/src/sjplayer/PostEffect.d | 19 +++++++++++++++---- src/sj/Game.d | 2 +- src/sj/TitleScene.d | 19 ++++++++++++++++--- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/sjplayer/src/sjplayer/PostEffect.d b/sjplayer/src/sjplayer/PostEffect.d index 5ece992..58387d2 100644 --- a/sjplayer/src/sjplayer/PostEffect.d +++ b/sjplayer/src/sjplayer/PostEffect.d @@ -12,14 +12,17 @@ class PostEffect { struct Instance { public: /// - align(1) float raster_fineness = 600; + align(4) float raster_fineness = 600; /// - align(1) float raster_width = 0; + align(4) float raster_width = 0; /// - align(1) vec2 clip_lefttop = vec2(0, 0); + align(8) vec2 clip_lefttop = vec2(0, 0); /// - align(1) vec2 clip_rightbottom = vec2(0, 0); + align(8) vec2 clip_rightbottom = vec2(0, 0); + + /// + align(16) vec4 contrast = vec4(1, 1, 1, 1); } /// @@ -125,6 +128,8 @@ class PostEffectProgram { vec2 clip_lefttop; vec2 clip_rightbottom; + + vec4 contrast; } instance; in vec2 uv_; @@ -141,6 +146,12 @@ class PostEffectProgram { vec2 tex_uv = (uv + vec2(1, 1)) / 2; pixel_ = texture(fb, fb_size * tex_uv); + // contrast + pixel_.r = pow(pixel_.r, instance.contrast.r); + pixel_.g = pow(pixel_.g, instance.contrast.g); + pixel_.b = pow(pixel_.b, instance.contrast.b); + pixel_.a = pow(pixel_.a, instance.contrast.a); + // clipping pixel_.a *= step(-1+instance.clip_lefttop.x, uv_.x) * diff --git a/src/sj/Game.d b/src/sj/Game.d index 96f78ec..4923888 100644 --- a/src/sj/Game.d +++ b/src/sj/Game.d @@ -45,7 +45,7 @@ class Game : AbstractGame { lobby_ = new LobbyWorld(programs_); - title_ = new TitleScene(lobby_, programs_); + title_ = new TitleScene(posteffect_, lobby_, programs_); select_ = new SelectScene(lobby_, programs_, fonts_, music_list_); load_ = new LoadingScene(lobby_, posteffect_, programs_, fonts_); play_ = new PlayScene(posteffect_); diff --git a/src/sj/TitleScene.d b/src/sj/TitleScene.d index 2b40f70..7afb135 100644 --- a/src/sj/TitleScene.d +++ b/src/sj/TitleScene.d @@ -6,6 +6,8 @@ import std.conv, import gl4d; +static import sjplayer; + import sj.KeyInput, sj.LobbyWorld, sj.ProgramSet, @@ -34,11 +36,14 @@ class TitleScene : SceneInterface { enum BgOuterColor = vec4(-0.1, -0.1, -0.1, 1); /// enum CubeInterval = 0.005; + /// + enum Contrast = vec4(1.2, 1.2, 1.2, 1); /// - this(LobbyWorld lobby, ProgramSet program) { - lobby_ = lobby; - title_ = program.Get!TitleTextProgram; + this(sjplayer.PostEffect posteffect, LobbyWorld lobby, ProgramSet program) { + posteffect_ = posteffect; + lobby_ = lobby; + title_ = program.Get!TitleTextProgram; } /// @@ -54,6 +59,8 @@ class TitleScene : SceneInterface { bg_outer_ease_ = Easing!vec4(lobby_.background.outer_color, BgOuterColor); cube_interval_ease_ = Easing!float(lobby_.cube_interval, CubeInterval); + + contrast_ease_ = Easing!vec4(posteffect_.contrast, Contrast); } override SceneInterface Update(KeyInput input) { const ratio = anime_.Update(); @@ -65,6 +72,8 @@ class TitleScene : SceneInterface { lobby_.cube_interval = cube_interval_ease_.Calculate(ratio); + posteffect_.contrast = contrast_ease_.Calculate(ratio); + if (anime_.isFinished && input.down) { select_scene_.Initialize(); return select_scene_; @@ -80,6 +89,8 @@ class TitleScene : SceneInterface { private: SelectScene select_scene_; + sjplayer.PostEffect posteffect_; + LobbyWorld lobby_; TitleTextProgram title_; @@ -89,4 +100,6 @@ class TitleScene : SceneInterface { Easing!vec4 bg_inner_ease_; Easing!vec4 bg_outer_ease_; Easing!float cube_interval_ease_; + + Easing!vec4 contrast_ease_; }