use of io.xol.chunkstories.api.rendering.shader.Shader 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.shader.Shader 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.shader.Shader in project chunkstories by Hugobros3.
the class FrametimeRenderer method draw.
public static void draw(OpenGLRenderingContext renderingContext) {
lel++;
lel %= 1024;
long elapsedTime = (System.nanoTime() - lastTime);
lastTime = System.nanoTime();
dataBB.putFloat(lel * 4, elapsedTime / 1000000f);
renderingContext.setDepthTestMode(DepthTestMode.DISABLED);
renderingContext.setBlendMode(BlendMode.MIX);
renderingContext.setCullingMode(CullingMode.DISABLED);
Shader overlayProgram = renderingContext.useShader("fps_graph");
overlayProgram.setUniform1f("currentTiming", lel);
overlayProgram.setUniform2f("screenSize", renderingContext.getWindow().getWidth(), renderingContext.getWindow().getHeight());
overlayProgram.setUniform1f("sizeInPixels", 768);
overlayProgram.setUniform1f("heightInPixels", 192);
overlayProgram.setUniform1f("xPosition", 0);
overlayProgram.setUniform1f("yPosition", 0);
overlayProgram.setUniform3f("graphColour", 0, 1, 0);
overlayProgram.setUniform1f("shade", 0.0f);
dataBB.rewind();
texture.uploadTextureData(1024, dataBB);
texture.setLinearFiltering(false);
texture.setTextureWrapping(true);
renderingContext.bindTexture1D("frametimeData", texture);
renderingContext.drawFSQuad();
renderingContext.getFontRenderer().drawStringWithShadow(renderingContext.getFontRenderer().defaultFont(), 4, 192 - 30, "Frametime (ms)", 2, 2, new Vector4f(0.0f, 1.0f, 0.0f, 1.0f));
}
use of io.xol.chunkstories.api.rendering.shader.Shader in project chunkstories by Hugobros3.
the class MemUsageRenderer method draw.
public static void draw(OpenGLRenderingContext renderingContext) {
lel++;
lel %= 1024;
// long elapsedTime = (System.nanoTime() - lastTime);
lastTime = System.nanoTime();
float totalMemoryMB = Runtime.getRuntime().totalMemory() / 1024 / 1024;
float freeMemoryMB = Runtime.getRuntime().freeMemory() / 1024 / 1024;
float usedMemoryMB = totalMemoryMB - freeMemoryMB;
dataBB.putFloat(lel * 4, usedMemoryMB / totalMemoryMB * 192f);
// System.out.println(usedMemoryMB + " / " + totalMemoryMB);
renderingContext.setDepthTestMode(DepthTestMode.DISABLED);
renderingContext.setBlendMode(BlendMode.MIX);
renderingContext.setCullingMode(CullingMode.DISABLED);
Shader overlayProgram = renderingContext.useShader("fps_graph");
overlayProgram.setUniform1f("currentTiming", lel);
overlayProgram.setUniform2f("screenSize", renderingContext.getWindow().getWidth(), renderingContext.getWindow().getHeight());
overlayProgram.setUniform1f("sizeInPixels", 768);
overlayProgram.setUniform1f("heightInPixels", 192);
overlayProgram.setUniform1f("xPosition", 0);
overlayProgram.setUniform1f("yPosition", 192 + 192);
overlayProgram.setUniform3f("graphColour", 1, 1, 0);
overlayProgram.setUniform1f("shade", 1.0f);
dataBB.rewind();
texture.uploadTextureData(1024, dataBB);
texture.setLinearFiltering(false);
texture.setTextureWrapping(true);
renderingContext.bindTexture1D("frametimeData", texture);
renderingContext.drawFSQuad();
renderingContext.getFontRenderer().drawStringWithShadow(renderingContext.getFontRenderer().defaultFont(), 4, 192 + 192 + 192 - 30, "Memory used (%" + Runtime.getRuntime().totalMemory() / 1024 / 1024 + "Mb)", 2, 2, new Vector4f(1.0f, 1.0f, 0.0f, 1.0f));
}
use of io.xol.chunkstories.api.rendering.shader.Shader in project chunkstories by Hugobros3.
the class WorldLogicTimeRenderer method draw.
public static void draw(OpenGLRenderingContext renderingContext) {
renderingContext.setDepthTestMode(DepthTestMode.DISABLED);
renderingContext.setBlendMode(BlendMode.MIX);
renderingContext.setCullingMode(CullingMode.DISABLED);
Shader overlayProgram = renderingContext.useShader("fps_graph");
overlayProgram.setUniform1f("currentTiming", lel);
overlayProgram.setUniform2f("screenSize", renderingContext.getWindow().getWidth(), renderingContext.getWindow().getHeight());
overlayProgram.setUniform1f("sizeInPixels", 768);
overlayProgram.setUniform1f("heightInPixels", 192);
overlayProgram.setUniform1f("xPosition", 0);
overlayProgram.setUniform1f("yPosition", 192);
overlayProgram.setUniform3f("graphColour", 0, 1, 1);
overlayProgram.setUniform1f("shade", 0.0f);
dataBB.rewind();
texture.uploadTextureData(1024, dataBB);
texture.setLinearFiltering(false);
texture.setTextureWrapping(true);
renderingContext.bindTexture1D("frametimeData", texture);
renderingContext.drawFSQuad();
renderingContext.getFontRenderer().drawStringWithShadow(renderingContext.getFontRenderer().defaultFont(), 4, 192 + 192 - 30, "World logic timing (ms)", 2, 2, new Vector4f(0.0f, 1.0f, 1.0f, 1.0f));
}
Aggregations