Pavel Daniel
Pavel Daniel

Reputation: 109

Waving flag effect in vertex shader

I am looking to create a waving flag effect in a vertex shader and here is what i have so far:

#version 330

layout(location = 0) in vec3 in_position;       
layout(location = 1) in vec3 in_color;      

uniform mat4 model_matrix, view_matrix, projection_matrix;
uniform vec3 culoare;
uniform float currentAngle;

out vec3 vertex_to_fragment_color;

void main(){

vertex_to_fragment_color = culoare;

vec4 v = vec4( in_position.x, in_position.y, in_position.z, 1.0 );

v.y  = sin( in_position.x + currentAngle );
v.y += sin( in_position.z + currentAngle );
v.y *= in_position.x * 0.08;

gl_Position = projection_matrix*view_matrix*model_matrix*v; 
}

current_angle is a variable that i'm sending to the shader and it kind of looks like this:

if ( currentAngle > 360.0f ) currentAngle -= 360.0f;
if ( currentAngle < 0.0f   ) currentAngle += 360.0f;

I am new to this so i could really use some help to get this right.

Upvotes: 1

Views: 2255

Answers (1)

genpfault
genpfault

Reputation: 52094

GLSL's sin() and cos() take their arguments in radians, not degrees.

You can use the GLSL function radians() to convert degrees to radians.

You'll also have to subdivide your flag rectangle to get a convincing effect.

Upvotes: 1

Related Questions