47 lines
1.4 KiB
GLSL
47 lines
1.4 KiB
GLSL
#version 330 core
|
|
layout(location = 0) in vec3 aPos;
|
|
layout(location = 1) in vec2 aTexCoord;
|
|
layout(location = 2) in int aTexIndex;
|
|
|
|
out vec2 TexCoord;
|
|
|
|
flat out int TexIndex;
|
|
flat out vec3 originalTexCoord;
|
|
|
|
uniform mat4 ProjMatrix;
|
|
uniform float u_bobtime;
|
|
uniform int u_ismoving;
|
|
|
|
const float bobbingSpeed = 18.0; // Speed of the bobbing effect
|
|
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;
|
|
|
|
// 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;
|
|
|
|
// Apply rotation around Z-axis (head tilt)
|
|
float cosA = cos(tiltAngle);
|
|
float sinA = sin(tiltAngle);
|
|
|
|
float newX = position.x * cosA - position.y * sinA;
|
|
float newY = position.x * sinA + position.y * cosA;
|
|
|
|
position.x = newX;
|
|
position.y = newY;
|
|
}
|
|
gl_Position = ProjMatrix * vec4(position, 1.0);
|
|
TexCoord = aTexCoord;
|
|
TexIndex = aTexIndex;
|
|
} |