shader fix, terrain editing fix
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
This commit is contained in:
parent
991cef322e
commit
63a302444f
@ -22,6 +22,7 @@ uniform mat4 lightSpaceMatrix;
|
|||||||
out vec3 Normal;
|
out vec3 Normal;
|
||||||
out vec3 FragPos;
|
out vec3 FragPos;
|
||||||
out vec2 TexCoord;
|
out vec2 TexCoord;
|
||||||
|
out vec3 ViewFragPos;
|
||||||
out vec4 FragPosLightSpace;
|
out vec4 FragPosLightSpace;
|
||||||
|
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ void main() {
|
|||||||
|
|
||||||
//push frag, normal, and texture positions to fragment shader
|
//push frag, normal, and texture positions to fragment shader
|
||||||
FragPos = vec3(model * FinalVertex);
|
FragPos = vec3(model * FinalVertex);
|
||||||
|
ViewFragPos = vec3(view * model * FinalVertex);
|
||||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||||
TexCoord = aTex;
|
TexCoord = aTex;
|
||||||
|
|
||||||
|
|||||||
@ -21,6 +21,7 @@ uniform mat4 lightSpaceMatrix;
|
|||||||
//output buffers
|
//output buffers
|
||||||
out vec3 Normal;
|
out vec3 Normal;
|
||||||
out vec3 FragPos;
|
out vec3 FragPos;
|
||||||
|
out vec3 ViewFragPos;
|
||||||
out vec2 TexCoord;
|
out vec2 TexCoord;
|
||||||
out vec4 FragPosLightSpace;
|
out vec4 FragPosLightSpace;
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ void main() {
|
|||||||
|
|
||||||
//push frag, normal, and texture positions to fragment shader
|
//push frag, normal, and texture positions to fragment shader
|
||||||
FragPos = vec3(model * FinalVertex);
|
FragPos = vec3(model * FinalVertex);
|
||||||
|
ViewFragPos = vec3(view * model * FinalVertex);
|
||||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||||
TexCoord = aTex;
|
TexCoord = aTex;
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
#maven.buildNumber.plugin properties file
|
#maven.buildNumber.plugin properties file
|
||||||
#Wed Sep 18 20:37:06 EDT 2024
|
#Thu Sep 19 15:35:07 EDT 2024
|
||||||
buildNumber=338
|
buildNumber=339
|
||||||
|
|||||||
@ -15,8 +15,6 @@ TODO(?):
|
|||||||
|
|
||||||
- Building cube voxels w/ LOD
|
- Building cube voxels w/ LOD
|
||||||
|
|
||||||
- Deferred Shading Pipeline
|
|
||||||
|
|
||||||
- Audio Ray Tracing
|
- Audio Ray Tracing
|
||||||
|
|
||||||
- Hair/Cloth Simulation
|
- Hair/Cloth Simulation
|
||||||
|
|||||||
@ -807,6 +807,10 @@ Work on clustered lighting
|
|||||||
Cluster lighting completed
|
Cluster lighting completed
|
||||||
ClientPointLightComponent
|
ClientPointLightComponent
|
||||||
Small rendering info display
|
Small rendering info display
|
||||||
|
Fix terrain editing across chunk borders on server
|
||||||
|
- This is because the ray on the client doesn't intersect at the border (because the physics generation isn't working on chunk-end)
|
||||||
|
- Also because the client doesn't scan border chunks to see if they should update
|
||||||
|
Fix shader program bug with no-bone variants
|
||||||
|
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
|
|||||||
@ -233,18 +233,23 @@ public class CollisionBodyCreation {
|
|||||||
public static DBody generateBodyFromTerrainData(CollisionEngine collisionEngine, TerrainChunkData data, long categoryBits){
|
public static DBody generateBodyFromTerrainData(CollisionEngine collisionEngine, TerrainChunkData data, long categoryBits){
|
||||||
DBody body = null;
|
DBody body = null;
|
||||||
|
|
||||||
float[] vertices = new float[data.getVertices().size()];
|
int elementCount = data.getFaceElements().size();
|
||||||
|
|
||||||
|
float[] vertices = new float[elementCount * 3];
|
||||||
int vertexInserterPos = 0;
|
int vertexInserterPos = 0;
|
||||||
int[] indices = new int[data.getFaceElements().size()];
|
int[] indices = new int[elementCount];
|
||||||
int indexInserterPos = 0;
|
int indexInserterPos = 0;
|
||||||
|
|
||||||
for(float vertexValue : data.getVertices()){
|
|
||||||
vertices[vertexInserterPos] = vertexValue;
|
|
||||||
vertexInserterPos++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int element : data.getFaceElements()){
|
for(int element : data.getFaceElements()){
|
||||||
indices[indexInserterPos] = element;
|
//add a new vertex
|
||||||
|
vertices[vertexInserterPos*3+0] = data.getVertices().get(element*3+0);
|
||||||
|
vertices[vertexInserterPos*3+1] = data.getVertices().get(element*3+1);
|
||||||
|
vertices[vertexInserterPos*3+2] = data.getVertices().get(element*3+2);
|
||||||
|
vertexInserterPos = vertexInserterPos + 1;
|
||||||
|
|
||||||
|
//push faces -- instead of pushing the element directly, instead use the incrementer because we want to draw a new vertex
|
||||||
|
//there should be no vertex-sharing between triangles. This keeps the meshes from blurring texture/lighting
|
||||||
|
indices[indexInserterPos] = indexInserterPos;
|
||||||
indexInserterPos++;
|
indexInserterPos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -422,7 +422,7 @@ public class PhysicsEntityUtils {
|
|||||||
* @return The rigid body created (note, attachment has already been performed)
|
* @return The rigid body created (note, attachment has already been performed)
|
||||||
*/
|
*/
|
||||||
public static DBody clientAttachTerrainChunkRigidBody(Entity terrain, TerrainChunkData data){
|
public static DBody clientAttachTerrainChunkRigidBody(Entity terrain, TerrainChunkData data){
|
||||||
DBody terrainBody = CollisionBodyCreation.generateBodyFromTerrainData(Globals.clientSceneWrapper.getCollisionEngine(), data,Collidable.TYPE_STATIC_BIT);
|
DBody terrainBody = CollisionBodyCreation.generateBodyFromTerrainData(Globals.clientSceneWrapper.getCollisionEngine(), data, Collidable.TYPE_STATIC_BIT);
|
||||||
|
|
||||||
|
|
||||||
Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(terrainBody, new Collidable(terrain,Collidable.TYPE_TERRAIN, false));
|
Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(terrainBody, new Collidable(terrain,Collidable.TYPE_TERRAIN, false));
|
||||||
|
|||||||
@ -1,7 +1,11 @@
|
|||||||
package electrosphere.net.client.protocol;
|
package electrosphere.net.client.protocol;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
import org.joml.Vector3i;
|
||||||
|
|
||||||
import electrosphere.client.scene.ClientWorldData;
|
import electrosphere.client.scene.ClientWorldData;
|
||||||
import electrosphere.client.terrain.cache.ChunkData;
|
import electrosphere.client.terrain.cache.ChunkData;
|
||||||
@ -44,8 +48,39 @@ public class TerrainProtocol implements ClientProtocolTemplate<TerrainMessage> {
|
|||||||
Globals.clientTerrainManager.attachTerrainMessage(message);
|
Globals.clientTerrainManager.attachTerrainMessage(message);
|
||||||
break;
|
break;
|
||||||
case UPDATEVOXEL: {
|
case UPDATEVOXEL: {
|
||||||
if(Globals.clientTerrainManager.containsChunkDataAtWorldPoint(message.getworldX(), message.getworldY(), message.getworldZ())){
|
//
|
||||||
ChunkData data = Globals.clientTerrainManager.getChunkDataAtWorldPoint(message.getworldX(), message.getworldY(), message.getworldZ());
|
//find what all drawcells might be updated by this voxel update
|
||||||
|
Vector3i worldPos = new Vector3i(message.getworldX(), message.getworldY(), message.getworldZ());
|
||||||
|
List<Vector3i> positionsToUpdate = new LinkedList<Vector3i>();
|
||||||
|
positionsToUpdate.add(worldPos);
|
||||||
|
if(message.getvoxelX() < 1){
|
||||||
|
positionsToUpdate.add(new Vector3i(worldPos).sub(1,0,0));
|
||||||
|
if(message.getvoxelY() < 1){
|
||||||
|
positionsToUpdate.add(new Vector3i(worldPos).sub(1,1,0));
|
||||||
|
if(message.getvoxelZ() < 1){
|
||||||
|
positionsToUpdate.add(new Vector3i(worldPos).sub(1,1,1));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(message.getvoxelZ() < 1){
|
||||||
|
positionsToUpdate.add(new Vector3i(worldPos).sub(1,0,1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(message.getvoxelY() < 1){
|
||||||
|
positionsToUpdate.add(new Vector3i(worldPos).sub(0,1,0));
|
||||||
|
if(message.getvoxelZ() < 1){
|
||||||
|
positionsToUpdate.add(new Vector3i(worldPos).sub(0,1,1));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(message.getvoxelZ() < 1){
|
||||||
|
positionsToUpdate.add(new Vector3i(worldPos).sub(0,0,1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
//update the terrain cache
|
||||||
|
if(Globals.clientTerrainManager.containsChunkDataAtWorldPoint(worldPos.x, worldPos.y, worldPos.z)){
|
||||||
|
ChunkData data = Globals.clientTerrainManager.getChunkDataAtWorldPoint(worldPos.x, worldPos.y, worldPos.z);
|
||||||
if(data != null){
|
if(data != null){
|
||||||
data.updatePosition(
|
data.updatePosition(
|
||||||
message.getvoxelX(),
|
message.getvoxelX(),
|
||||||
@ -54,7 +89,16 @@ public class TerrainProtocol implements ClientProtocolTemplate<TerrainMessage> {
|
|||||||
message.getterrainWeight(),
|
message.getterrainWeight(),
|
||||||
message.getterrainValue()
|
message.getterrainValue()
|
||||||
);
|
);
|
||||||
Globals.drawCellManager.markUpdateable(message.getworldX(), message.getworldY(), message.getworldZ());
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
//mark all relevant drawcells as updateable
|
||||||
|
for(Vector3i worldPosToUpdate : positionsToUpdate){
|
||||||
|
if(Globals.clientTerrainManager.containsChunkDataAtWorldPoint(worldPosToUpdate.x, worldPosToUpdate.y, worldPosToUpdate.z)){
|
||||||
|
ChunkData data = Globals.clientTerrainManager.getChunkDataAtWorldPoint(worldPosToUpdate.x, worldPosToUpdate.y, worldPosToUpdate.z);
|
||||||
|
if(data != null){
|
||||||
|
Globals.drawCellManager.markUpdateable(worldPosToUpdate.x, worldPosToUpdate.y, worldPosToUpdate.z);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package electrosphere.renderer.meshgen;
|
package electrosphere.renderer.meshgen;
|
||||||
|
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
|
import java.nio.IntBuffer;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -673,7 +674,7 @@ public class TerrainChunkModelGeneration {
|
|||||||
//all normals in order, flattened as an array of floats instead of vecs
|
//all normals in order, flattened as an array of floats instead of vecs
|
||||||
List<Float> normalsFlat = new LinkedList<Float>();
|
List<Float> normalsFlat = new LinkedList<Float>();
|
||||||
//all elements of faces in order
|
//all elements of faces in order
|
||||||
List<Integer> elementsFlat = new LinkedList<Integer>();
|
LinkedList<Integer> elementsFlat = new LinkedList<Integer>();
|
||||||
//List of texture sampler values
|
//List of texture sampler values
|
||||||
List<Float> textureSamplers = new LinkedList<Float>();
|
List<Float> textureSamplers = new LinkedList<Float>();
|
||||||
//List of texture ratio values
|
//List of texture ratio values
|
||||||
@ -792,6 +793,8 @@ public class TerrainChunkModelGeneration {
|
|||||||
FloatBuffer vertexArrayBufferData = BufferUtils.createFloatBuffer(elementCount * 3);
|
FloatBuffer vertexArrayBufferData = BufferUtils.createFloatBuffer(elementCount * 3);
|
||||||
FloatBuffer normalArrayBufferData = BufferUtils.createFloatBuffer(elementCount * 3);
|
FloatBuffer normalArrayBufferData = BufferUtils.createFloatBuffer(elementCount * 3);
|
||||||
FloatBuffer textureArrayBufferData = BufferUtils.createFloatBuffer(elementCount * 2);
|
FloatBuffer textureArrayBufferData = BufferUtils.createFloatBuffer(elementCount * 2);
|
||||||
|
IntBuffer elementArrayBufferData = BufferUtils.createIntBuffer(elementCount);
|
||||||
|
int incrementer = 0;
|
||||||
for(int element : data.getFaceElements()){
|
for(int element : data.getFaceElements()){
|
||||||
//for each element, need to push vert, normal, etc
|
//for each element, need to push vert, normal, etc
|
||||||
|
|
||||||
@ -808,6 +811,11 @@ public class TerrainChunkModelGeneration {
|
|||||||
//push current uvs
|
//push current uvs
|
||||||
textureArrayBufferData.put(data.getUVs().get(element*2+0));
|
textureArrayBufferData.put(data.getUVs().get(element*2+0));
|
||||||
textureArrayBufferData.put(data.getUVs().get(element*2+1));
|
textureArrayBufferData.put(data.getUVs().get(element*2+1));
|
||||||
|
|
||||||
|
//push faces -- instead of pushing the element directly, instead use the incrementer because we want to draw a new vertex
|
||||||
|
//there should be no vertex-sharing between triangles. This keeps the meshes from blurring texture/lighting
|
||||||
|
elementArrayBufferData.put(incrementer);
|
||||||
|
incrementer++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//actually buffer vertices
|
//actually buffer vertices
|
||||||
@ -828,14 +836,17 @@ public class TerrainChunkModelGeneration {
|
|||||||
mesh.bufferTextureCoords(textureArrayBufferData, 2);
|
mesh.bufferTextureCoords(textureArrayBufferData, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//buffer element indices
|
||||||
|
if(elementArrayBufferData.position() > 0){
|
||||||
|
elementArrayBufferData.flip();
|
||||||
|
mesh.bufferFaces(elementArrayBufferData, elementCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (NullPointerException ex){
|
} catch (NullPointerException ex){
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
//alert mesh to use direct array access and set the number of elements in the direct arrays
|
|
||||||
mesh.setUseElementArray(false);
|
|
||||||
mesh.setDirectArraySize(elementCount);
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@ -2,6 +2,8 @@ package electrosphere.server.datacell;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
@ -375,6 +377,8 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
|
|||||||
loadedCells.add(groundDataCells.get(getServerDataCellKey(worldPos)));
|
loadedCells.add(groundDataCells.get(getServerDataCellKey(worldPos)));
|
||||||
cellPlayerlessFrameMap.put(groundDataCells.get(getServerDataCellKey(worldPos)),0);
|
cellPlayerlessFrameMap.put(groundDataCells.get(getServerDataCellKey(worldPos)),0);
|
||||||
loadedCellsLock.release();
|
loadedCellsLock.release();
|
||||||
|
} else {
|
||||||
|
LoggerInterface.loggerEngine.WARNING("Trying to create data cell outside world bounds! " + worldPos);
|
||||||
}
|
}
|
||||||
return groundDataCells.get(getServerDataCellKey(worldPos));
|
return groundDataCells.get(getServerDataCellKey(worldPos));
|
||||||
}
|
}
|
||||||
@ -524,14 +528,42 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
|
|||||||
terrainEditLock.acquireUninterruptibly();
|
terrainEditLock.acquireUninterruptibly();
|
||||||
//update terrain
|
//update terrain
|
||||||
serverTerrainManager.deformTerrainAtLocationToValue(worldPosition, voxelPosition, weight, type);
|
serverTerrainManager.deformTerrainAtLocationToValue(worldPosition, voxelPosition, weight, type);
|
||||||
this.createTerrainPhysicsEntities(worldPosition);
|
List<Vector3i> worldPositionsToUpdate = new LinkedList<Vector3i>();
|
||||||
//broadcast update to terrain
|
worldPositionsToUpdate.add(worldPosition);
|
||||||
ServerDataCell cell = groundDataCells.get(getServerDataCellKey(worldPosition));
|
if(voxelPosition.x < 1){
|
||||||
if(cell != null){
|
worldPositionsToUpdate.add(new Vector3i(worldPosition).sub(1,0,0));
|
||||||
cell.broadcastNetworkMessage(TerrainMessage.constructUpdateVoxelMessage(
|
if(voxelPosition.y < 1){
|
||||||
worldPosition.x, worldPosition.y, worldPosition.z,
|
worldPositionsToUpdate.add(new Vector3i(worldPosition).sub(1,1,0));
|
||||||
voxelPosition.x, voxelPosition.y, voxelPosition.z,
|
if(voxelPosition.z < 1){
|
||||||
weight, type));
|
worldPositionsToUpdate.add(new Vector3i(worldPosition).sub(1,1,1));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(voxelPosition.z < 1){
|
||||||
|
worldPositionsToUpdate.add(new Vector3i(worldPosition).sub(1,0,1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(voxelPosition.y < 1){
|
||||||
|
worldPositionsToUpdate.add(new Vector3i(worldPosition).sub(0,1,0));
|
||||||
|
if(voxelPosition.z < 1){
|
||||||
|
worldPositionsToUpdate.add(new Vector3i(worldPosition).sub(0,1,1));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(voxelPosition.z < 1){
|
||||||
|
worldPositionsToUpdate.add(new Vector3i(worldPosition).sub(0,0,1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//update all loaded cells
|
||||||
|
for(Vector3i toUpdate : worldPositionsToUpdate){
|
||||||
|
ServerDataCell cell = groundDataCells.get(getServerDataCellKey(toUpdate));
|
||||||
|
if(cell != null){
|
||||||
|
this.createTerrainPhysicsEntities(toUpdate);
|
||||||
|
cell.broadcastNetworkMessage(TerrainMessage.constructUpdateVoxelMessage(
|
||||||
|
worldPosition.x, worldPosition.y, worldPosition.z,
|
||||||
|
voxelPosition.x, voxelPosition.y, voxelPosition.z,
|
||||||
|
weight, type));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
terrainEditLock.release();
|
terrainEditLock.release();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,9 +56,9 @@ public class TerrainEditing {
|
|||||||
voxelPos.x < ServerTerrainChunk.CHUNK_DIMENSION &&
|
voxelPos.x < ServerTerrainChunk.CHUNK_DIMENSION &&
|
||||||
voxelPos.y < ServerTerrainChunk.CHUNK_DIMENSION &&
|
voxelPos.y < ServerTerrainChunk.CHUNK_DIMENSION &&
|
||||||
voxelPos.z < ServerTerrainChunk.CHUNK_DIMENSION &&
|
voxelPos.z < ServerTerrainChunk.CHUNK_DIMENSION &&
|
||||||
voxelPos.x > 0 &&
|
voxelPos.x >= 0 &&
|
||||||
voxelPos.y > 0 &&
|
voxelPos.y >= 0 &&
|
||||||
voxelPos.z > 0 &&
|
voxelPos.z >= 0 &&
|
||||||
currentPositionMagnitude > 0 &&
|
currentPositionMagnitude > 0 &&
|
||||||
(data = voxelCellManager.getChunkAtPosition(chunkPos)) != null
|
(data = voxelCellManager.getChunkAtPosition(chunkPos)) != null
|
||||||
){
|
){
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user