voxel texture mapping

This commit is contained in:
Halbear 2026-09-17 21:48:04 +01:00
parent 4565188f15
commit 0074bf1d1f
7 changed files with 165 additions and 77 deletions

View file

@ -656,22 +656,12 @@ public class GameCore implements GameLogic {
return imGuiIO.getWantCaptureKeyboard();
}
Vector3f CamPos = new Vector3f();
Vector3f LastCamRotation = new Vector3f();
@Override
public void Update(EngineInstance engineInstance, long FrameDiffNanoSeconds) {
if(!PrimaryRuntime.IsServer && !RenderThread.Headless) {
Camera cam = engineInstance.scene().GetCamera();
Project3D projection = engineInstance.scene().GetProjection();
CamPos.set(cam.GetPosition());
Vector3i ChunkPos = new Vector3i((int)Math.floor(CamPos.x/ (float) VoxelChunkGenerator.CHUNK_SIZE),(int)Math.floor(CamPos.y/ (float)VoxelChunkGenerator.CHUNK_SIZE),(int)Math.floor(CamPos.z/ (float)VoxelChunkGenerator.CHUNK_SIZE));
// if(ChunkPos.x != VoxelWorldManager.LastPosition.x || ChunkPos.y != VoxelWorldManager.LastPosition.y || ChunkPos.z != VoxelWorldManager.LastPosition.z) {
// VoxelWorldManager.GenerateChunks(ChunkPos, new Vector3i(5, 5, 5));
// VoxelWorldManager.UnloadFarChunks(ChunkPos, 10);
//} else {
//}
for (int i = 0; i < VisualisedCollisionActor3D.CollisionVisuals.size(); i++) {
VisualisedCollisionActor3D.CollisionVisuals.get(i).Update();
}
for(int i = 0; i < Actor3DElement.ElementNames.size(); i++){
if( Actor3DElement.ActorElementRegistry.get(Actor3DElement.ElementNames.get(i)) == null) continue;
Actor3DElement.ActorElementRegistry.get(Actor3DElement.ElementNames.get(i)).UpdateModelMatrix();
@ -688,9 +678,16 @@ public class GameCore implements GameLogic {
float DeltaTime = (float)FrameDiffNanoSeconds/(PhysicsFrameTime*1000000f);
Camera cam = engineInstance.scene().GetCamera();
Project3D projection = engineInstance.scene().GetProjection();
Vector3f CamRot = cam.GetRotation();
Vector3i ChunkPos = new Vector3i((int)Math.floor(CamPos.x/ (float) VoxelChunkGenerator.CHUNK_SIZE),(int)Math.floor(CamPos.y/ (float)VoxelChunkGenerator.CHUNK_SIZE),(int)Math.floor(CamPos.z/ (float)VoxelChunkGenerator.CHUNK_SIZE));
VoxelWorldManager.UnloadFarChunks(ChunkPos, 12,cam.GetViewMatrix(),projection.GetProjectionMatrix());
VoxelWorldManager.GenerateChunks(ChunkPos, new Vector3i(12,6,12),cam.GetViewMatrix(),projection.GetProjectionMatrix());
if(ChunkPos.x != VoxelWorldManager.LastPosition.x || ChunkPos.y != VoxelWorldManager.LastPosition.y || ChunkPos.z != VoxelWorldManager.LastPosition.z || CamRot.x != LastCamRotation.x || CamRot.y != LastCamRotation.y || CamRot.z != LastCamRotation.z) {
VoxelWorldManager.UnloadFarChunks(ChunkPos, 20,cam.GetViewMatrix(),projection.GetProjectionMatrix());
VoxelWorldManager.GenerateChunks(ChunkPos, new Vector3i(20,8,20),cam.GetViewMatrix(),projection.GetProjectionMatrix());
} else {
VoxelWorldManager.UnloadFarChunks(ChunkPos, 64,cam.GetViewMatrix(),projection.GetProjectionMatrix());
VoxelWorldManager.GenerateChunks(ChunkPos, new Vector3i(32,12,32),cam.GetViewMatrix(),projection.GetProjectionMatrix());
}
LastCamRotation.set(CamRot);
if(PrimaryRuntime.IsServer){
/* if(UseLegacyNetworking) Server.LegacyCollectIncomingPackets();
else*/ //Server.CollectIncomingPackets();

View file

@ -70,7 +70,7 @@ public class VoxelWorldManager {
private static Vector3f min = new Vector3f();
private static Vector3f min2 = new Vector3f();
public static void GenerateChunks(Vector3i Position, Vector3i Radius, Matrix4f cameraView,Matrix4f projectionMatrix) {
public static synchronized void GenerateChunks(Vector3i Position, Vector3i Radius, Matrix4f cameraView,Matrix4f projectionMatrix) {
projectionMatrix.mul(cameraView, viewProjectionMatrix);
frustumIntersection.set(viewProjectionMatrix);
@ -190,25 +190,28 @@ public class VoxelWorldManager {
}
public static void UnloadFarChunks(Vector3i centerChunk, int unloadRadius,Matrix4f cameraView,Matrix4f projectionMatrix) {
public static synchronized void UnloadFarChunks(Vector3i centerChunk, int unloadRadius,Matrix4f cameraView,Matrix4f projectionMatrix) {
int maxDistSq = unloadRadius * unloadRadius;
projectionMatrix.mul(cameraView, viewProjectionMatrix);
frustumIntersection.set(viewProjectionMatrix);
RenderChunks.entrySet().removeIf(entry -> {
Vector3i pos = entry.getKey();
projectionMatrix.mul(cameraView, viewProjectionMatrix);
frustumIntersection.set(viewProjectionMatrix);
min.set(pos.x * CHUNK_SIZE, pos.y * CHUNK_SIZE, pos.z * CHUNK_SIZE);
max.set(min.x + CHUNK_SIZE, min.y + CHUNK_SIZE, min.z + CHUNK_SIZE);
boolean InView = frustumIntersection.testAab(min.x, min.y, min.z, max.x, max.y, max.z);
if (!InView) {
RenderChunk chunk = entry.getValue();
Resources.meshPool().free(chunk);
KnownChunks.remove(pos);
return true;
}
int dx = pos.x - centerChunk.x;
int dy = pos.y - centerChunk.y;
int dz = pos.z - centerChunk.z;
int distSq = dx * dx + dy * dy + dz * dz;
boolean InView = frustumIntersection.testAab(min.x, min.y, min.z, max.x, max.y, max.z);
if (distSq > maxDistSq || !InView) {
if (distSq > maxDistSq) {
RenderChunk chunk = entry.getValue();
Resources.meshPool().free(chunk);

View file

@ -201,12 +201,10 @@ public class LightRenderer {
private static ShaderModule[] CreateShaderModules(VulkanContext VkCtx, LightSpecConsts lightSpecConsts, boolean shadowPipeline) {
if (EngineConfig.getInstance().RecompileShaders()) {
ShaderCompiler.CompileGLSLShaderOnChange(VERTEX_SHADER_FILE_GLSL, Shaderc.shaderc_glsl_vertex_shader);
//ShaderCompiler.CompileGLSLShaderOnChange( FRAGMENT_SHADER_FILE_GLSL, Shaderc.shaderc_glsl_fragment_shader);
ShaderCompiler.CompileGLSLShaderOnChange(shadowPipeline ? FRAGMENT_SHADER_FILE_GLSL : NO_SHADOWS_FRAGMENT_SHADER_FILE_GLSL, Shaderc.shaderc_glsl_fragment_shader);
}
return new ShaderModule[]{
new ShaderModule(VkCtx, VK_SHADER_STAGE_VERTEX_BIT, VERTEX_SHADER_FILE_SPV, null),
//new ShaderModule(VkCtx, VK_SHADER_STAGE_FRAGMENT_BIT, FRAGMENT_SHADER_FILE_SPV, lightSpecConsts.getSpecInfo()),
new ShaderModule(VkCtx, VK_SHADER_STAGE_FRAGMENT_BIT, shadowPipeline ? FRAGMENT_SHADER_FILE_SPV : NO_SHADOWS_FRAGMENT_SHADER_FILE_SPV, shadowPipeline ? lightSpecConsts.getSpecInfo() : null),
};
}