Skip to content

Commit

Permalink
add distortion animation
Browse files Browse the repository at this point in the history
  • Loading branch information
grhp committed Mar 17, 2012
1 parent 0a58717 commit 08d5e1f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
4 changes: 3 additions & 1 deletion TextureWarping-Gridless.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct {
GLuint FboTexture;
GLuint FboHandle;
GLuint QuadVao;
float Power;
float BarrelPower;
} Globals;

static GLuint LoadProgram(const char* vsKey, const char* gsKey, const char* fsKey);
Expand Down Expand Up @@ -106,6 +106,7 @@ void PezUpdate(float seconds)
const float RadiansPerSecond = 0.5f;
Globals.Theta += seconds * RadiansPerSecond;
//Globals.Theta = Pi / 4;
Globals.BarrelPower = 2.0 - 0.5 * (sin(Globals.Theta * 4.0f) + 1.0);
}

void PezRender()
Expand Down Expand Up @@ -182,6 +183,7 @@ void PezRender()

glBindFramebuffer(GL_FRAMEBUFFER, 0);
glUseProgram(Globals.QuadProgram);
glUniform1f(u("BarrelPower"), Globals.BarrelPower);
glBindTexture(GL_TEXTURE_2D, Globals.FboTexture);
glBindVertexArray(Globals.QuadVao);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
Expand Down
26 changes: 11 additions & 15 deletions TextureWarping-Gridless.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ void main()

in vec2 vTexCoord;
out vec4 FragColor;
uniform float BarrelPower = 2.0;
uniform sampler2D Sampler;

const bool BlackBackground = true;
const bool BlackBorder = false;
const vec4 BackgroundColor = vec4(1);
const bool Border = true;

void main()
{
vec2 p = vTexCoord;
float theta = atan(p.y,p.x);
float radius = length(p);
radius = radius * radius;
radius = pow(radius, BarrelPower);
p.x = radius * cos(theta);
p.y = radius * sin(theta);
vec2 tc = 0.5 * (p + 1.0);
Expand All @@ -34,22 +35,17 @@ void main()
float v = fwidth(q.y);
float L = 1.0;

if (BlackBackground) {
if (q.x < -u || q.y < -v) {
FragColor = vec4(0);
return;
}
if (q.x < u) L *= (q.x/u);
if (q.y < v) L *= (q.y/v);
if (q.x < -u || q.y < -v) {
FragColor = BackgroundColor;
return;
}

if (BlackBorder) {
if (q.x < -u || q.y < -v) {
FragColor = vec4(1);
return;
}
if (Border) {
if (q.x < u) L *= abs(q.x/u);
if (q.y < v) L *= abs(q.y/v);
} else {
if (q.x < u) L *= q.x/u;
if (q.y < v) L *= q.y/v;
}

FragColor = L * texture(Sampler, tc);
Expand Down

0 comments on commit 08d5e1f

Please sign in to comment.