[remove] Removed a glitch effect of TextProgram.
This commit is contained in:
parent
7af750c131
commit
6f7dd2c142
@ -228,15 +228,6 @@ private class SongAppearState : AbstractSceneState {
|
|||||||
override UpdateResult Update(KeyInput input) {
|
override UpdateResult Update(KeyInput input) {
|
||||||
const ratio = anime_.Update();
|
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_) {
|
with (owner.lobby_) {
|
||||||
cube_matrix.rotation += cube_rota_speed_ease_.Calculate(ratio);
|
cube_matrix.rotation += cube_rota_speed_ease_.Calculate(ratio);
|
||||||
cube_interval = cube_interval_ease_.Calculate(ratio);
|
cube_interval = cube_interval_ease_.Calculate(ratio);
|
||||||
@ -282,30 +273,11 @@ private class SongWaitState : AbstractSceneState {
|
|||||||
matrix.scale = TitleTextScale;
|
matrix.scale = TitleTextScale;
|
||||||
matrix.translation =
|
matrix.translation =
|
||||||
TitleTextTranslation + vec3(-modelWidth/2*matrix.scale.x, 0, 0);
|
TitleTextTranslation + vec3(-modelWidth/2*matrix.scale.x, 0, 0);
|
||||||
frame = 0;
|
|
||||||
}
|
}
|
||||||
frame_ = 0;
|
|
||||||
}
|
}
|
||||||
override UpdateResult Update(KeyInput input) {
|
override UpdateResult Update(KeyInput input) {
|
||||||
owner.lobby_.cube_matrix.rotation += CubeRotationSpeed;
|
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) {
|
if (input.up) {
|
||||||
song.StopPlaying();
|
song.StopPlaying();
|
||||||
owner.title_scene_.Initialize();
|
owner.title_scene_.Initialize();
|
||||||
@ -322,7 +294,6 @@ private class SongWaitState : AbstractSceneState {
|
|||||||
return CreateResult(song_appear_state_);
|
return CreateResult(song_appear_state_);
|
||||||
}
|
}
|
||||||
|
|
||||||
++frame_;
|
|
||||||
return CreateResult(this);
|
return CreateResult(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,6 +305,4 @@ private class SongWaitState : AbstractSceneState {
|
|||||||
SongAppearState song_appear_state_;
|
SongAppearState song_appear_state_;
|
||||||
|
|
||||||
size_t song_index_;
|
size_t song_index_;
|
||||||
|
|
||||||
int frame_;
|
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ class Text {
|
|||||||
|
|
||||||
model_width_ = 0;
|
model_width_ = 0;
|
||||||
int bmp_width;
|
int bmp_width;
|
||||||
|
size_t glyph_count;
|
||||||
foreach (c; text) {
|
foreach (c; text) {
|
||||||
if (c == ' ') continue;
|
if (c == ' ') continue;
|
||||||
|
|
||||||
@ -98,6 +99,7 @@ class Text {
|
|||||||
|
|
||||||
bmp_width += srcsz.x;
|
bmp_width += srcsz.x;
|
||||||
model_width_ += advance;
|
model_width_ += advance;
|
||||||
|
++glyph_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
texture_.Bind();
|
texture_.Bind();
|
||||||
@ -115,7 +117,7 @@ class Text {
|
|||||||
indices_.Bind();
|
indices_.Bind();
|
||||||
ElementArrayBufferAllocator indices_allcator;
|
ElementArrayBufferAllocator indices_allcator;
|
||||||
with (indices_allcator) {
|
with (indices_allcator) {
|
||||||
size = text.length * 6 * ushort.sizeof;
|
size = glyph_count * 6 * ushort.sizeof;
|
||||||
usage = GL_STATIC_DRAW;
|
usage = GL_STATIC_DRAW;
|
||||||
Allocate(indices_);
|
Allocate(indices_);
|
||||||
}
|
}
|
||||||
@ -123,7 +125,7 @@ class Text {
|
|||||||
auto indices_ptr = indices_data.entity;
|
auto indices_ptr = indices_data.entity;
|
||||||
|
|
||||||
ushort vertex_count;
|
ushort vertex_count;
|
||||||
foreach (i; 0..text.length) {
|
foreach (i; 0..glyph_count) {
|
||||||
*indices_ptr++ = vertex_count;
|
*indices_ptr++ = vertex_count;
|
||||||
*indices_ptr++ = vertex_count++;
|
*indices_ptr++ = vertex_count++;
|
||||||
|
|
||||||
@ -147,8 +149,7 @@ class Text {
|
|||||||
void Draw(mat4 proj, mat4 view) {
|
void Draw(mat4 proj, mat4 view) {
|
||||||
if (index_count_ == 0) return;
|
if (index_count_ == 0) return;
|
||||||
|
|
||||||
program_.Use(proj, view,
|
program_.Use(proj, view, matrix.Create(), texture_, color);
|
||||||
matrix.Create(), texture_, color, frame, model_width_);
|
|
||||||
|
|
||||||
vao_.Bind();
|
vao_.Bind();
|
||||||
indices_.Bind();
|
indices_.Bind();
|
||||||
@ -164,8 +165,6 @@ class Text {
|
|||||||
ModelMatrixFactory!4 matrix;
|
ModelMatrixFactory!4 matrix;
|
||||||
///
|
///
|
||||||
vec4 color = vec4(0, 0, 0, 1);
|
vec4 color = vec4(0, 0, 0, 1);
|
||||||
///
|
|
||||||
int frame;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void CopyRawPixels(in ubyte* src, vec2i srcsz, ubyte* dst, vec2i dstsz, vec2i offset) {
|
static void CopyRawPixels(in ubyte* src, vec2i srcsz, ubyte* dst, vec2i dstsz, vec2i offset) {
|
||||||
|
@ -28,11 +28,9 @@ class TextProgram {
|
|||||||
layout(location = 0) in vec3 vert;
|
layout(location = 0) in vec3 vert;
|
||||||
layout(location = 1) in vec2 uv;
|
layout(location = 1) in vec2 uv;
|
||||||
|
|
||||||
out vec3 vert_;
|
|
||||||
out vec2 uv_;
|
out vec2 uv_;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vert_ = vert;
|
|
||||||
uv_ = uv;
|
uv_ = uv;
|
||||||
gl_Position = P * V * M * vec4(vert, 1);
|
gl_Position = P * V * M * vec4(vert, 1);
|
||||||
}
|
}
|
||||||
@ -41,46 +39,14 @@ class TextProgram {
|
|||||||
enum FragmentShaderSrc = ShaderHeader ~ q{
|
enum FragmentShaderSrc = ShaderHeader ~ q{
|
||||||
layout(location = 3) uniform sampler2D tex;
|
layout(location = 3) uniform sampler2D tex;
|
||||||
layout(location = 4) uniform vec4 color;
|
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_;
|
in vec2 uv_;
|
||||||
|
|
||||||
out vec4 pixel_;
|
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() {
|
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_ = 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,
|
void Use(mat4 proj, mat4 view, mat4 model, ref Texture2DRef tex, vec4 color) {
|
||||||
ref Texture2DRef tex, vec4 color, int frame, float model_width) {
|
|
||||||
tex.BindToUnit(GL_TEXTURE0);
|
tex.BindToUnit(GL_TEXTURE0);
|
||||||
sampler_.Bind(0);
|
sampler_.Bind(0);
|
||||||
|
|
||||||
@ -134,8 +99,6 @@ class TextProgram {
|
|||||||
program_.uniform!2 = model;
|
program_.uniform!2 = model;
|
||||||
program_.uniform!3 = 0;
|
program_.uniform!3 = 0;
|
||||||
program_.uniform!4 = color;
|
program_.uniform!4 = color;
|
||||||
program_.uniform!5 = frame;
|
|
||||||
program_.uniform!6 = model_width;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user