Added color multiplier stack to shaders, fixed dynamic font colors
- ShapeFragment.glsl now declares uniformColorMultiplier, which is used as an additional fragment color multiplier (independent from VBAs) - Managed with a new stack by ShapeRenderHelper - Fixed dynamic font colors
This commit is contained in:
parent
d197c0a73e
commit
008e8b33a5
@ -117,13 +117,13 @@ public abstract class SpriteTypeface extends Typeface {
|
||||
return output.set(resultWidth, height);
|
||||
}
|
||||
|
||||
private Shape createCharShape(char c, Vec4 color) {
|
||||
private Shape createCharShape(char c) {
|
||||
return new Shape(
|
||||
Usage.STATIC, getProgram(),
|
||||
Faces.createRectangle(
|
||||
getProgram(),
|
||||
getTexture(c),
|
||||
color,
|
||||
Colors.WHITE,
|
||||
Vectors.ZERO_3,
|
||||
new Vec3(getWidth(c), 0, 0),
|
||||
new Vec3(0, getHeight(), 0),
|
||||
@ -182,7 +182,7 @@ public abstract class SpriteTypeface extends Typeface {
|
||||
private Shape getShape(char c) {
|
||||
Shape shape = charShapes.get(c);
|
||||
if (shape == null) {
|
||||
shape = createCharShape(c, this.color);
|
||||
shape = createCharShape(c);
|
||||
charShapes.put(c, shape);
|
||||
}
|
||||
return shape;
|
||||
@ -195,14 +195,18 @@ public abstract class SpriteTypeface extends Typeface {
|
||||
@Override
|
||||
public void drawChar(char c, Vec4 color, Mat4 transform) {
|
||||
workspace.renderer.pushTransform().mul(transform);
|
||||
workspace.renderer.pushColorMultiplier().mul(color);
|
||||
getShape(c).render(workspace.renderer);
|
||||
workspace.renderer.popColorMultiplier();
|
||||
workspace.renderer.popTransform();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawRectangle(Vec2 size, Vec4 color, Mat4 transform) {
|
||||
workspace.renderer.pushTransform().mul(transform).scale(size.x, size.y, 1);
|
||||
workspace.renderer.pushColorMultiplier().mul(color);
|
||||
unitLine.render(workspace.renderer);
|
||||
workspace.renderer.popColorMultiplier();
|
||||
workspace.renderer.popTransform();
|
||||
}
|
||||
|
||||
|
@ -18,18 +18,26 @@
|
||||
package ru.windcorp.progressia.client.graphics.model;
|
||||
|
||||
import glm.mat._4.Mat4;
|
||||
import glm.vec._4.Vec4;
|
||||
import ru.windcorp.progressia.client.graphics.Colors;
|
||||
import ru.windcorp.progressia.common.util.StashingStack;
|
||||
|
||||
public class ShapeRenderHelper {
|
||||
|
||||
protected static final int TRANSFORM_STACK_SIZE = 64;
|
||||
protected static final int COLOR_MULTIPLIER_STACK_SIZE = TRANSFORM_STACK_SIZE;
|
||||
|
||||
protected final StashingStack<Mat4> transformStack = new StashingStack<>(
|
||||
TRANSFORM_STACK_SIZE, Mat4::new
|
||||
);
|
||||
|
||||
protected final StashingStack<Vec4> colorMultiplierStack = new StashingStack<>(
|
||||
COLOR_MULTIPLIER_STACK_SIZE, Vec4::new
|
||||
);
|
||||
|
||||
{
|
||||
transformStack.push().identity();
|
||||
colorMultiplierStack.push().set(Colors.WHITE);
|
||||
}
|
||||
|
||||
public Mat4 pushTransform() {
|
||||
@ -49,9 +57,28 @@ public class ShapeRenderHelper {
|
||||
return getTransform();
|
||||
}
|
||||
|
||||
public Vec4 pushColorMultiplier() {
|
||||
Vec4 previous = colorMultiplierStack.getHead();
|
||||
return colorMultiplierStack.push().set(previous);
|
||||
}
|
||||
|
||||
public void popColorMultiplier() {
|
||||
colorMultiplierStack.removeHead();
|
||||
}
|
||||
|
||||
public Vec4 getColorMultiplier() {
|
||||
return colorMultiplierStack.getHead();
|
||||
}
|
||||
|
||||
public Vec4 getFinalColorMultiplier() {
|
||||
return getColorMultiplier();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
transformStack.removeAll();
|
||||
transformStack.push().identity();
|
||||
colorMultiplierStack.removeAll();
|
||||
colorMultiplierStack.push().set(Colors.WHITE);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -54,13 +54,15 @@ public class ShapeRenderProgram extends Program {
|
||||
private static final String
|
||||
FINAL_TRANSFORM_UNIFORM_NAME = "finalTransform",
|
||||
POSITIONS_ATTRIBUTE_NAME = "inputPositions",
|
||||
COLOR_MULTIPLER_ATTRIBUTE_NAME = "inputColorMultiplier",
|
||||
UNIFORM_COLOR_MULTIPLER_ATTRIBUTE_NAME = "uniformColorMultiplier",
|
||||
ATTRIBUTE_COLOR_MULTIPLER_ATTRIBUTE_NAME = "inputColorMultiplier",
|
||||
TEXTURE_COORDS_ATTRIBUTE_NAME = "inputTextureCoords",
|
||||
USE_TEXTURE_UNIFORM_NAME = "useTexture",
|
||||
TEXTURE_SLOT_UNIFORM_NAME = "textureSlot";
|
||||
|
||||
private final Uniform4Matrix finalTransformUniform;
|
||||
private final AttributeVertexArray positionsAttribute;
|
||||
private final Uniform4Float colorsUniform;
|
||||
private final AttributeVertexArray colorsAttribute;
|
||||
private final AttributeVertexArray textureCoordsAttribute;
|
||||
private final Uniform1Int useTextureUniform;
|
||||
@ -85,8 +87,11 @@ public class ShapeRenderProgram extends Program {
|
||||
this.positionsAttribute =
|
||||
getAttribute(POSITIONS_ATTRIBUTE_NAME).asVertexArray();
|
||||
|
||||
this.colorsUniform =
|
||||
getUniform(UNIFORM_COLOR_MULTIPLER_ATTRIBUTE_NAME).as4Float();
|
||||
|
||||
this.colorsAttribute =
|
||||
getAttribute(COLOR_MULTIPLER_ATTRIBUTE_NAME).asVertexArray();
|
||||
getAttribute(ATTRIBUTE_COLOR_MULTIPLER_ATTRIBUTE_NAME).asVertexArray();
|
||||
|
||||
this.textureCoordsAttribute =
|
||||
getAttribute(TEXTURE_COORDS_ATTRIBUTE_NAME).asVertexArray();
|
||||
@ -140,6 +145,7 @@ public class ShapeRenderProgram extends Program {
|
||||
|
||||
protected void configure(ShapeRenderHelper helper) {
|
||||
finalTransformUniform.set(helper.getFinalTransform());
|
||||
colorsUniform.set(helper.getFinalColorMultiplier());
|
||||
}
|
||||
|
||||
protected int bindVertices(VertexBufferObject vertices) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
#version 120
|
||||
|
||||
uniform vec4 uniformColorMultiplier;
|
||||
|
||||
varying vec4 varyingColorMultiplier;
|
||||
varying vec2 varyingTextureCoords;
|
||||
|
||||
@ -17,6 +19,7 @@ void applyTexture() {
|
||||
|
||||
void applyColorMultiplier() {
|
||||
gl_FragColor *= varyingColorMultiplier;
|
||||
gl_FragColor *= uniformColorMultiplier;
|
||||
}
|
||||
|
||||
void applyAlpha() {
|
||||
|
Reference in New Issue
Block a user