use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories by Hugobros3.
the class FarTerrainGSMeshRenderer method renderTerrain.
@Override
public void renderTerrain(RenderingInterface renderer, ReadyVoxelMeshesMask mask) {
Shader terrainShader = renderer.useShader("terrain_blocky");
renderer.setBlendMode(BlendMode.DISABLED);
renderer.getCamera().setupShader(terrainShader);
worldRenderer.getSkyRenderer().setupShader(terrainShader);
terrainShader.setUniform1f("viewDistance", world.getClient().getConfiguration().getIntOption("client.rendering.viewDistance"));
Texture2D waterTexture = renderer.textures().getTexture("./textures/water/shallow.png");
waterTexture.setLinearFiltering(true);
waterTexture.setMipMapping(true);
Texture2D waterTexture2 = renderer.textures().getTexture("./textures/water/deep.png");
waterTexture2.setLinearFiltering(true);
waterTexture2.setMipMapping(true);
// renderer.bindCubemap("environmentCubemap", worldRenderer.renderBuffers.rbEnvironmentMap);
renderer.bindTexture2D("blockLightmap", TexturesHandler.getTexture("./textures/environement/light.png"));
Texture2D lightColors = TexturesHandler.getTexture("./textures/environement/lightcolors.png");
renderer.bindTexture2D("lightColors", lightColors);
renderer.bindTexture2D("waterNormalShallow", waterTexture);
renderer.bindTexture2D("waterNormalDeep", waterTexture2);
world.getGenerator().getEnvironment().setupShadowColors(renderer, terrainShader);
renderer.bindTexture2D("vegetationColorTexture", world.getGenerator().getEnvironment().getGrassTexture(renderer));
terrainShader.setUniform1f("mapSize", worldRenderer.getWorld().getSizeInChunks() * 32);
terrainShader.setUniform1f("animationTimer", worldRenderer.getAnimationTimer());
renderer.bindArrayTexture("heights", worldRenderer.getSummariesTexturesHolder().getHeightsArrayTexture());
renderer.bindArrayTexture("topVoxels", worldRenderer.getSummariesTexturesHolder().getTopVoxelsArrayTexture());
renderer.bindTexture1D("blocksTexturesSummary", colours.get());
if (renderer.getClient().getInputsManager().getInputByName("wireframeFarTerrain").isPressed() && ClientLimitations.isDebugAllowed)
renderer.setPolygonFillMode(PolygonFillMode.WIREFRAME);
if (!renderer.getClient().getInputsManager().getInputByName("hideFarTerrain").isPressed() && ClientLimitations.isDebugAllowed) {
renderer.setCullingMode(CullingMode.DISABLED);
// renderer.setCullingMode(CullingMode.COUNTERCLOCKWISE);
renderer.setDepthTestMode(DepthTestMode.LESS_OR_EQUAL);
Player player = Client.getInstance().getPlayer();
Location playerPosition = player.getLocation();
if (playerPosition == null)
// We won't do shit with that going on
return;
Vector2d playerCenter = new Vector2d(playerPosition.x, playerPosition.z);
int chunkX = (int) Math.floor(playerPosition.x / 32.0);
int chunkZ = (int) Math.floor(playerPosition.z / 32.0);
int regionX = chunkX / 8;
int regionZ = chunkZ / 8;
int[] lodInstanceCount = new int[detailLevels.length];
ByteBuffer[] lodByteBuffer = new ByteBuffer[detailLevels.length];
// ByteBuffer summariesAttributes = MemoryUtil.memAlloc(9 * 9 * (4 + 2 * 4));
// MemFreeByteBuffer auto_free_summariesAttributes = new MemFreeByteBuffer(summariesAttributes);
// int count = 0;
double lodBias = -0.2;
double lodExponent = 0.35;
if (!world.getClient().getConfiguration().getBooleanOption("client.rendering.hqTerrain")) {
lodBias = 0.3;
lodExponent = 0.35;
} else {
lodBias = 0.0;
lodExponent = 0.45;
}
if (mask == null) {
lodExponent = 1.0;
lodBias = 0.6;
}
Vector2d center = new Vector2d();
for (int i = -4; i <= 4; i++) for (int j = -4; j <= 4; j++) {
int regionI = regionX + i;
int regionJ = regionZ + j;
int index = worldRenderer.getSummariesTexturesHolder().getSummaryIndex(regionI, regionJ);
if (index == -1)
continue;
// For the extra row of triangles to mask the seams
int index10 = worldRenderer.getSummariesTexturesHolder().getSummaryIndex(regionI + 1, regionJ);
int index01 = worldRenderer.getSummariesTexturesHolder().getSummaryIndex(regionI, regionJ + 1);
int index11 = worldRenderer.getSummariesTexturesHolder().getSummaryIndex(regionI + 1, regionJ + 1);
if (index10 == -1 || index01 == -1 || index11 == -1)
continue;
HeightmapImplementation sum = (HeightmapImplementation) world.getRegionsSummariesHolder().getHeightmap(regionI, regionJ);
// Early out
if (sum == null || !sum.isLoaded())
continue;
if (!renderer.getCamera().isBoxInFrustrum(new CollisionBox(regionI * 256, 0, regionJ * 256, 256, 1024, /*+ sum.getHeightMipmapped(0, 0, 9)*/
256)))
continue;
for (int l = 0; l < 8; l++) for (int m = 0; m < 8; m++) {
if (mask != null) {
if (mask.shouldMaskSlab(regionI * 8 + l, regionJ * 8 + m, sum.min[l][m], sum.max[l][m]))
continue;
}
center.set(regionI * 256 + l * 32 + 16, regionJ * 256 + m * 32 + 16);
int lod = detailLevels.length - (int) ((lodBias + Math.pow(Math.min(1024, center.distance(playerCenter)) / 1024, lodExponent)) * detailLevels.length);
// System.out.println(center.distance(playerCenter));
if (lod <= 0)
lod = 0;
if (lod >= detailLevels.length)
lod = detailLevels.length - 1;
// lod = 2;
// lod = 2;
// System.out.println("lod:"+lod);
// lod = Math.random() > 0.5 ? 1 : 2;
ByteBuffer summariesAttributes = lodByteBuffer[lod];
if (summariesAttributes == null) {
summariesAttributes = MemoryUtil.memAlloc(9 * 9 * 8 * 8 * (4 + 2 * 4));
lodByteBuffer[lod] = summariesAttributes;
}
summariesAttributes.putFloat(regionI * 256 + l * 32);
summariesAttributes.putFloat(regionJ * 256 + m * 32);
summariesAttributes.put((byte) index);
summariesAttributes.put((byte) index10);
summariesAttributes.put((byte) index01);
summariesAttributes.put((byte) index11);
lodInstanceCount[lod]++;
// Always add both so lod 1 is drew under
/*if(lod != 0) {
lod = 0;
summariesAttributes = lodByteBuffer[lod];
if(summariesAttributes == null) {
summariesAttributes = MemoryUtil.memAlloc(9 * 9 * 8 * 8 * (4 + 2 * 4));
lodByteBuffer[lod] = summariesAttributes;
}
summariesAttributes.putFloat(regionI * 256 + l * 32);
summariesAttributes.putFloat(regionJ * 256 + m * 32);
summariesAttributes.put((byte)index);
summariesAttributes.put((byte)index10);
summariesAttributes.put((byte)index01);
summariesAttributes.put((byte)index11);
lodInstanceCount[lod]++;
}*/
}
}
// for(int lod = 0; lod < detailLevels.length; lod++) {
for (int lod = detailLevels.length - 1; lod >= 0; lod--) {
// Check if anything was supposed to be drew at this lod
ByteBuffer summariesAttributes = lodByteBuffer[lod];
if (summariesAttributes == null)
continue;
if (lod < 0) {
MemoryUtil.memFree(summariesAttributes);
continue;
}
// Flip buffer, box it for autodeletion, upload it
summariesAttributes.flip();
MemFreeByteBuffer auto_free_summariesAttributes = new MemFreeByteBuffer(summariesAttributes);
gridAttributes.uploadData(auto_free_summariesAttributes);
terrainShader.setUniform1i("lodLevel", lod);
terrainShader.setUniform1f("textureLodLevel", lod - 5);
terrainShader.setUniform1i("maskPresence", mask == null ? 0 : 1);
renderer.bindAttribute("vertexIn", grids[lod].asAttributeSource(VertexFormat.FLOAT, 3, 0, 0L));
renderer.bindAttribute("displacementIn", gridAttributes.asAttributeSource(VertexFormat.FLOAT, 2, (4 + 2 * 4), 0L, 1));
renderer.bindAttribute("indexIn", gridAttributes.asIntegerAttributeSource(VertexFormat.BYTE, 4, (4 + 2 * 4), 8L, 1));
renderer.draw(Primitive.POINT, 0, (detailLevels[lod] + 1) * (detailLevels[lod] + 1) * 1, lodInstanceCount[lod]);
}
}
renderer.setPolygonFillMode(PolygonFillMode.FILL);
}
use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories by Hugobros3.
the class FarTerrainMeshRenderer method renderTerrain.
public void renderTerrain(RenderingInterface renderer, ReadyVoxelMeshesMask mask) {
// Check for world updates
Vector3dc cameraPosition = renderer.getCamera().getCameraPosition();
int xCoordinates = ((int) (double) cameraPosition.x());
int zCoordinates = ((int) (double) cameraPosition.z());
xCoordinates %= world.getWorldSize();
zCoordinates %= world.getWorldSize();
if (xCoordinates < 0)
xCoordinates += world.getWorldSize();
if (zCoordinates < 0)
zCoordinates += world.getWorldSize();
int chunkCoordinatesX = xCoordinates / 32;
int chunkCoordinatesZ = zCoordinates / 32;
if (centerChunkX != chunkCoordinatesX || centerChunkZ != chunkCoordinatesZ) {
centerChunkX = chunkCoordinatesX;
centerChunkZ = chunkCoordinatesZ;
this.markFarTerrainMeshDirty();
}
// Setup shader etc
Shader terrainShader = renderer.useShader("terrain");
renderer.setBlendMode(BlendMode.DISABLED);
renderer.getCamera().setupShader(terrainShader);
worldRenderer.getSkyRenderer().setupShader(terrainShader);
terrainShader.setUniform1f("viewDistance", world.getClient().getConfiguration().getIntOption("client.rendering.viewDistance"));
Texture2D waterTexture = renderer.textures().getTexture("./textures/water/shallow.png");
waterTexture.setLinearFiltering(true);
waterTexture.setMipMapping(true);
// renderer.bindCubemap("environmentCubemap", worldRenderer.renderBuffers.rbEnvironmentMap);
renderer.bindTexture2D("blockLightmap", TexturesHandler.getTexture("./textures/environement/light.png"));
Texture2D lightColors = TexturesHandler.getTexture("./textures/environement/lightcolors.png");
renderer.bindTexture2D("lightColors", lightColors);
renderer.bindTexture2D("normalTexture", waterTexture);
world.getGenerator().getEnvironment().setupShadowColors(renderer, terrainShader);
// worldRenderer.setupShadowColors(terrainShader);
renderer.bindTexture2D("vegetationColorTexture", world.getGenerator().getEnvironment().getGrassTexture(renderer));
// renderingContext.bindTexture2D("vegetationColorTexture", worldRenderer.getGrassTexture());
terrainShader.setUniform1f("mapSize", world.getSizeInChunks() * 32);
// TODO hidden inputs ?
if (renderer.getClient().getInputsManager().getInputByName("wireframeFarTerrain").isPressed() && ClientLimitations.isDebugAllowed)
renderer.setPolygonFillMode(PolygonFillMode.WIREFRAME);
if (!renderer.getClient().getInputsManager().getInputByName("hideFarTerrain").isPressed() && ClientLimitations.isDebugAllowed)
drawTerrainBits(renderer, mask, terrainShader);
renderer.setPolygonFillMode(PolygonFillMode.FILL);
}
use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories by Hugobros3.
the class FarTerrainNoMeshRenderer method renderTerrain.
@Override
public void renderTerrain(RenderingInterface renderer, ReadyVoxelMeshesMask mask) {
Shader terrainShader = renderer.useShader("terrain");
renderer.setBlendMode(BlendMode.DISABLED);
renderer.getCamera().setupShader(terrainShader);
worldRenderer.getSkyRenderer().setupShader(terrainShader);
terrainShader.setUniform1f("viewDistance", world.getClient().getConfiguration().getIntOption("client.rendering.viewDistance"));
Texture2D waterTexture = renderer.textures().getTexture("./textures/water/shallow.png");
waterTexture.setLinearFiltering(true);
waterTexture.setMipMapping(true);
// renderer.bindCubemap("environmentCubemap", worldRenderer.renderBuffers.rbEnvironmentMap);
renderer.bindTexture2D("blockLightmap", TexturesHandler.getTexture("./textures/environement/light.png"));
Texture2D lightColors = TexturesHandler.getTexture("./textures/environement/lightcolors.png");
renderer.bindTexture2D("lightColors", lightColors);
renderer.bindTexture2D("normalTexture", waterTexture);
world.getGenerator().getEnvironment().setupShadowColors(renderer, terrainShader);
// worldRenderer.setupShadowColors(terrainShader);
renderer.bindTexture2D("vegetationColorTexture", world.getGenerator().getEnvironment().getGrassTexture(renderer));
terrainShader.setUniform1f("mapSize", worldRenderer.getWorld().getSizeInChunks() * 32);
renderer.bindArrayTexture("heights", worldRenderer.getSummariesTexturesHolder().getHeightsArrayTexture());
renderer.bindArrayTexture("topVoxels", worldRenderer.getSummariesTexturesHolder().getTopVoxelsArrayTexture());
renderer.bindTexture1D("blocksTexturesSummary", colours.get());
if (renderer.getClient().getInputsManager().getInputByName("wireframeFarTerrain").isPressed() && ClientLimitations.isDebugAllowed)
renderer.setPolygonFillMode(PolygonFillMode.WIREFRAME);
if (!renderer.getClient().getInputsManager().getInputByName("hideFarTerrain").isPressed() && ClientLimitations.isDebugAllowed) {
renderer.setCullingMode(CullingMode.COUNTERCLOCKWISE);
renderer.setDepthTestMode(DepthTestMode.LESS_OR_EQUAL);
Player player = Client.getInstance().getPlayer();
Location playerPosition = player.getLocation();
if (playerPosition == null)
// We won't do shit with that going on
return;
Vector2d playerCenter = new Vector2d(playerPosition.x, playerPosition.z);
int chunkX = (int) Math.floor(playerPosition.x / 32.0);
int chunkZ = (int) Math.floor(playerPosition.z / 32.0);
int regionX = chunkX / 8;
int regionZ = chunkZ / 8;
int[] lodInstanceCount = new int[detailLevels.length];
ByteBuffer[] lodByteBuffer = new ByteBuffer[detailLevels.length];
// ByteBuffer summariesAttributes = MemoryUtil.memAlloc(9 * 9 * (4 + 2 * 4));
// MemFreeByteBuffer auto_free_summariesAttributes = new MemFreeByteBuffer(summariesAttributes);
// int count = 0;
double lodBias = -0.0;
double lodExponent = 0.35;
if (!world.getClient().getConfiguration().getBooleanOption("client.rendering.hqTerrain")) {
lodBias = 0.4;
lodExponent = 0.35;
}
if (mask == null) {
lodExponent = 1.0;
lodBias = 0.6;
}
Vector2d center = new Vector2d();
for (int i = -4; i <= 4; i++) for (int j = -4; j <= 4; j++) {
int regionI = regionX + i;
int regionJ = regionZ + j;
int index = worldRenderer.getSummariesTexturesHolder().getSummaryIndex(regionI, regionJ);
if (index == -1)
continue;
// For the extra row of triangles to mask the seams
int index10 = worldRenderer.getSummariesTexturesHolder().getSummaryIndex(regionI + 1, regionJ);
int index01 = worldRenderer.getSummariesTexturesHolder().getSummaryIndex(regionI, regionJ + 1);
int index11 = worldRenderer.getSummariesTexturesHolder().getSummaryIndex(regionI + 1, regionJ + 1);
if (i < 4 && index10 == -1)
continue;
if (j < 4 && index01 == -1)
continue;
if (i < 4 && j < 4 && index11 == -1)
continue;
HeightmapImplementation sum = (HeightmapImplementation) world.getRegionsSummariesHolder().getHeightmap(regionI, regionJ);
// Early out
if (sum == null || !sum.isLoaded())
continue;
if (!renderer.getCamera().isBoxInFrustrum(new CollisionBox(regionI * 256, 0, regionJ * 256, 256, 1024, /*+ sum.getHeightMipmapped(0, 0, 9)*/
256)))
continue;
for (int l = 0; l < 8; l++) for (int m = 0; m < 8; m++) {
if (mask != null) {
if (mask.shouldMaskSlab(regionI * 8 + l, regionJ * 8 + m, sum.min[l][m], sum.max[l][m]))
continue;
}
center.set(regionI * 256 + l * 32 + 16, regionJ * 256 + m * 32 + 16);
int lod = detailLevels.length - (int) ((lodBias + Math.pow(Math.min(1024, center.distance(playerCenter)) / 1024, lodExponent)) * detailLevels.length);
// System.out.println(center.distance(playerCenter));
if (lod <= 0)
lod = 0;
if (lod >= detailLevels.length)
lod = detailLevels.length - 1;
// lod = 2;
// System.out.println("lod:"+lod);
// lod = Math.random() > 0.5 ? 1 : 2;
ByteBuffer summariesAttributes = lodByteBuffer[lod];
if (summariesAttributes == null) {
summariesAttributes = MemoryUtil.memAlloc(9 * 9 * 8 * 8 * (4 + 2 * 4));
lodByteBuffer[lod] = summariesAttributes;
}
summariesAttributes.putFloat(regionI * 256 + l * 32);
summariesAttributes.putFloat(regionJ * 256 + m * 32);
summariesAttributes.put((byte) index);
summariesAttributes.put((byte) index10);
summariesAttributes.put((byte) index01);
summariesAttributes.put((byte) index11);
lodInstanceCount[lod]++;
// Always add both so lod 1 is drew under
if (lod != 0) {
lod = 0;
summariesAttributes = lodByteBuffer[lod];
if (summariesAttributes == null) {
summariesAttributes = MemoryUtil.memAlloc(9 * 9 * 8 * 8 * (4 + 2 * 4));
lodByteBuffer[lod] = summariesAttributes;
}
summariesAttributes.putFloat(regionI * 256 + l * 32);
summariesAttributes.putFloat(regionJ * 256 + m * 32);
summariesAttributes.put((byte) index);
summariesAttributes.put((byte) index10);
summariesAttributes.put((byte) index01);
summariesAttributes.put((byte) index11);
lodInstanceCount[lod]++;
}
}
}
// for(int lod = 0; lod < detailLevels.length; lod++) {
for (int lod = detailLevels.length - 1; lod >= 0; lod--) {
// Check if anything was supposed to be drew at this lod
ByteBuffer summariesAttributes = lodByteBuffer[lod];
if (summariesAttributes == null)
continue;
if (lod < 0) {
MemoryUtil.memFree(summariesAttributes);
continue;
}
// Flip buffer, box it for autodeletion, upload it
summariesAttributes.flip();
MemFreeByteBuffer auto_free_summariesAttributes = new MemFreeByteBuffer(summariesAttributes);
gridAttributes.uploadData(auto_free_summariesAttributes);
terrainShader.setUniform1i("lodLevel", lod);
terrainShader.setUniform1f("textureLodLevel", lod - 5);
terrainShader.setUniform1i("maskPresence", mask == null ? 0 : 1);
renderer.bindAttribute("vertexIn", grids[lod].asAttributeSource(VertexFormat.FLOAT, 3, 0, 0L));
renderer.bindAttribute("displacementIn", gridAttributes.asAttributeSource(VertexFormat.FLOAT, 2, (4 + 2 * 4), 0L, 1));
renderer.bindAttribute("indexIn", gridAttributes.asIntegerAttributeSource(VertexFormat.BYTE, 4, (4 + 2 * 4), 8L, 1));
renderer.draw(Primitive.TRIANGLE, 0, (detailLevels[lod] + 1) * (detailLevels[lod] + 1) * 2 * 3, lodInstanceCount[lod]);
}
}
renderer.setPolygonFillMode(PolygonFillMode.FILL);
}
use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories by Hugobros3.
the class DecalsRendererImplementation method renderDecals.
public void renderDecals(RenderingInterface renderingInterface) {
for (DecalType decalType : decalsTypes.values()) {
Texture2D diffuseTexture = decalType.getTexture();
diffuseTexture.setTextureWrapping(false);
diffuseTexture.setLinearFiltering(false);
renderingInterface.bindAlbedoTexture(diffuseTexture);
if (!decalType.verticesObject.isDataPresent())
continue;
renderingInterface.bindAttribute("vertexIn", decalType.verticesObject.asAttributeSource(VertexFormat.FLOAT, 3, 4 * (3 + 2), 0));
renderingInterface.bindAttribute("texCoordIn", decalType.verticesObject.asAttributeSource(VertexFormat.FLOAT, 2, 4 * (3 + 2), 4 * 3));
renderingInterface.draw(Primitive.TRIANGLE, 0, decalType.kount);
}
WorldRenderingDecalsEvent event = new WorldRenderingDecalsEvent(world, worldRenderer, renderingInterface, this);
world.getGameContext().getPluginManager().fireEvent(event);
}
use of io.xol.chunkstories.api.rendering.textures.Texture2D in project chunkstories by Hugobros3.
the class VoxelTexturesStoreAndAtlaser method getMaterialAtlasTexture.
public Texture2D getMaterialAtlasTexture() {
Texture2D materialTexture = this.materialTexture;
if (materialTexture == null) {
materialTexture = getTextureFromBufferedImage(materialTextureImage);
this.materialTexture = materialTexture;
}
return materialTexture;
}
Aggregations