Skip to content

Instantly share code, notes, and snippets.

@esnho
Created September 24, 2021 17:07
Show Gist options
  • Save esnho/1a126f8db1f4753989e6463345298f61 to your computer and use it in GitHub Desktop.
Save esnho/1a126f8db1f4753989e6463345298f61 to your computer and use it in GitHub Desktop.
Swinging geometry shader for structure
attribute vec4 vertex;
attribute vec4 normal;
attribute vec2 textureCoord;
varying vec4 ncoord;
varying vec4 vcoord;
varying vec2 tcoord; //
uniform sampler2D tex; // texture one
uniform sampler2D tex2; // texture two
uniform vec2 tres; // size of texture (screen)
uniform vec4 fparams; // 4 floats coming in
uniform float ftime; // 0.0 to 1.0
uniform int itime; // increases when ftime hits 1.0
uniform mat4 MVP;
//f1:swing amount:
#define PI 3.1415926535897932384626
float time = float(itime) + ftime;
// https://github.com/dmnsgn/glsl-rotate/blob/master/rotation-3d-y.glsl
mat4 rotation3dY(float angle) {
float s = sin(angle);
float c = cos(angle);
return mat4(
c, 0.0, -s, 0.0,
0.0, 1.0, 0.0, 0.0,
s, 0.0, c, 0.0,
0.0, 0.0, 0.0, 1.0
);
}
void main(void)
{
vec4 c = texture2D(tex2,textureCoord);
tcoord = textureCoord;
// my demo code
// vec4 vertex = a_position;
vec4 v = vertex;
v = v * rotation3dY(sin(time + v.y) * fparams[1]);
vec4 Vert = MVP * v;
ncoord = normal;
gl_Position = Vert;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment