Skip to content

Commit 9efcebc

Browse files
committed
Color waving
1 parent c7464f3 commit 9efcebc

File tree

6 files changed

+69
-12
lines changed

6 files changed

+69
-12
lines changed

common/src/main/kotlin/com/lambda/graphics/renderer/gui/rect/RectEntry.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class RectEntry(
1111
override val updateBlock: IRectEntry.() -> Unit
1212
) : IRectEntry {
1313
override var position by owner.field(Rect.ZERO)
14-
1514
override var roundRadius by owner.field(0.0)
1615

1716
private var leftTop by owner.field(Color.WHITE!!)
@@ -65,7 +64,6 @@ class RectEntry(
6564

6665
interface IRectEntry : IRenderEntry<IRectEntry> {
6766
var position: Rect
68-
6967
var roundRadius: Double
7068

7169
fun color(leftTop: Color, rightTop: Color, rightBottom: Color, leftBottom: Color)

common/src/main/kotlin/com/lambda/graphics/renderer/gui/rect/RectRenderer.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,35 @@ package com.lambda.graphics.renderer.gui.rect
33
import com.lambda.graphics.buffer.vao.vertex.VertexAttrib
44
import com.lambda.graphics.renderer.gui.AbstractGuiRenderer
55
import com.lambda.graphics.shader.Shader
6+
import com.lambda.module.modules.client.ClickGui
7+
import com.lambda.util.math.Vec2d
8+
import org.lwjgl.glfw.GLFW.glfwGetTime
69

710
class RectRenderer : AbstractGuiRenderer<IRectEntry>(
811
VertexAttrib.Group.RECT
912
) {
13+
var shadeColor = false
14+
1015
override fun render() {
1116
shader.use()
17+
18+
shader["u_Shade"] = shadeColor
19+
20+
if (shadeColor) {
21+
shader["u_Time"] = glfwGetTime() * ClickGui.colorSpeed * 3.0
22+
shader["u_Color1"] = ClickGui.shadeColor1
23+
shader["u_Color2"] = ClickGui.shadeColor2
24+
shader["u_Size"] = Vec2d.ONE / Vec2d(ClickGui.colorWidth, ClickGui.colorHeight)
25+
}
26+
1227
super.render()
1328
}
1429

30+
override fun build(block: IRectEntry.() -> Unit): IRectEntry {
31+
shadeColor = false
32+
return super.build(block)
33+
}
34+
1535
override fun newEntry(block: IRectEntry.() -> Unit) =
1636
RectEntry(this, block)
1737

common/src/main/kotlin/com/lambda/gui/api/layer/RenderLayer.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ import com.mojang.blaze3d.systems.RenderSystem.defaultBlendFunc
88
import org.lwjgl.opengl.GL11.GL_ONE
99
import org.lwjgl.opengl.GL11.GL_SRC_ALPHA
1010

11-
class RenderLayer(private val allowGlowing: Boolean = false) {
12-
val rect = RectRenderer().asRenderer
11+
class RenderLayer(private val allowEffects: Boolean = false) {
12+
private val rectRenderer = RectRenderer()
13+
14+
val rect = rectRenderer.asRenderer
1315
val font = FontRenderer().asRenderer
1416

1517
fun render() {
1618
rect.update()
1719
font.update()
1820

19-
if (allowGlowing && ClickGui.glow) blendFunc(GL_SRC_ALPHA, GL_ONE)
20-
rect.render()
21-
defaultBlendFunc()
21+
rectRenderer.shadeColor = ClickGui.shade
22+
applyFancyBlending(rect::render)
2223

2324
font.render()
2425
}
@@ -27,4 +28,12 @@ class RenderLayer(private val allowGlowing: Boolean = false) {
2728
rect.destroy()
2829
font.destroy()
2930
}
31+
32+
private fun applyFancyBlending(block: () -> Unit) {
33+
if (ClickGui.glow && allowEffects) {
34+
blendFunc(GL_SRC_ALPHA, GL_ONE)
35+
block()
36+
defaultBlendFunc()
37+
} else block()
38+
}
3039
}

common/src/main/kotlin/com/lambda/module/modules/client/ClickGui.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,19 @@ object ClickGui : Module(
2222
val buttonStep by setting("Button Step", 1.0, 0.0..5.0, 0.1, visibility = { page == Page.General })
2323

2424
// Colors
25-
val mainColor by setting("Main Color", Color(100, 215, 255), visibility = { page == Page.Colors })
25+
private val primaryColor by setting("Primary Color", Color(130, 200, 255), visibility = { page == Page.Colors })
26+
private val secondaryColor by setting("Secondary Color", Color(225, 130, 225), visibility = { page == Page.Colors && shade })
2627
val backgroundColor by setting("Background Color", Color(0, 0, 0, 80), visibility = { page == Page.Colors })
27-
val glow by setting("Glow (experimental)", true, visibility = { page == Page.Colors })
28+
val glow by setting("Glow", true, visibility = { page == Page.Colors })
29+
val shade by setting("Shade Color", true, visibility = { page == Page.Colors })
30+
val colorWidth by setting("Color Width", 40.0, 1.0..100.0, 1.0, visibility = { page == Page.Colors && shade })
31+
val colorHeight by setting("Color Height", 40.0, 1.0..100.0, 1.0, visibility = { page == Page.Colors && shade })
32+
val colorSpeed by setting("Color Speed", 1.0, 0.1..10.0, 0.1, visibility = { page == Page.Colors && shade })
33+
34+
val mainColor: Color get() = if (shade) Color.WHITE else primaryColor
35+
36+
val shadeColor1 get() = primaryColor
37+
val shadeColor2 get() = secondaryColor
2838

2939
enum class Page {
3040
General,

common/src/main/resources/assets/lambda/shaders/fragment/renderer/rect.frag

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#version 330 core
22

3+
uniform bool u_Shade;
4+
uniform float u_Time;
5+
uniform vec4 u_Color1;
6+
uniform vec4 u_Color2;
7+
uniform vec2 u_Size;
8+
9+
in vec2 v_Position;
310
in vec2 v_TexCoord;
411
in vec4 v_Color;
512
in vec2 v_Size;
@@ -9,7 +16,16 @@ out vec4 color;
916

1017
#define SMOOTHING 0.5
1118

12-
void main() {
19+
vec4 shade() {
20+
if (!u_Shade) return v_Color;
21+
22+
vec2 pos = v_Position * u_Size;
23+
float p = sin(pos.x + pos.y - u_Time) * 0.5 + 0.5;
24+
25+
return mix(u_Color1, u_Color2, p) * vec4(1.0, 1.0, 1.0, v_Color.a);
26+
}
27+
28+
vec4 round() {
1329
vec2 halfSize = v_Size * 0.5;
1430

1531
float radius = max(v_RoundRadius, SMOOTHING);
@@ -21,7 +37,9 @@ void main() {
2137
float distance = length(max(abs(center) - halfSize + radius, 0.0)) - radius;
2238

2339
float alpha = 1.0 - smoothstep(-SMOOTHING, SMOOTHING, distance);
24-
alpha = clamp(alpha, 0.0, 1.0);
40+
return vec4(1.0, 1.0, 1.0, clamp(alpha, 0.0, 1.0));
41+
}
2542

26-
color = v_Color * vec4(1.0, 1.0, 1.0, alpha);
43+
void main() {
44+
color = shade() * round();
2745
}

common/src/main/resources/assets/lambda/shaders/vertex/renderer/rect.vert

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ layout (location = 3) in vec4 color;
88
uniform mat4 u_Projection;
99
uniform mat4 u_ModelView;
1010

11+
out vec2 v_Position;
1112
out vec2 v_TexCoord;
1213
out vec4 v_Color;
1314
out vec2 v_Size;
@@ -16,6 +17,7 @@ out float v_RoundRadius;
1617
void main() {
1718
gl_Position = u_Projection * u_ModelView * pos;
1819

20+
v_Position = pos.xy;
1921
v_TexCoord = uv;
2022
v_Color = color;
2123

0 commit comments

Comments
 (0)