Texture coords are now precomputed in VBOs

Also optimized GLSL code and started using LOC in RenderPrograms
This commit is contained in:
2020-12-18 00:30:22 +03:00
parent 7cc4fcbffc
commit cd6e6d7d9c
4 changed files with 47 additions and 44 deletions

View File

@@ -4,8 +4,6 @@ varying vec3 varyingColorMultiplier;
varying vec2 varyingTextureCoords;
uniform sampler2D textureSlot;
uniform vec2 textureStart;
uniform vec2 textureSize;
uniform bool useTexture;
@@ -13,32 +11,12 @@ void applyTexture() {
if (!useTexture) {
gl_FragColor = vec4(1, 1, 1, 1);
} else {
gl_FragColor = texture2D(
textureSlot,
vec2(
varyingTextureCoords[0] * textureSize[0] + textureStart[0],
varyingTextureCoords[1] * textureSize[1] + textureStart[1]
)
);
gl_FragColor = texture2D(textureSlot, varyingTextureCoords);
}
}
void multiply(inout vec4 vector, float scalar) {
vector.x *= scalar;
vector.y *= scalar;
vector.z *= scalar;
vector.w *= scalar;
}
void linearMultiply(inout vec4 vector, vec4 scalars) {
vector.x *= scalars.x;
vector.y *= scalars.y;
vector.z *= scalars.z;
vector.w *= scalars.w;
}
void applyColorMultiplier() {
linearMultiply(gl_FragColor, vec4(varyingColorMultiplier, 1.0));
gl_FragColor *= vec4(varyingColorMultiplier, 1.0);
}
void applyAlpha() {

View File

@@ -9,5 +9,5 @@ void applyShading() {
float angleCos = dot(normal, light);
float lightness = (angleCos + 1.5) / 2;
linearMultiply(gl_FragColor, vec4(lightness, lightness, lightness, 1.0));
gl_FragColor *= vec4(lightness, lightness, lightness, 1.0);
}