text texture animation

This commit is contained in:
devZoGok
2021-10-19 19:06:41 +03:00
parent a4fed6f062
commit bfab74a663
6 changed files with 35 additions and 10 deletions
+9 -3
View File
@@ -4,16 +4,22 @@ in vec2 texCoords;
out vec4 FragColor; out vec4 FragColor;
struct Texture{
float mixRatio;
sampler2D pastTexture, nextTexture;
bool animated;
};
uniform bool texturingEnabled; uniform bool texturingEnabled;
uniform bool diffuseColorEnabled; uniform bool diffuseColorEnabled;
uniform bool guiPlane; uniform bool guiPlane;
uniform vec4 diffuseColor; uniform vec4 diffuseColor;
uniform sampler2D tex; uniform Texture diffuseMap;
void main(){ void main(){
vec4 c = (texturingEnabled ? texture(tex, texCoords) : diffuseColor); vec4 c = (texturingEnabled ? texture(diffuseMap.pastTexture, texCoords) : diffuseColor);
if(diffuseColorEnabled){ if(diffuseColorEnabled){
float alpha = texture(tex, texCoords).w; float alpha = texture(diffuseMap.pastTexture, texCoords).w;
c = vec4(diffuseColor.xyz, alpha); c = vec4(diffuseColor.xyz, alpha);
} }
+2
View File
@@ -10,6 +10,8 @@ namespace vb01{
currentValue = pastKeyframe.value; currentValue = pastKeyframe.value;
break; break;
case Keyframe::LINEAR: case Keyframe::LINEAR:
currentValue = interpolateBezier(vector<float>({pastKeyframe.value, nextKeyframe.value}), ratio);
break;
case Keyframe::BEZIER: case Keyframe::BEZIER:
vector<float> points = vector<float>({pastKeyframe.value, pastKeyframe.rightHandleValue, nextKeyframe.leftHandleValue, nextKeyframe.value}); vector<float> points = vector<float>({pastKeyframe.value, pastKeyframe.rightHandleValue, nextKeyframe.leftHandleValue, nextKeyframe.value});
currentValue = interpolateBezier(points, ratio); currentValue = interpolateBezier(points, ratio);
+3 -2
View File
@@ -107,8 +107,9 @@ namespace vb01{
shader->setVec4(diffuseColor, "diffuseColor"); shader->setVec4(diffuseColor, "diffuseColor");
} }
else if(type == MATERIAL_TEXT){ else if(type == MATERIAL_TEXT){
shader->setInt(0, "textTex"); shader->setInt(0, "textures[0].pastTexture");
//shader->setInt(1, "diffuseMap"); shader->setInt(1, "textures[0].nextTexture");
shader->setInt(2, "textures[1].pastTexture");
} }
if(texturingEnabled){ if(texturingEnabled){
+1 -1
View File
@@ -102,7 +102,7 @@ namespace vb01{
glBindVertexArray(VAO); glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferSubData(GL_ARRAY_BUFFER, 0, dataSize, data); glBufferSubData(GL_ARRAY_BUFFER, 0, dataSize, data);
glyph.texture->select(); glyph.texture->select(2);
glDrawArrays(GL_TRIANGLES, 0, 6); glDrawArrays(GL_TRIANGLES, 0, 6);
} }
+19 -3
View File
@@ -4,10 +4,26 @@ in vec2 texCoords;
out vec4 FragColor; out vec4 FragColor;
uniform sampler2D textTex, diffuseMap; struct Texture{
float mixRatio;
sampler2D pastTexture, nextTexture;
bool animated;
};
uniform Texture textures[2];
uniform bool texturingEnabled;
uniform vec4 diffuseColor; uniform vec4 diffuseColor;
void main(){ void main(){
float alpha = texture(textTex, texCoords).r; vec4 diffCol;
FragColor = vec4(diffuseColor.xyz, diffuseColor.w * alpha); if(texturingEnabled){
diffCol = texture(textures[0].pastTexture, texCoords);
if(textures[0].animated)
diffCol = mix(diffCol, texture(textures[0].nextTexture, texCoords), textures[0].mixRatio);
}
else
diffCol = diffuseColor;
float alpha = texture(textures[1].pastTexture, texCoords).r;
FragColor = vec4(diffCol.xyz, diffCol.w * alpha);
} }
+1 -1
View File
@@ -78,7 +78,7 @@ void main(){
vec4 finalColor = diffuseColor; vec4 finalColor = diffuseColor;
if(texturingEnabled){ if(texturingEnabled){
vec4 textureColor = texture(textures[0].pastTexture, texCoords); vec4 textureColor = texture(textures[0].pastTexture, texCoords);
finalColor = textures[0].animated ? mix(textureColor, texture(textures[0].nextTexture, texCoords), textures[0].mixRatio) : textureColor; finalColor = (textures[0].animated ? mix(textureColor, texture(textures[0].nextTexture, texCoords), textures[0].mixRatio) : textureColor);
} }
vec3 normal = norm; vec3 normal = norm;