Skip to content

Commit cc7616e

Browse files
committed
Custom line shader
1 parent aec823d commit cc7616e

File tree

10 files changed

+266
-111
lines changed

10 files changed

+266
-111
lines changed

src/main/kotlin/com/lambda/graphics/esp/ShapeScope.kt

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
4747
scope.filledColor,
4848
scope.outlineColor,
4949
scope.sides,
50-
scope.outlineMode
50+
scope.outlineMode,
51+
scope.thickness
5152
)
5253
)
5354
}
@@ -98,10 +99,10 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
9899
}
99100

100101
/** Draw a simple outlined box. */
101-
fun outline(box: Box, color: Color, sides: Int = DirectionMask.ALL) {
102-
builder.outline(box, color, sides)
102+
fun outline(box: Box, color: Color, sides: Int = DirectionMask.ALL, thickness: Float = builder.lineWidth) {
103+
builder.outline(box, color, sides, thickness = thickness)
103104
if (collectShapes) {
104-
shapes?.add(EspShape.BoxShape(box.hashCode(), box, null, color, sides))
105+
shapes?.add(EspShape.BoxShape(box.hashCode(), box, null, color, sides, thickness = thickness))
105106
}
106107
}
107108

@@ -114,11 +115,11 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
114115
}
115116
}
116117

117-
fun outline(box: DynamicAABB, color: Color, sides: Int = DirectionMask.ALL) {
118-
builder.outline(box, color, sides)
118+
fun outline(box: DynamicAABB, color: Color, sides: Int = DirectionMask.ALL, thickness: Float = builder.lineWidth) {
119+
builder.outline(box, color, sides, thickness = thickness)
119120
if (collectShapes) {
120121
box.pair?.second?.let {
121-
shapes?.add(EspShape.BoxShape(it.hashCode(), it, null, color, sides))
122+
shapes?.add(EspShape.BoxShape(it.hashCode(), it, null, color, sides, thickness = thickness))
122123
}
123124
}
124125
}
@@ -130,10 +131,10 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
130131
}
131132
}
132133

133-
fun outline(pos: BlockPos, color: Color, sides: Int = DirectionMask.ALL) {
134-
builder.outline(pos, color, sides)
134+
fun outline(pos: BlockPos, color: Color, sides: Int = DirectionMask.ALL, thickness: Float = builder.lineWidth) {
135+
builder.outline(pos, color, sides, thickness = thickness)
135136
if (collectShapes) {
136-
shapes?.add(EspShape.BoxShape(pos.hashCode(), Box(pos), null, color, sides))
137+
shapes?.add(EspShape.BoxShape(pos.hashCode(), Box(pos), null, color, sides, thickness = thickness))
137138
}
138139
}
139140

@@ -144,10 +145,10 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
144145
}
145146
}
146147

147-
fun outline(pos: BlockPos, state: BlockState, color: Color, sides: Int = DirectionMask.ALL) {
148-
builder.outline(pos, state, color, sides)
148+
fun outline(pos: BlockPos, state: BlockState, color: Color, sides: Int = DirectionMask.ALL, thickness: Float = builder.lineWidth) {
149+
builder.outline(pos, state, color, sides, thickness = thickness)
149150
if (collectShapes) {
150-
shapes?.add(EspShape.BoxShape(pos.hashCode(), Box(pos), null, color, sides))
151+
shapes?.add(EspShape.BoxShape(pos.hashCode(), Box(pos), null, color, sides, thickness = thickness))
151152
}
152153
}
153154

@@ -160,11 +161,11 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
160161
}
161162
}
162163

163-
fun outline(shape: VoxelShape, color: Color, sides: Int = DirectionMask.ALL) {
164-
builder.outline(shape, color, sides)
164+
fun outline(shape: VoxelShape, color: Color, sides: Int = DirectionMask.ALL, thickness: Float = builder.lineWidth) {
165+
builder.outline(shape, color, sides, thickness = thickness)
165166
if (collectShapes) {
166167
shape.boundingBoxes.forEach {
167-
shapes?.add(EspShape.BoxShape(it.hashCode(), it, null, color, sides))
168+
shapes?.add(EspShape.BoxShape(it.hashCode(), it, null, color, sides, thickness = thickness))
168169
}
169170
}
170171
}
@@ -175,11 +176,12 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
175176
filled: Color,
176177
outline: Color,
177178
sides: Int = DirectionMask.ALL,
178-
mode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And
179+
mode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And,
180+
thickness: Float = builder.lineWidth
179181
) {
180-
builder.box(pos, state, filled, outline, sides, mode)
182+
builder.box(pos, state, filled, outline, sides, mode, thickness = thickness)
181183
if (collectShapes) {
182-
shapes?.add(EspShape.BoxShape(pos.hashCode(), Box(pos), filled, outline, sides, mode))
184+
shapes?.add(EspShape.BoxShape(pos.hashCode(), Box(pos), filled, outline, sides, mode, thickness = thickness))
183185
}
184186
}
185187

