foliage work
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
4d934873c3
commit
cc51e4c908
@ -1113,6 +1113,7 @@ Change grass texture
|
||||
Fix allocations on FoliageChunk child iterations
|
||||
Reduce near clip to remove flickering on far chunks
|
||||
Complete overhaul of foliage management
|
||||
Fix foliage inconsistently placing on varied terrain
|
||||
|
||||
|
||||
# TODO
|
||||
|
||||
@ -276,7 +276,7 @@ public class FoliageCell {
|
||||
*/
|
||||
protected void generate(){
|
||||
boolean shouldGenerate = false;
|
||||
if(voxelPos.y + 1 >= ServerTerrainChunk.CHUNK_DIMENSION){
|
||||
if(!Globals.clientDrawCellManager.hasGeneratedPhysics(worldPos.x, worldPos.y, worldPos.z)){
|
||||
return;
|
||||
}
|
||||
ChunkData data = Globals.clientTerrainManager.getChunkDataAtWorldPoint(worldPos,ChunkData.NO_STRIDE);
|
||||
@ -285,61 +285,38 @@ public class FoliageCell {
|
||||
}
|
||||
//get foliage types supported
|
||||
List<String> foliageTypesSupported = new LinkedList<String>();
|
||||
boolean airAbove = data.getType(voxelPos.x,voxelPos.y+1,voxelPos.z) == 0;
|
||||
boolean airAbove = true;
|
||||
int scale = (int)Math.pow(2,lod);
|
||||
for(int x = 0; x < scale; x++){
|
||||
for(int y = 0; y < scale; y++){
|
||||
for(int z = 0; z < scale; z++){
|
||||
List<String> currentList = Globals.gameConfigCurrent.getVoxelData().getTypeFromId(data.getType(voxelPos)).getAmbientFoliage();
|
||||
if(voxelPos.y + y >= ServerTerrainChunk.CHUNK_DIMENSION){
|
||||
continue;
|
||||
}
|
||||
List<String> currentList = Globals.gameConfigCurrent.getVoxelData().getTypeFromId(data.getType(new Vector3i(voxelPos).add(x,y,z))).getAmbientFoliage();
|
||||
if(currentList == null){
|
||||
continue;
|
||||
}
|
||||
foliageTypesSupported.addAll(currentList);
|
||||
airAbove = data.getType(voxelPos.x,voxelPos.y+1,voxelPos.z) == 0;
|
||||
airAbove = data.getType(voxelPos.x + x,voxelPos.y + y + 1,voxelPos.z + z) == 0;
|
||||
if(foliageTypesSupported != null && foliageTypesSupported.size() > 0 && airAbove){
|
||||
shouldGenerate = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(shouldGenerate){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(shouldGenerate){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(shouldGenerate){
|
||||
Entity oldEntity = this.modelEntity;
|
||||
//create entity
|
||||
this.modelEntity = EntityCreationUtils.createClientSpatialEntity();
|
||||
FoliageModel.clientCreateFoliageChunkEntity(foliageTypesSupported,scale,this.modelEntity,this.getRealPos(),worldPos,voxelPos,null,null);
|
||||
//get type
|
||||
// String foliageTypeName = foliageTypesSupported.get(placementRandomizer.nextInt() % foliageTypesSupported.size());
|
||||
// FoliageType foliageType = Globals.gameConfigCurrent.getFoliageMap().getFoliage(foliageTypeName);
|
||||
|
||||
// //create cell and buffer
|
||||
// ByteBuffer buffer = BufferUtils.createByteBuffer(TARGET_FOLIAGE_PER_CELL * SINGLE_FOLIAGE_DATA_SIZE_BYTES);
|
||||
// if(buffer.capacity() < TARGET_FOLIAGE_PER_CELL * SINGLE_FOLIAGE_DATA_SIZE_BYTES){
|
||||
// LoggerInterface.loggerEngine.WARNING("Failed to allocate data for foliage cell! " + buffer.limit());
|
||||
// }
|
||||
// FloatBuffer floatBufferView = buffer.asFloatBuffer();
|
||||
// int drawCount = 0;
|
||||
// for(int x = 0; x < scale; x++){
|
||||
// for(int y = 0; y < scale; y++){
|
||||
// for(int z = 0; z < scale; z++){
|
||||
// drawCount = drawCount + this.insertBlades(x, y, z, floatBufferView, data);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// // drawCount = drawCount + this.insertBlades(0, 0, 0, floatBufferView, data);
|
||||
// if(drawCount > 0){
|
||||
// buffer.position(0);
|
||||
// buffer.limit(TARGET_FOLIAGE_PER_CELL * SINGLE_FOLIAGE_DATA_SIZE_BYTES);
|
||||
// //construct data texture
|
||||
// Texture dataTexture = new Texture(Globals.renderingEngine.getOpenGLState(),buffer,SINGLE_FOLIAGE_DATA_SIZE_BYTES / 4,TARGET_FOLIAGE_PER_CELL);
|
||||
|
||||
// //create entity
|
||||
// this.modelEntity = EntityCreationUtils.createClientSpatialEntity();
|
||||
|
||||
// TextureInstancedActor.attachTextureInstancedActor(this.modelEntity, foliageType.getGraphicsTemplate().getModel().getPath(), vertexPath, fragmentPath, dataTexture, drawCount);
|
||||
// ClientEntityUtils.initiallyPositionEntity(this.modelEntity, this.getRealPos(), new Quaterniond());
|
||||
// EntityUtils.getScale(this.modelEntity).set(1,1,1);
|
||||
// //add ambient foliage behavior tree
|
||||
// AmbientFoliage.attachAmbientFoliageTree(this.modelEntity, 1.0f, foliageType.getGrowthModel().getGrowthRate());
|
||||
// }
|
||||
FoliageModel.clientCreateFoliageChunkEntity(foliageTypesSupported,scale,this.modelEntity,this.getRealPos(),worldPos,voxelPos,notifyTarget,oldEntity);
|
||||
} else {
|
||||
this.homogenous = true;
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ public class FoliageModel {
|
||||
/**
|
||||
* The interval to space along
|
||||
*/
|
||||
static final int TARGET_FOLIAGE_SPACING = 50;
|
||||
static final int TARGET_FOLIAGE_SPACING = 25;
|
||||
|
||||
/**
|
||||
* The target number of foliage to place per cell
|
||||
@ -58,12 +58,12 @@ public class FoliageModel {
|
||||
/**
|
||||
* The length of the ray to ground test with
|
||||
*/
|
||||
static final float RAY_LENGTH = 1.0f;
|
||||
static final float RAY_LENGTH = 2.5f;
|
||||
|
||||
/**
|
||||
* The height above the chunk to start from when sampling downwards
|
||||
*/
|
||||
static final float SAMPLE_START_HEIGHT = 0.5f;
|
||||
static final float SAMPLE_START_HEIGHT = 1.0f;
|
||||
|
||||
/**
|
||||
* The ID of the air voxel
|
||||
@ -86,6 +86,11 @@ public class FoliageModel {
|
||||
*/
|
||||
static final int SINGLE_FOLIAGE_DATA_SIZE_BYTES = 3 * 4 + 2 * 4;
|
||||
|
||||
/**
|
||||
* Offset to sample by
|
||||
*/
|
||||
static final float SAMPLE_OFFSET = 0.499f;
|
||||
|
||||
/**
|
||||
* Vertex shader path
|
||||
*/
|
||||
@ -137,19 +142,41 @@ public class FoliageModel {
|
||||
}
|
||||
FloatBuffer floatBufferView = buffer.asFloatBuffer();
|
||||
int drawCount = 0;
|
||||
Vector3i currWorldPos = new Vector3i();
|
||||
Vector3i currVoxelPos = new Vector3i(voxelPos);
|
||||
Vector3d currRealPos = new Vector3d();
|
||||
for(int x = 0; x < scale; x++){
|
||||
for(int y = 0; y < scale; y++){
|
||||
for(int z = 0; z < scale; z++){
|
||||
ChunkData data = Globals.clientTerrainManager.getChunkDataAtWorldPoint(worldPos,ChunkData.NO_STRIDE);
|
||||
if(data == null){
|
||||
for(int y = 0; y < scale; y++){
|
||||
currVoxelPos.set(voxelPos).add(x,y,z);
|
||||
currWorldPos.set(worldPos).add(
|
||||
x / ServerTerrainChunk.CHUNK_DIMENSION,
|
||||
y / ServerTerrainChunk.CHUNK_DIMENSION,
|
||||
z / ServerTerrainChunk.CHUNK_DIMENSION
|
||||
);
|
||||
currRealPos.set(
|
||||
currVoxelPos.x + currWorldPos.x * ServerTerrainChunk.CHUNK_PLACEMENT_OFFSET,
|
||||
currVoxelPos.y + currWorldPos.y * ServerTerrainChunk.CHUNK_PLACEMENT_OFFSET,
|
||||
currVoxelPos.z + currWorldPos.z * ServerTerrainChunk.CHUNK_PLACEMENT_OFFSET
|
||||
);
|
||||
ChunkData data = Globals.clientTerrainManager.getChunkDataAtWorldPoint(currWorldPos,ChunkData.NO_STRIDE);
|
||||
List<String> currentList = Globals.gameConfigCurrent.getVoxelData().getTypeFromId(data.getType(currVoxelPos)).getAmbientFoliage();
|
||||
if(currentList == null){
|
||||
continue;
|
||||
}
|
||||
drawCount = drawCount + FoliageModel.insertBlades(
|
||||
realPos, voxelPos,
|
||||
if(data.getType(currVoxelPos.x,currVoxelPos.y+1,currVoxelPos.z) != AIR_VOXEL_ID){
|
||||
continue;
|
||||
}
|
||||
int numGenerated = FoliageModel.insertBlades(
|
||||
currWorldPos, currRealPos, currVoxelPos,
|
||||
scale, placementRandomizer,
|
||||
x, y, z,
|
||||
floatBufferView, data
|
||||
);
|
||||
drawCount = drawCount + numGenerated;
|
||||
// if(numGenerated > 0){
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -187,38 +214,23 @@ public class FoliageModel {
|
||||
* @return the number of blades of grass added
|
||||
*/
|
||||
protected static int insertBlades(
|
||||
Vector3d realPos, Vector3i voxelPos,
|
||||
Vector3i worldPos, Vector3d realPos, Vector3i voxelPos,
|
||||
int scale, Random placementRandomizer,
|
||||
int vX, int vY, int vZ,
|
||||
FloatBuffer floatBufferView, ChunkData chunkData
|
||||
){
|
||||
int rVal = 0;
|
||||
|
||||
//get positions offset
|
||||
Vector3d voxelRealPos = new Vector3d(realPos).add(vX,vY,vZ);
|
||||
Vector3i currVoxelPos = new Vector3i(voxelPos).add(vX,vY,vZ);
|
||||
|
||||
//check that the current voxel even supports foliage
|
||||
boolean shouldGenerate = false;
|
||||
List<String> foliageTypesSupported = null;
|
||||
if(chunkData != null && currVoxelPos.y + 1 < ServerTerrainChunk.CHUNK_DIMENSION){
|
||||
foliageTypesSupported = Globals.gameConfigCurrent.getVoxelData().getTypeFromId(chunkData.getType(currVoxelPos)).getAmbientFoliage();
|
||||
boolean airAbove = chunkData.getType(currVoxelPos.x,currVoxelPos.y+1,currVoxelPos.z) == AIR_VOXEL_ID;
|
||||
if(foliageTypesSupported != null && airAbove){
|
||||
shouldGenerate = true;
|
||||
}
|
||||
}
|
||||
if(shouldGenerate){
|
||||
//construct simple grid to place foliage on
|
||||
Vector3d sample_00 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(voxelRealPos).add(-0.5,SAMPLE_START_HEIGHT,-0.5), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_01 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(voxelRealPos).add(-0.5,SAMPLE_START_HEIGHT, 0), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_02 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(voxelRealPos).add(-0.5,SAMPLE_START_HEIGHT, 0.5), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_10 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(voxelRealPos).add( 0,SAMPLE_START_HEIGHT,-0.5), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_11 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(voxelRealPos).add( 0,SAMPLE_START_HEIGHT, 0), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_12 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(voxelRealPos).add( 0,SAMPLE_START_HEIGHT, 0.5), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_20 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(voxelRealPos).add( 0.5,SAMPLE_START_HEIGHT,-0.5), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_21 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(voxelRealPos).add( 0.5,SAMPLE_START_HEIGHT, 0), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_22 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(voxelRealPos).add( 0.5,SAMPLE_START_HEIGHT, 0.5), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_00 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(realPos).add(-SAMPLE_OFFSET,SAMPLE_START_HEIGHT,-SAMPLE_OFFSET), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_01 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(realPos).add(-SAMPLE_OFFSET,SAMPLE_START_HEIGHT, 0), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_02 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(realPos).add(-SAMPLE_OFFSET,SAMPLE_START_HEIGHT, SAMPLE_OFFSET), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_10 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(realPos).add( 0,SAMPLE_START_HEIGHT,-SAMPLE_OFFSET), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_11 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(realPos).add( 0,SAMPLE_START_HEIGHT, 0), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_12 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(realPos).add( 0,SAMPLE_START_HEIGHT, SAMPLE_OFFSET), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_20 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(realPos).add( SAMPLE_OFFSET,SAMPLE_START_HEIGHT,-SAMPLE_OFFSET), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_21 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(realPos).add( SAMPLE_OFFSET,SAMPLE_START_HEIGHT, 0), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
Vector3d sample_22 = Globals.clientSceneWrapper.getCollisionEngine().rayCastPosition(new Vector3d(realPos).add( SAMPLE_OFFSET,SAMPLE_START_HEIGHT, SAMPLE_OFFSET), new Vector3d(0,-1,0), RAY_LENGTH);
|
||||
//get the heights of each sample
|
||||
float height_11 = (float)(sample_11 != null ? sample_11.y : 0);
|
||||
float height_00 = (float)(sample_00 != null ? sample_00.y : height_11);
|
||||
@ -308,6 +320,9 @@ public class FoliageModel {
|
||||
}
|
||||
}
|
||||
if(addBlade){
|
||||
// if(realPos.y == 20 && sample_11 != null){
|
||||
// System.out.println("asdf");
|
||||
// }
|
||||
//convert y to relative to chunk
|
||||
offsetY = offsetY - realPos.y;
|
||||
double rotVar = placementRandomizer.nextDouble() * Math.PI * 2;
|
||||
@ -324,7 +339,12 @@ public class FoliageModel {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// String message = "Failed to collide with a chunk that definitely should already exist!\n";
|
||||
// message = message + "sample pos: " + new Vector3d(realPos).add(0,SAMPLE_START_HEIGHT,0) + "\n";
|
||||
// message = message + "generated physics: " + Globals.clientDrawCellManager.hasGeneratedPhysics(worldPos.x, worldPos.y, worldPos.z) + "\n";
|
||||
// throw new Error(message);
|
||||
// }
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user