Refactor shader code to replace 'u_time' with 'GameTime' and remove unused 'u_bobtime' uniform
This commit is contained in:
parent
939866b7ce
commit
55f5b32b93
@ -2,7 +2,7 @@
|
||||
|
||||
in vec2 TexCoord;
|
||||
flat in int TexIndex;
|
||||
flat in vec3 originalTexCoord;
|
||||
flat in float GameTime;
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform sampler2D Texture0;
|
||||
@ -22,7 +22,6 @@ uniform sampler2D Texture13;
|
||||
uniform sampler2D Texture14;
|
||||
uniform sampler2D Texture15;
|
||||
|
||||
uniform float u_time;
|
||||
uniform float u_battery;
|
||||
uniform vec2 u_resolution;
|
||||
uniform float u_hit_timer;
|
||||
@ -119,9 +118,9 @@ void main()
|
||||
float strength = 1.0 - u_battery;
|
||||
|
||||
vec2 blockUV = floor(gl_FragCoord.xy / blockSize);
|
||||
float noise = hash(blockUV + vec2(u_time * 3.0, u_time * 7.0));
|
||||
float noise2 = hash(blockUV + vec2(u_time * 13.0, u_time * 3.0));
|
||||
float noise3 = hash(blockUV + vec2(u_time * 17.0, u_time * 13.0));
|
||||
float noise = hash(blockUV + vec2(GameTime * 3.0, GameTime * 7.0));
|
||||
float noise2 = hash(blockUV + vec2(GameTime * 13.0, GameTime * 3.0));
|
||||
float noise3 = hash(blockUV + vec2(GameTime * 17.0, GameTime * 13.0));
|
||||
|
||||
// Horizontal bands
|
||||
noise *= 0.9 + 0.1 * sin(uv.y * 400.0);
|
||||
@ -138,7 +137,7 @@ void main()
|
||||
vec3 color = vec3(r, g, b);
|
||||
|
||||
vec3 noisyColor = mix(color.rgb, vec3(noise, noise2, noise3), (strength / 2 + .2));
|
||||
float flicker = (1 - strength * 0.5) + 0.25 * (strength * sin(u_time + sin(u_time * 7.0) + 1));
|
||||
float flicker = (1 - strength * 0.5) + 0.25 * (strength * sin(GameTime + sin(GameTime * 7.0) + 1));
|
||||
|
||||
float dim = u_battery < 0.1 ? u_battery * 10.0 : 1;
|
||||
noiseColor = vec4(noisyColor, texColor.a * flicker * dim);
|
||||
|
||||
@ -6,10 +6,10 @@ layout(location = 2) in int aTexIndex;
|
||||
out vec2 TexCoord;
|
||||
|
||||
flat out int TexIndex;
|
||||
flat out vec3 originalTexCoord;
|
||||
flat out float GameTime;
|
||||
|
||||
uniform mat4 ProjMatrix;
|
||||
uniform float u_bobtime;
|
||||
uniform float u_time;
|
||||
uniform int u_ismoving;
|
||||
|
||||
const float bobbingSpeed = 18.0; // Speed of the bobbing effect
|
||||
@ -18,18 +18,17 @@ const float bobbingIntensity = 0.6; // Intensity of the bobbing effect
|
||||
void main()
|
||||
{
|
||||
vec3 position = aPos;
|
||||
originalTexCoord = aPos;
|
||||
if (u_ismoving == 1 && aTexIndex == 1) {
|
||||
// Calculate bobbing offset based on sine waves
|
||||
float verticalBob = sin(u_bobtime * bobbingSpeed) * bobbingIntensity;
|
||||
float horizontalBob = sin(u_bobtime * bobbingSpeed * 0.5) * bobbingIntensity * 0.3;
|
||||
float verticalBob = sin(u_time * bobbingSpeed) * bobbingIntensity;
|
||||
float horizontalBob = sin(u_time * bobbingSpeed * 0.5) * bobbingIntensity * 0.3;
|
||||
|
||||
// Apply the bobbing offset
|
||||
position.y += verticalBob;
|
||||
position.x += horizontalBob;
|
||||
|
||||
// Optional: Add slight rotation for more realistic head movement
|
||||
float tiltAngle = sin(u_bobtime * bobbingSpeed * 0.7) * bobbingIntensity * 0.02;
|
||||
float tiltAngle = sin(u_time * bobbingSpeed * 0.7) * bobbingIntensity * 0.02;
|
||||
|
||||
// Apply rotation around Z-axis (head tilt)
|
||||
float cosA = cos(tiltAngle);
|
||||
@ -41,6 +40,7 @@ void main()
|
||||
position.x = newX;
|
||||
position.y = newY;
|
||||
}
|
||||
GameTime = u_time;
|
||||
gl_Position = ProjMatrix * vec4(position, 1.0);
|
||||
TexCoord = aTexCoord;
|
||||
TexIndex = aTexIndex;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 15:52:44 by qmennen #+# #+# */
|
||||
/* Updated: 2025/06/11 16:56:03 by qmennen ### ########.fr */
|
||||
/* Updated: 2025/06/11 17:49:35 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -127,7 +127,6 @@ typedef struct s_screen
|
||||
int u_resolution_location;
|
||||
int u_hit_timer_location;
|
||||
int u_enabled_location;
|
||||
int u_bobtime_location;
|
||||
int u_ismoving_location;
|
||||
int flash;
|
||||
} t_screen;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/08 18:27:59 by qmennen #+# #+# */
|
||||
/* Updated: 2025/06/11 17:45:39 by qmennen ### ########.fr */
|
||||
/* Updated: 2025/06/11 17:49:30 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
void set_uniforms(t_game *game)
|
||||
{
|
||||
glUniform1f(game->screen->u_time_location, (float)mlx_get_time());
|
||||
glUniform1f(game->screen->u_bobtime_location, (float)mlx_get_time());
|
||||
glUniform1i(game->screen->u_ismoving_location,
|
||||
game->player->is_moving);
|
||||
glUniform1f(game->screen->u_battery_location, game->player->battery);
|
||||
@ -43,8 +42,6 @@ int load_uniforms(t_game **game)
|
||||
ctx->shaderprogram, "u_enabled");
|
||||
(*game)->screen->u_resolution_location = glGetUniformLocation(
|
||||
ctx->shaderprogram, "u_resolution");
|
||||
(*game)->screen->u_bobtime_location = glGetUniformLocation(
|
||||
ctx->shaderprogram, "u_bobtime");
|
||||
(*game)->screen->u_ismoving_location = glGetUniformLocation(
|
||||
ctx->shaderprogram, "u_ismoving");
|
||||
if ((*game)->screen->u_time_location < 0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user