@@ -188,11 +190,12 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
188190
filled: Color,
189191
outline: Color,
190192
sides: Int = DirectionMask.ALL,
191-
mode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And
193+
mode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And,
194+
thickness: Float = builder.lineWidth
192195
) {
193-
builder.box(pos, filled, outline, sides, mode)
196+
builder.box(pos, filled, outline, sides, mode, thickness = thickness)
194197
if (collectShapes) {
195-
shapes?.add(EspShape.BoxShape(pos.hashCode(), Box(pos), filled, outline, sides, mode))
198+
shapes?.add(EspShape.BoxShape(pos.hashCode(), Box(pos), filled, outline, sides, mode, thickness = thickness))
196199
}
197200
}
198201

@@ -201,11 +204,12 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
201204
filledColor: Color,
202205
outlineColor: Color,
203206
sides: Int = DirectionMask.ALL,
204-
mode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And
207+
mode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And,
208+
thickness: Float = builder.lineWidth
205209
) {
206-
builder.box(box, filledColor, outlineColor, sides, mode)
210+
builder.box(box, filledColor, outlineColor, sides, mode, thickness = thickness)
207211
if (collectShapes) {
208-
shapes?.add(EspShape.BoxShape(box.hashCode(), box, filledColor, outlineColor, sides, mode))
212+
shapes?.add(EspShape.BoxShape(box.hashCode(), box, filledColor, outlineColor, sides, mode, thickness = thickness))
209213
}
210214
}
211215

@@ -214,13 +218,14 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
214218
filledColor: Color,
215219
outlineColor: Color,
216220
sides: Int = DirectionMask.ALL,
217-
mode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And
221+
mode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And,
222+
thickness: Float = builder.lineWidth
218223
) {
219-
builder.box(box, filledColor, outlineColor, sides, mode)
224+
builder.box(box, filledColor, outlineColor, sides, mode, thickness = thickness)
220225
if (collectShapes) {
221226
box.pair?.second?.let {
222227
shapes?.add(
223-
EspShape.BoxShape(it.hashCode(), it, filledColor, outlineColor, sides, mode)
228+
EspShape.BoxShape(it.hashCode(), it, filledColor, outlineColor, sides, mode, thickness = thickness)
224229
)
225230
}
226231
}
@@ -231,9 +236,10 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
231236
filled: Color,
232237
outline: Color,
233238
sides: Int = DirectionMask.ALL,
234-
mode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And
239+
mode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And,
240+
thickness: Float = builder.lineWidth
235241
) {
236-
builder.box(entity, filled, outline, sides, mode)
242+
builder.box(entity, filled, outline, sides, mode, thickness = thickness)
237243
if (collectShapes) {
238244
shapes?.add(
239245
EspShape.BoxShape(
@@ -242,7 +248,8 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
242248
filled,
243249
outline,
244250
sides,
245-
mode
251+
mode,
252+
thickness = thickness
246253
)
247254
)
248255
}
@@ -253,9 +260,10 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
253260
filled: Color,
254261
outline: Color,
255262
sides: Int = DirectionMask.ALL,
256-
mode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And
263+
mode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And,
264+
thickness: Float = builder.lineWidth
257265
) {
258-
builder.box(entity, filled, outline, sides, mode)
266+
builder.box(entity, filled, outline, sides, mode, thickness = thickness)
259267
if (collectShapes) {
260268
shapes?.add(
261269
EspShape.BoxShape(
@@ -264,7 +272,8 @@ class ShapeScope(val region: RenderRegion, val collectShapes: Boolean = false) {
264272
filled,
265273
outline,
266274
sides,
267-
mode
275+
mode,
276+
thickness = thickness
268277
)
269278
)
270279
}
@@ -277,6 +286,7 @@ class BoxScope(val box: Box, val parent: ShapeScope) {
277286
internal var outlineColor: Color? = null
278287
internal var sides: Int = DirectionMask.ALL
279288
internal var outlineMode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And
289+
internal var thickness: Float = parent.builder.lineWidth
280290

281291
fun filled(color: Color, sides: Int = DirectionMask.ALL) {
282292
this.filledColor = color
@@ -287,12 +297,14 @@ class BoxScope(val box: Box, val parent: ShapeScope) {
287297
fun outline(
288298
color: Color,
289299
sides: Int = DirectionMask.ALL,
290-
mode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And
300+
mode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And,
301+
thickness: Float = parent.builder.lineWidth
291302
) {
292303
this.outlineColor = color
293304
this.sides = sides
294305
this.outlineMode = mode
295-
parent.builder.outline(box, color, sides, mode)
306+
this.thickness = thickness
307+
parent.builder.outline(box, color, sides, mode, thickness = thickness)
296308
}
297309
}
298310

@@ -342,7 +354,8 @@ sealed class EspShape(val id: Int) {
342354
val filledColor: Color?,
343355
val outlineColor: Color?,
344356
val sides: Int = DirectionMask.ALL,
345-
val outlineMode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And
357+
val outlineMode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.And,
358+
val thickness: Float = 1.0f
346359
) : EspShape(id) {
347360
override fun renderInterpolated(
348361
prev: EspShape,
@@ -364,7 +377,7 @@ sealed class EspShape(val id: Int) {
364377

365378
val shapeBuilder = RegionShapeBuilder(region)
366379
filledColor?.let { shapeBuilder.filled(interpBox, it, sides) }
367-
outlineColor?.let { shapeBuilder.outline(interpBox, it, sides, outlineMode) }
380+
outlineColor?.let { shapeBuilder.outline(interpBox, it, sides, outlineMode, thickness = thickness) }
368381

369382
collector.faceVertices.addAll(shapeBuilder.collector.faceVertices)
370383
collector.edgeVertices.addAll(shapeBuilder.collector.edgeVertices)

src/main/kotlin/com/lambda/graphics/mc/LambdaRenderPipelines.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ object LambdaRenderPipelines : Loadable {
9292
RenderPipelines.register(
9393
RenderPipeline.builder(LAMBDA_ESP_SNIPPET, RenderPipelines.GLOBALS_SNIPPET)
9494
.withLocation(Identifier.of("lambda", "pipeline/esp_lines"))
95-
.withVertexShader(Identifier.ofVanilla("core/rendertype_lines"))
96-
.withFragmentShader(Identifier.ofVanilla("core/rendertype_lines"))
95+
.withVertexShader(Identifier.of("lambda", "core/advanced_lines"))
96+
.withFragmentShader(Identifier.of("lambda", "core/advanced_lines"))
9797
.withBlend(BlendFunction.TRANSLUCENT)
9898
.withDepthWrite(false)
9999
.withDepthTestFunction(DepthTestFunction.LEQUAL_DEPTH_TEST)
100100
.withCull(false)
101101
.withVertexFormat(
102102
VertexFormats.POSITION_COLOR_NORMAL_LINE_WIDTH,
103-
VertexFormat.DrawMode.LINES
103+
VertexFormat.DrawMode.QUADS
104104
)
105105
.build()
106106
)
@@ -110,15 +110,15 @@ object LambdaRenderPipelines : Loadable {
110110
RenderPipelines.register(
111111
RenderPipeline.builder(LAMBDA_ESP_SNIPPET, RenderPipelines.GLOBALS_SNIPPET)
112112
.withLocation(Identifier.of("lambda", "pipeline/esp_lines_through"))
113-
.withVertexShader(Identifier.ofVanilla("core/rendertype_lines"))
114-
.withFragmentShader(Identifier.ofVanilla("core/rendertype_lines"))
113+
.withVertexShader(Identifier.of("lambda", "core/advanced_lines"))
114+
.withFragmentShader(Identifier.of("lambda", "core/advanced_lines"))
115115
.withBlend(BlendFunction.TRANSLUCENT)
116116
.withDepthWrite(false)
117117
.withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST)
118118
.withCull(false)
119119
.withVertexFormat(
120120
VertexFormats.POSITION_COLOR_NORMAL_LINE_WIDTH,
121-
VertexFormat.DrawMode.LINES
121+
VertexFormat.DrawMode.QUADS
122122
)
123123
.build()
124124
)

src/main/kotlin/com/lambda/graphics/mc/RegionRenderer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ class RegionRenderer(val region: RenderRegion) {
9696
if (edgeIndexCount == 0) return
9797

9898
renderPass.setVertexBuffer(0, vb)
99-
// Use vanilla's sequential index buffer for lines
100-
val shapeIndexBuffer = RenderSystem.getSequentialBuffer(VertexFormat.DrawMode.LINES)
99+
// Use vanilla's sequential index buffer for quads
100+
val shapeIndexBuffer = RenderSystem.getSequentialBuffer(VertexFormat.DrawMode.QUADS)
101101
val indexBuffer = shapeIndexBuffer.getIndexBuffer(edgeIndexCount)
102102

103103
renderPass.setIndexBuffer(indexBuffer, shapeIndexBuffer.indexType)

0 commit comments

Comments
 (0)