Verified Commit 70c083aa authored by Lars Mitsem Selbekk's avatar Lars Mitsem Selbekk Committed by Mathias O. Myklebust
Browse files

Make converted units red

parent e1601d88
attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;
uniform mat4 u_projTrans;
varying vec4 v_color;
varying vec2 v_texCoords;
void main() {
v_color = a_color;
v_texCoords = a_texCoord0;
gl_Position = u_projTrans * a_position;
}
#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
void main() {
vec4 c = v_color * texture2D(u_texture, v_texCoords);
float color = (c.r + c.g + c.b) / 3.0;
gl_FragColor = vec4(color, color / 3.0, color / 3.0, c.a);
}
......@@ -36,7 +36,7 @@ open class UnitController(
var converted: Boolean = false
set(value) {
field = value
unitView.flipped = converted
unitView.converted = converted
}
private var unitHealthBarController = UnitHealthBarController(
......
package se.battlegoo.battlegoose.views
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.glutils.ShaderProgram
object RedShiftShader : ShaderProgram(
// No-op vertex shader
Gdx.files.internal("shaders/noop.vert"),
// Red-shifting fragment shader
Gdx.files.internal("shaders/redShift.frag")
)
package se.battlegoo.battlegoose.views
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import se.battlegoo.battlegoose.utils.TextureAsset
class UnitView(
......@@ -21,8 +22,9 @@ class UnitView(
field = value
}
var flipped: Boolean = false
var converted: Boolean = false
set(value) {
if (value == field) return
field = value
facingDirection = if (value)
textureStartFacingDirection.flipped()
......@@ -30,6 +32,15 @@ class UnitView(
textureStartFacingDirection
}
override fun render(sb: SpriteBatch) {
val previousShader = sb.shader
if (converted) {
sb.shader = RedShiftShader
}
super.render(sb)
sb.shader = previousShader
}
var focused: Boolean = false
init {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment