From da761b2e72cb650e2196686e3466397f27683889 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Sat, 7 Mar 2015 14:56:16 +0100 Subject: [PATCH] Added movement to water texture. Movement speed currently hard coded. --- data/shader/phong.fsh | 13 +++++++++++-- graphics.cc | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/data/shader/phong.fsh b/data/shader/phong.fsh index 154ee93..a2ed89e 100644 --- a/data/shader/phong.fsh +++ b/data/shader/phong.fsh @@ -40,6 +40,9 @@ uniform float lightIntensities[32]; uniform float farPlane; uniform vec4 fogColor; uniform vec3 cameraCenter; +uniform bool movingTexture; +uniform vec2 movement; +uniform float time; vec2 poissonDisk[16] = vec2[]( vec2( -0.94201624, -0.39906216 ), @@ -191,7 +194,13 @@ void main() float fogFactor = clamp((1.0 - ((farPlane - 35.0) -distanceCameraCenter)/30.0), 0.0, 1.0); fogFactor *= clamp((1.0-((fragPosition.y-40.0)/30.0)), 0.0, 1.0); - vec4 texture = texture(uTexture, vTexCoord).rgba; - oColor = vec4(finalColor, 1.0f)*texture; + vec4 textureColor = vec4(0.0, 0.0, 0.0, 1.0); + if (movingTexture == true) { + textureColor = texture(uTexture, vec2(vTexCoord.x + movement.x * time, vTexCoord.y + movement.y * time)).rgba; + } + else { + textureColor = texture(uTexture, vTexCoord).rgba; + } + oColor = vec4(finalColor, 1.0f)*textureColor; oColor = mix(oColor, fogColor, fogFactor); } diff --git a/graphics.cc b/graphics.cc index 73882e7..f741754 100644 --- a/graphics.cc +++ b/graphics.cc @@ -314,6 +314,8 @@ void Graphics::render(double time) // set Material Parameters lightingShader->setUniform("ambientColor", level->getAmbientLight()); lightingShader->setUniform("camera", level->getPhysics()->getCameraPosition()); + lightingShader->setUniform("movement", glm::vec2(-0.3f, -0.4f)); + lightingShader->setUniform("time", (float) time); // render the level level->render(lightingShader, true, &lightingViewProjectionMatrix, &depthBiasVPs);