From 6f7dd2c142d9276a9d51450890387c6fd8b115ea Mon Sep 17 00:00:00 2001 From: falsycat Date: Sun, 13 Oct 2019 00:00:00 +0000 Subject: [PATCH] [remove] Removed a glitch effect of TextProgram. --- src/sj/SelectScene.d | 31 ------------------------------- src/sj/Text.d | 13 ++++++------- src/sj/TextProgram.d | 41 ++--------------------------------------- 3 files changed, 8 insertions(+), 77 deletions(-) diff --git a/src/sj/SelectScene.d b/src/sj/SelectScene.d index df6ec10..6864b4c 100644 --- a/src/sj/SelectScene.d +++ b/src/sj/SelectScene.d @@ -228,15 +228,6 @@ private class SongAppearState : AbstractSceneState { override UpdateResult Update(KeyInput input) { const ratio = anime_.Update(); - if (owner.text_.frame++%10 > 7) { - alias RT = TitleTextRandomTranslationRange; - owner.text_.matrix.translation += vec3( - uniform(-RT, RT), uniform(-RT, RT), uniform(-RT, RT)); - alias RS = TitleTextRandomScaleRange; - owner.text_.matrix.scale += vec3( - uniform(-RS, RS), uniform(-RS, RS), 0); - } - with (owner.lobby_) { cube_matrix.rotation += cube_rota_speed_ease_.Calculate(ratio); cube_interval = cube_interval_ease_.Calculate(ratio); @@ -282,30 +273,11 @@ private class SongWaitState : AbstractSceneState { matrix.scale = TitleTextScale; matrix.translation = TitleTextTranslation + vec3(-modelWidth/2*matrix.scale.x, 0, 0); - frame = 0; } - frame_ = 0; } override UpdateResult Update(KeyInput input) { owner.lobby_.cube_matrix.rotation += CubeRotationSpeed; - if (frame_%10 == 0) with (owner.text_) { - ++frame; - - if (frame_%100 == 0) { - matrix.scale = TitleTextScale; - matrix.translation = - TitleTextTranslation + vec3(-modelWidth/2*matrix.scale.x, 0, 0); - - } else if (frame_%20 == 0) { - alias RT = TitleTextRandomTranslationRange; - matrix.translation += vec3(uniform(-RT, RT), uniform(-RT, RT), uniform(-RT, RT)); - - alias RS = TitleTextRandomScaleRange; - matrix.scale += vec3(uniform(-RS, RS), uniform(-RS, RS), 0); - } - } - if (input.up) { song.StopPlaying(); owner.title_scene_.Initialize(); @@ -322,7 +294,6 @@ private class SongWaitState : AbstractSceneState { return CreateResult(song_appear_state_); } - ++frame_; return CreateResult(this); } @@ -334,6 +305,4 @@ private class SongWaitState : AbstractSceneState { SongAppearState song_appear_state_; size_t song_index_; - - int frame_; } diff --git a/src/sj/Text.d b/src/sj/Text.d index d9b33f3..2dc6a80 100644 --- a/src/sj/Text.d +++ b/src/sj/Text.d @@ -45,7 +45,8 @@ class Text { gloader.flags = FT_LOAD_DEFAULT | FT_LOAD_RENDER; model_width_ = 0; - int bmp_width; + int bmp_width; + size_t glyph_count; foreach (c; text) { if (c == ' ') continue; @@ -98,6 +99,7 @@ class Text { bmp_width += srcsz.x; model_width_ += advance; + ++glyph_count; } texture_.Bind(); @@ -115,7 +117,7 @@ class Text { indices_.Bind(); ElementArrayBufferAllocator indices_allcator; with (indices_allcator) { - size = text.length * 6 * ushort.sizeof; + size = glyph_count * 6 * ushort.sizeof; usage = GL_STATIC_DRAW; Allocate(indices_); } @@ -123,7 +125,7 @@ class Text { auto indices_ptr = indices_data.entity; ushort vertex_count; - foreach (i; 0..text.length) { + foreach (i; 0..glyph_count) { *indices_ptr++ = vertex_count; *indices_ptr++ = vertex_count++; @@ -147,8 +149,7 @@ class Text { void Draw(mat4 proj, mat4 view) { if (index_count_ == 0) return; - program_.Use(proj, view, - matrix.Create(), texture_, color, frame, model_width_); + program_.Use(proj, view, matrix.Create(), texture_, color); vao_.Bind(); indices_.Bind(); @@ -164,8 +165,6 @@ class Text { ModelMatrixFactory!4 matrix; /// vec4 color = vec4(0, 0, 0, 1); - /// - int frame; private: static void CopyRawPixels(in ubyte* src, vec2i srcsz, ubyte* dst, vec2i dstsz, vec2i offset) { diff --git a/src/sj/TextProgram.d b/src/sj/TextProgram.d index 5fcdc99..486ac55 100644 --- a/src/sj/TextProgram.d +++ b/src/sj/TextProgram.d @@ -28,11 +28,9 @@ class TextProgram { layout(location = 0) in vec3 vert; layout(location = 1) in vec2 uv; - out vec3 vert_; out vec2 uv_; void main() { - vert_ = vert; uv_ = uv; gl_Position = P * V * M * vec4(vert, 1); } @@ -41,46 +39,14 @@ class TextProgram { enum FragmentShaderSrc = ShaderHeader ~ q{ layout(location = 3) uniform sampler2D tex; layout(location = 4) uniform vec4 color; - layout(location = 5) uniform int frame; - layout(location = 6) uniform float model_width; - in vec3 vert_; in vec2 uv_; out vec4 pixel_; - float choose(int a, int b, float a_big, float b_big) { - float condition = step(float(a), float(b)); - return condition * b_big + (1-condition) * a_big; - } - float choose(float a, float b, float c, float hit, float other) { - float condition = step(a, b) * step(b, c); - return condition * hit + (1-condition) * other; - } - void main() { - float vx = vert_.x / model_width; - vec2 uv = uv_; - - uv.y = choose(3, frame%4, uv.y, - choose(0, vx, 0.25, clamp(uv.y, 0, 0.4), uv.y)); - uv.y = choose(15, frame%18, uv.y, - choose(0.1, vx, 0.2, clamp(uv.y, 0.6, 1), uv.y)); - uv.y = choose(8, frame%14, uv.y, - choose(0.1, vx, 0.6, clamp(uv.y, 0, 0.8), uv.y)); - uv.y = choose(21, frame%29, uv.y, - choose(0.2, vx, 0.3, clamp(uv.y, 0.3, 1), uv.y)); - uv.y = choose(20, frame%23, uv.y, - choose(0.4, vx, 0.6, clamp(uv.y, 0.4, 1), uv.y)); - uv.y = choose(5, frame%6, uv.y, - choose(0.5, vx, 0.8, clamp(uv.y, 0, 0.7), uv.y)); - uv.y = choose(15, frame%17, uv.y, - choose(0.6, vx, 0.7, clamp(uv.y, 0.5, 1), uv.y)); - uv.y = choose(7, frame%9, uv.y, - choose(0.6, vx, 0.9, clamp(uv.y, 0.3, 1), uv.y)); - pixel_ = color; - pixel_.a *= texture(tex, uv).r; + pixel_.a *= texture(tex, uv_).r; } }; @@ -123,8 +89,7 @@ class TextProgram { } /// - void Use(mat4 proj, mat4 view, mat4 model, - ref Texture2DRef tex, vec4 color, int frame, float model_width) { + void Use(mat4 proj, mat4 view, mat4 model, ref Texture2DRef tex, vec4 color) { tex.BindToUnit(GL_TEXTURE0); sampler_.Bind(0); @@ -134,8 +99,6 @@ class TextProgram { program_.uniform!2 = model; program_.uniform!3 = 0; program_.uniform!4 = color; - program_.uniform!5 = frame; - program_.uniform!6 = model_width; } private: