Skip to content

Commit 244ee90

Browse files
Added new hotkeys. Added new debug tab. Fixed project creation validation bug
1 parent 6ca99e5 commit 244ee90

File tree

15 files changed

+302
-9
lines changed

15 files changed

+302
-9
lines changed
807 Bytes
Loading
316 Bytes
Loading

composeApp/src/jvmMain/composeResources/files/shaders/desktop/fblobprocessor.glsl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ out vec4 FragColor;
66

77
uniform usampler2D uTileMap;
88
uniform sampler2DArray uBlobTexture;
9+
uniform sampler2DArray uBlobMask;
10+
uniform vec4 uMaskColor;
11+
uniform bool uShouldDrawMask;
12+
913

1014
uniform vec2 uTileUnit;// (1,1) / map_size_in_tiles
1115
uniform vec4 uColorTint;
@@ -14,6 +18,12 @@ bool withinBounds(vec2 toCheck, vec2 minBounds, vec2 maxBounds) {
1418
return toCheck.x >= minBounds.x && toCheck.x < maxBounds.x && toCheck.y >= minBounds.y && toCheck.y < maxBounds.y;
1519
}
1620

21+
vec4 blendPixels(vec4 src, vec4 dst) {
22+
// vec4 preProcessed = (src * src.a) + (dst * (1.0 - src.a));
23+
// return vec4(preProcessed.rgb, max(src.a, dst.a));
24+
return max(src, dst);
25+
}
26+
1727
bool withinUnit(vec2 cords) {
1828
return withinBounds(cords, vec2(0), vec2(1));
1929
}
@@ -200,7 +210,15 @@ vec4 getPixel(vec2 texCord) {
200210
ivec2 currentBlobMask = blobMasks[i];
201211
if (checkMask(mask, currentBlobMask.x)) blobIndex = currentBlobMask.y;
202212
}
203-
return texture(uBlobTexture, vec3(tileCoordinates, blobIndex)) * uColorTint;
213+
214+
vec4 currentColor = texture(uBlobTexture, vec3(tileCoordinates, blobIndex)) * uColorTint;
215+
if (!uShouldDrawMask)
216+
return currentColor;
217+
else {
218+
vec4 maskColor = texture(uBlobMask, vec3(tileCoordinates, blobIndex)) * uMaskColor;
219+
// return blendPixels(currentColor, maskColor);
220+
return blendPixels(maskColor, currentColor);
221+
}
204222

205223
}
206224

composeApp/src/jvmMain/kotlin/ua/valeriishymchuk/lobmapeditor/domain/terrain/Terrain.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ data class Terrain (
6666

6767
companion object {
6868

69+
const val MAX_TERRAIN_HEIGHT = 7;
6970

7071
fun deserialize(json: JsonObject): Terrain {
7172
// Extract dimensions in pixels

composeApp/src/jvmMain/kotlin/ua/valeriishymchuk/lobmapeditor/render/EditorRenderer.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ class EditorRenderer(override val di: DI) : GLEventListener, DIAware {
178178

179179
translate(Vector3f(toolService.refenceOverlayTool.offset.value.mul(-1f, Vector2f()), 0f))
180180
}
181-
)
181+
),
182+
toolService.debugTool.debugInfo.value
182183
)
183184

184185

composeApp/src/jvmMain/kotlin/ua/valeriishymchuk/lobmapeditor/render/InputListener.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import ua.valeriishymchuk.lobmapeditor.domain.unit.GameUnit.Companion.UNIT_DIMEN
2828
import ua.valeriishymchuk.lobmapeditor.services.project.EditorService
2929
import ua.valeriishymchuk.lobmapeditor.services.project.EditorService.Companion.deleteUnits
3030
import ua.valeriishymchuk.lobmapeditor.services.project.ToolService
31+
import ua.valeriishymchuk.lobmapeditor.services.project.tools.TerrainPickTool
3132
import ua.valeriishymchuk.lobmapeditor.shared.GameConstants
3233
import ua.valeriishymchuk.lobmapeditor.shared.refence.Reference
3334
import java.awt.Desktop
@@ -150,6 +151,27 @@ class InputListener(
150151
KeyEvent.VK_E -> {
151152
// runTestError()
152153
}
154+
155+
KeyEvent.VK_R -> {
156+
if (isCtrlPressed) {
157+
toolService.refenceOverlayTool.enabled.value = !toolService.refenceOverlayTool.enabled.value
158+
}
159+
}
160+
161+
162+
KeyEvent.VK_G -> {
163+
if (isCtrlPressed) {
164+
toolService.gridTool.enabled.value = !toolService.gridTool.enabled.value
165+
}
166+
}
167+
168+
169+
KeyEvent.VK_Q -> {
170+
if (isCtrlPressed) {
171+
toolService.currentTool.value = TerrainPickTool
172+
}
173+
}
174+
153175
}
154176
}
155177

composeApp/src/jvmMain/kotlin/ua/valeriishymchuk/lobmapeditor/render/context/RenderContext.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ data class RenderContext(
2121
val selectedObjectives: List<Objective>,
2222
val selection: SelectionContext,
2323
val gridContext: GridContext,
24-
val overlayReferenceContext: OverlayReferenceContext
24+
val overlayReferenceContext: OverlayReferenceContext,
25+
val debugInfo: DebugInfo
2526
) {
2627
fun getMvp(model: Matrix4f): Matrix4f {
2728
return Matrix4f(projectionMatrix)
@@ -47,6 +48,10 @@ data class RenderContext(
4748
val positionMatrix: Matrix4f
4849
)
4950

51+
data class DebugInfo(
52+
val firstHeightColor: Vector4f,
53+
val secondHeightColor: Vector4f
54+
)
5055

5156

5257
}

composeApp/src/jvmMain/kotlin/ua/valeriishymchuk/lobmapeditor/render/program/BlobProcessorProgram.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class BlobProcessorProgram(
2525
val mvpLocation = ctx.glGetUniformLocation(program, "uMVP")
2626
val tileMapLocation = ctx.glGetUniformLocation(program, "uTileMap")
2727
val blobTextureLocation = ctx.glGetUniformLocation(program, "uBlobTexture")
28+
val shouldDrawMaskLocation = ctx.glGetUniformLocation(program, "uShouldDrawMask")
29+
val maskColorLocation = ctx.glGetUniformLocation(program, "uMaskColor")
30+
val blobMaskTextureLocation = ctx.glGetUniformLocation(program, "uBlobMask")
2831
val tileUnitLocation = ctx.glGetUniformLocation(program, "uTileUnit")
2932
val mapSizeLocation = ctx.glGetUniformLocation(program, "uMapSize")
3033
val colorTintLocation = ctx.glGetUniformLocation(program, "uColorTint")
@@ -145,6 +148,16 @@ class BlobProcessorProgram(
145148
ctx.glActiveTexture(GL.GL_TEXTURE0 + 1)
146149
ctx.glBindTexture(GL3.GL_TEXTURE_2D_ARRAY, data.blobTexture)
147150
ctx.glUniform1i(blobTextureLocation, 1)
151+
152+
val mask = data.mask
153+
ctx.glUniform1i(shouldDrawMaskLocation, if(mask != null ) 1 else 0)
154+
if (mask != null) {
155+
ctx.glActiveTexture(GL.GL_TEXTURE0 + 2)
156+
ctx.glBindTexture(GL3.GL_TEXTURE_2D_ARRAY, mask.blobMask)
157+
ctx.glUniform1i(blobMaskTextureLocation, 2)
158+
ctx.glUniform4fv(maskColorLocation, 1, floatArrayOf(mask.maskColor.x, mask.maskColor.y, mask.maskColor.z, mask.maskColor.w), 0)
159+
}
160+
148161
// if (maskTextureLocation >= 0) // handling the fact that mask texute location can be discarded by compiler because its not being used
149162
// ctx.applyTexture(maskTextureLocation, 2, data.maskTexture)
150163

@@ -176,21 +189,30 @@ class BlobProcessorProgram(
176189
val tileUnit: Vector2f,
177190
val mapSize: Vector2f, // in world units
178191
val colorTint: Vector4f,
192+
val mask: Mask?
193+
179194
) {
180195
constructor(
181196
mvp: Matrix4f,
182197
blobTexture: Int,
183198
mapTileSize: Vector2i,
184199
mapSize: Vector2i, // in world units
185200
colorTint: Vector4f,
201+
mask: Mask? = null
186202
): this(
187203
mvp,
188204
blobTexture,
189205
Vector2f(1f / mapTileSize.x, 1f / mapTileSize.y),
190206
Vector2f(mapSize.x.toFloat(), mapSize.y.toFloat()),
191207
colorTint,
208+
mask
209+
)
192210

211+
data class Mask(
212+
val blobMask: Int,
213+
val maskColor: Vector4f
193214
)
215+
194216
}
195217

196218
}

composeApp/src/jvmMain/kotlin/ua/valeriishymchuk/lobmapeditor/render/stage/BlobTileStage.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import com.jogamp.opengl.GL.GL_TRIANGLES
44
import com.jogamp.opengl.GL3
55
import org.joml.Matrix4f
66
import org.joml.Vector2i
7+
import org.joml.Vector3f
78
import org.joml.Vector4f
9+
import ua.valeriishymchuk.lobmapeditor.domain.terrain.Terrain
810
import ua.valeriishymchuk.lobmapeditor.domain.terrain.TerrainType
911
import ua.valeriishymchuk.lobmapeditor.render.context.RenderContext
1012
import ua.valeriishymchuk.lobmapeditor.render.helper.glBindVBO
@@ -50,8 +52,8 @@ class BlobTileStage(
5052

5153
val heightMap = scenario.map.terrainHeight
5254
val maxTerrain: Int = heightMap.map.flatMap { it }.distinct().max()
53-
val minTerrain: Int = heightMap.map.flatMap { it }.distinct().min() + 1
54-
55+
// val minTerrain: Int = heightMap.map.flatMap { it }.distinct().min() + 1
56+
val minTerrain: Int = heightMap.map.flatMap { it }.distinct().min()
5557
for (heightTile in minTerrain..maxTerrain) {
5658
blobProcessorProgram.setUpVBO(glCtx, tileMapVertices)
5759
blobProcessorProgram.setUpVAO(glCtx)
@@ -63,9 +65,24 @@ class BlobTileStage(
6365
Vector2i(scenario.map.widthTiles, scenario.map.heightTiles),
6466
Vector2i(scenario.map.widthPixels, scenario.map.heightPixels),
6567
Vector4f(1f),
68+
BlobProcessorProgram.Uniform.Mask(
69+
textureStorage.heightMaskBlobTexture,
70+
getTintByHeight(heightTile)
71+
)
6672
)
6773
)
6874
glCtx.glDrawArrays(GL_TRIANGLES, 0, 6)
6975
}
7076
}
77+
78+
private fun RenderContext.getTintByHeight(height: Int): Vector4f {
79+
val maxHeight = Terrain.MAX_TERRAIN_HEIGHT
80+
// val basicTint = Vector4f(Vector3f(0.1f, 0.2f, 0.1f),0.2f)
81+
// val maxTint = Vector4f(Vector3f(0.55f, 0.4f, 0.3f), 0.2f)
82+
val basicTint = debugInfo.firstHeightColor
83+
val maxTint = debugInfo.secondHeightColor
84+
val step = 1f / maxHeight
85+
return basicTint.lerp(maxTint, step * height, Vector4f())
86+
}
87+
7188
}

composeApp/src/jvmMain/kotlin/ua/valeriishymchuk/lobmapeditor/render/texture/TextureStorage.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class TextureStorage {
5252
private set
5353
var heightBlobTexture: Int = -1
5454
private set
55+
var heightMaskBlobTexture: Int = -1
56+
private set
5557
var objectiveMaskTexture: Int = -1
5658
private set
5759
var objectiveOverlayTexture: Int = -1
@@ -179,6 +181,17 @@ class TextureStorage {
179181
)
180182
heightBlobTexture = textures["tilesets/blending/height"]!!
181183

184+
loadAtlas(
185+
ctx, "tilesets/blending/height_mask",
186+
Vector2i(16),
187+
Vector2i(8, 6),
188+
ImageFilter(
189+
useClamp = true,
190+
useLinear = false
191+
)
192+
)
193+
heightMaskBlobTexture = textures["tilesets/blending/height_mask"]!!
194+
182195
loadInternalTexture(ctx, "other/arrow-body")
183196
arrowBody = textures["other/arrow-body"]!!
184197

0 commit comments

Comments
 (0)