Skip to content

Commit ce946f2

Browse files
committed
Shader optimization
1 parent a1577f4 commit ce946f2

File tree

8 files changed

+15
-24
lines changed

8 files changed

+15
-24
lines changed

common/src/main/kotlin/com/lambda/graphics/shader/Shader.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ class Shader(fragmentPath: String, vertexPath: String) {
2828

2929
fun use() {
3030
glUseProgram(id)
31-
set("u_Projection", RenderMain.projectionMatrix)
32-
set("u_ModelView", RenderMain.modelViewMatrix)
31+
set("u_ProjModel", Matrix4f(RenderMain.projectionMatrix).mul(RenderMain.modelViewMatrix))
3332
}
3433

3534
private fun loc(name: String) =

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ layout (location = 0) in vec3 pos1;
44
layout (location = 1) in vec3 pos2;
55
layout (location = 2) in vec4 color;
66

7-
uniform mat4 u_Projection;
8-
uniform mat4 u_ModelView;
7+
uniform mat4 u_ProjModel;
98

109
uniform float u_TickDelta;
1110
uniform vec3 u_CameraPosition;
@@ -15,6 +14,6 @@ out vec4 v_Color;
1514
#define VERTEX_POSITION mix(pos1, pos2, u_TickDelta) - u_CameraPosition
1615

1716
void main() {
18-
gl_Position = u_Projection * u_ModelView * vec4(VERTEX_POSITION, 1.0);
17+
gl_Position = u_ProjModel * vec4(VERTEX_POSITION, 1.0);
1918
v_Color = color;
2019
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
layout (location = 0) in vec3 pos;
44
layout (location = 1) in vec4 color;
55

6-
uniform mat4 u_Projection;
7-
uniform mat4 u_ModelView;
8-
6+
uniform mat4 u_ProjModel;
97
uniform vec3 u_CameraPosition;
108

119
out vec4 v_Color;
1210

1311
#define VERTEX_POSITION pos - u_CameraPosition
1412

1513
void main() {
16-
gl_Position = u_Projection * u_ModelView * vec4(VERTEX_POSITION, 1.0);
14+
gl_Position = u_ProjModel * vec4(VERTEX_POSITION, 1.0);
1715
v_Color = color;
1816
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ layout (location = 0) in vec4 pos;
44
layout (location = 1) in vec2 uv;
55
layout (location = 2) in vec4 color;
66

7-
uniform mat4 u_Projection;
8-
uniform mat4 u_ModelView;
7+
uniform mat4 u_ProjModel;
98

109
out vec2 v_TexCoord;
1110
out vec4 v_Color;
1211

1312
void main() {
14-
gl_Position = u_Projection * u_ModelView * pos;
13+
gl_Position = u_ProjModel * pos;
1514

1615
v_TexCoord = uv;
1716
v_Color = color;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ layout (location = 3) in float round;
77
layout (location = 4) in float shade;
88
layout (location = 5) in vec4 color;
99

10-
uniform mat4 u_Projection;
11-
uniform mat4 u_ModelView;
10+
uniform mat4 u_ProjModel;
1211

1312
out vec2 v_Position;
1413
out vec2 v_TexCoord;
@@ -18,7 +17,7 @@ out float v_RoundRadius;
1817
out float v_Shade;
1918

2019
void main() {
21-
gl_Position = u_Projection * u_ModelView * pos;
20+
gl_Position = u_ProjModel * pos;
2221

2322
v_Position = gl_Position.xy * 0.5 + 0.5;
2423
v_TexCoord = uv;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ layout (location = 1) in float alpha;
55
layout (location = 2) in float shade;
66
layout (location = 3) in vec4 color;
77

8-
uniform mat4 u_Projection;
9-
uniform mat4 u_ModelView;
8+
uniform mat4 u_ProjModel;
109

1110
out vec2 v_Position;
1211
out float v_Alpha;
1312
out vec4 v_Color;
1413
out float v_Shade;
1514

1615
void main() {
17-
gl_Position = u_Projection * u_ModelView * pos;
16+
gl_Position = u_ProjModel * pos;
1817

1918
v_Position = gl_Position.xy * 0.5 + 0.5;
2019
v_Alpha = alpha;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ layout (location = 0) in vec3 pos1;
44
layout (location = 1) in vec3 pos2;
55
layout (location = 2) in vec4 color;
66

7-
uniform mat4 u_Projection;
8-
uniform mat4 u_ModelView;
7+
uniform mat4 u_ProjModel;
98

109
uniform float u_TickDelta;
1110
uniform vec3 u_CameraPosition;
@@ -15,7 +14,7 @@ out vec4 v_Color;
1514
#define VERTEX_POSITION mix(pos1, pos2, u_TickDelta) - u_CameraPosition
1615

1716
#define SCREEN_CENTER vec4(0.0, 0.0, 0.0, 1.0)
18-
#define PROJECTED u_Projection * u_ModelView * vec4(VERTEX_POSITION, 1.0)
17+
#define PROJECTED u_ProjModel * vec4(VERTEX_POSITION, 1.0)
1918

2019
void main() {
2120
gl_Position = gl_VertexID % 2 == 0 ? SCREEN_CENTER : PROJECTED;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
layout (location = 0) in vec3 pos;
44
layout (location = 1) in vec4 color;
55

6-
uniform mat4 u_Projection;
7-
uniform mat4 u_ModelView;
6+
uniform mat4 u_ProjModel;
87

98
uniform vec3 u_CameraPosition;
109

@@ -13,7 +12,7 @@ out vec4 v_Color;
1312
#define VERTEX_POSITION pos - u_CameraPosition
1413

1514
#define SCREEN_CENTER vec4(0.0, 0.0, 0.0, 1.0)
16-
#define PROJECTED u_Projection * u_ModelView * vec4(VERTEX_POSITION, 1.0)
15+
#define PROJECTED u_ProjModel * vec4(VERTEX_POSITION, 1.0)
1716

1817
void main() {
1918
gl_Position = gl_VertexID % 2 == 0 ? SCREEN_CENTER : PROJECTED;

0 commit comments

Comments
 (0)