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