-
Notifications
You must be signed in to change notification settings - Fork 0
/
MovingTexShader.cpp
38 lines (31 loc) · 1.54 KB
/
MovingTexShader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "MovingTexShader.h"
#include "FileHelper.h"
#include "Resource.h"
MovingTexShader::MovingTexShader(Recipe& recipe) : NormalMappingProgram(recipe), texMoveValue(0.f){}
MovingTexShader MovingTexShader::create(){
return MovingTexShader(Recipe()
.addShader(Shader::compile(Shader::VertexShader, FileHelper::loadTextFile("shaders/Transform.glsl")))
.addShader(Shader::compile(Shader::VertexShader, FileHelper::loadTextFile("shaders/MovingTexture.vert")))
.addShader(Shader::compile(Shader::FragmentShader, FileHelper::loadTextFile("shaders/Transform.glsl")))
.addShader(Shader::compile(Shader::FragmentShader, FileHelper::loadTextFile("shaders/SimpleIlluminationModel.glsl")))
.addShader(Shader::compile(Shader::FragmentShader, FileHelper::loadTextFile("shaders/MovingTexture.frag")))
);
}
void MovingTexShader::onPreDraw(const Model & model)const{
NormalMappingProgram::onPreDraw(model);
GLint objectId;
if (0 <= (objectId = glGetUniformLocation(this->getProgramId(), "in_time"))) {
glUniform2fv(objectId, 1, texMoveValue.data());
}
}
void MovingTexShader::onPostDraw(const Model & model)const{
NormalMappingProgram::onPostDraw(model);
}
MovingTextureAnimation::MovingTextureAnimation(MovingTexShader & shader) : shader(shader) {
}
bool MovingTextureAnimation::stepFrame(const double timeElapsed, const double timeDelta) {
//movement += (cosf((float)timeElapsed) + 0.50f) * 0.001f;
//shader.setTexMoveValue({ movement * 0.5f, movement });
shader.setTexMoveValue({ (float)timeElapsed * 0.05f, (float)timeElapsed * 0.05f });
return false;
}