smoot ltr animation? kinda

This commit is contained in:
Mylloon 2023-05-21 20:32:08 +02:00
parent e94c476437
commit f8f62312f9
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 27 additions and 9 deletions

View file

@ -8,8 +8,13 @@ in vec2 vsoTexCoord;
out vec4 fragColor;
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform mat4 viewMatrix;
uniform vec4 lumPos;
uniform float fadeAmount;
const float fadeStart = 0;
const float fadeEnd = 1;
void main(void) {
const vec3 Vu = vec3(0, 0, -1);
@ -19,5 +24,10 @@ void main(void) {
float ispec = pow(clamp(dot(-Vu, reflexion), 0., 1.), 20);
float phongIL = clamp(dot(-Ld, vsoNormal), 0., 1.);
fragColor = phongIL * texture(tex0, vsoTexCoord) + ispec * vec4(1);
vec4 color1 = texture(tex0, vsoTexCoord);
vec4 color2 = texture(tex1, vsoTexCoord);
float fadeFactor = smoothstep(fadeStart, fadeEnd, 1 - vsoTexCoord.x);
fragColor = phongIL * mix(color1, color2, fadeFactor * fadeAmount) + ispec * vec4(1);
}

View file

@ -2,7 +2,7 @@
static GLuint _pId = 0;
static GLuint _murId = 0;
static GLuint _texId = 0;
static GLuint _texId[2] = {0};
static const char *matrix_proj = "proj";
static const char *matrix_model = "model";
@ -35,14 +35,15 @@ static void init(void) {
_murId = gl4dgGenGrid2df(100, 100);
_pId = gl4duCreateProgram("<vs>shaders/tag.vs", "<fs>shaders/tag.fs", NULL);
glGenTextures(1, &_texId);
load_img("images/wall.png", _texId);
glGenTextures(2, _texId);
load_img("images/wall.png", _texId[0]);
load_img("images/wall.png", _texId[1]);
TTF_Font *font = NULL;
if (initFont(&font, "fonts/Instrument.ttf", 100)) {
exit(3);
}
if (writeText(&_texId, font, "macron = loser", (SDL_Color){0, 0, 0, 255},
if (writeText(&_texId[1], font, "macron = loser", (SDL_Color){0, 0, 0, 255},
GL_TRUE)) {
exit(3);
}
@ -86,10 +87,17 @@ static void draw(void) {
gl4duSendMatrices();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _texId);
glBindTexture(GL_TEXTURE_2D, _texId[0]);
glUniform1f(glGetUniformLocation(_pId, "phase"), 0);
glUniform4fv(glGetUniformLocation(_pId, "lumPos"), 1, lum_pos);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, _texId[1]);
GLfloat fade_amout = (GLfloat)t0 / 7000.f;
glUniform1f(glGetUniformLocation(_pId, "fadeAmount"), fade_amout);
glUniform1i(glGetUniformLocation(_pId, "tex0"), 0);
glUniform1i(glGetUniformLocation(_pId, "tex1"), 1);
gl4dgDraw(_murId);
glUseProgram(0);
@ -97,8 +105,8 @@ static void draw(void) {
}
static void deinit(void) {
if (_texId) {
glDeleteTextures(1, &_texId);
_texId = 0;
if (_texId[0]) {
glDeleteTextures(sizeof(_texId) / sizeof(*_texId), _texId);
_texId[0] = 0;
}
}