use of io.xol.chunkstories.api.rendering.shader.Shader in project chunkstories by Hugobros3.
the class VoxelOverlays method drawSelectionBox.
public void drawSelectionBox(RenderingInterface renderingInterface, Location location) {
if (vertexBuffer == null)
vertexBuffer = renderingInterface.newVertexBuffer();
int x = (int) (double) location.x();
int y = (int) (double) location.y();
int z = (int) (double) location.z();
CellData peek = location.getWorld().peekSafely(x, y, z);
if (peek.getVoxel() == null || peek.getVoxel().isAir())
return;
CollisionBox[] boxes = peek.getTranslatedCollisionBoxes();
// TODO: getTranslatedCollisionBoxes(voxelContext)
if (boxes == null)
return;
renderingInterface.setCullingMode(CullingMode.DISABLED);
renderingInterface.setBlendMode(BlendMode.MIX);
renderingInterface.setDepthTestMode(DepthTestMode.LESS_OR_EQUAL);
// ShadersLibrary.getShaderProgram("overlay");
Shader overlayProgram = renderingInterface.useShader("overlay");
renderingInterface.getCamera().setupShader(overlayProgram);
overlayProgram.setUniform4f("colorIn", new Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
ByteBuffer data = ByteBuffer.allocateDirect(4 * 3 * 8 * 3 * boxes.length);
data.order(ByteOrder.nativeOrder());
// FloatBuffer fb = data.asFloatBuffer();
// fb.order(ByteOrder.nativeOrder());
// float[] data = new float[3 * 8 * 6 * boxes.length];
int i = 0;
for (CollisionBox box : boxes) {
i = cubeVertices(data, i, (float) box.xpos, (float) box.ypos, (float) box.zpos, (float) box.xw, (float) box.h, (float) box.zw);
}
data.flip();
vertexBuffer.uploadData(data);
renderingInterface.bindAttribute("vertexIn", vertexBuffer.asAttributeSource(VertexFormat.FLOAT, 3));
// renderingContext.bindAttribute("vertexIn", new FloatBufferAttributeSource(data, 3));
renderingInterface.draw(Primitive.LINE, 0, boxes.length * 3 * 8);
renderingInterface.setBlendMode(BlendMode.DISABLED);
// System.out.println("k");
/*
glColor4f(1, 1, 1, 1.0f);
//GL11.glBlendFunc(GL11.GL_ONE_MINUS_SRC_COLOR, GL11.GL_ZERO);
//GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
//GL11.glBlendEquation(GL11.);
glBegin(GL_LINES);
VoxelContext bri = new VoxelContextOlder(world, x, y, z);
if (bri.getVoxel() == null)
{
System.out.println(bri.getData());
return;
}
for (CollisionBox box : bri.getVoxel().getTranslatedCollisionBoxes(world, x, y, z))
cubeVertices((float) box.xpos, (float) box.ypos, (float) box.zpos, (float) box.xw, (float) box.h, (float) box.zw);
glEnd();
glColor4f(1, 1, 1, 1);*/
}
use of io.xol.chunkstories.api.rendering.shader.Shader in project chunkstories-core by Hugobros3.
the class PostProcessPass method render.
@Override
public void render(RenderingInterface renderer) {
if (shadedBuffer != null) {
renderer.getRenderTargetManager().setConfiguration(fbo);
// renderer.getRenderTargetManager().clearBoundRenderTargetAll();
// TODO mix in the reflections earlier ?
// Texture2D bloomRendered = RenderingConfig.doBloom ? bloomRenderer.renderBloom(renderingContext) : null;
Layer layer = renderer.getWindow().getLayer();
// (layer instanceof Ingame) ? ((Ingame)layer).getPauseOverlayFade() : 0;
float pauseFade = 0.0f;
pauseFade = layer.getClass().getName().contains("Ingame") ? 0 : 1;
// We render to the screen.
// renderer.getRenderTargetManager().setConfiguration(null);
renderer.setDepthTestMode(DepthTestMode.DISABLED);
renderer.setBlendMode(BlendMode.DISABLED);
Shader postProcess = renderer.useShader("postprocess");
renderer.bindTexture2D("shadedBuffer", shadedBuffer);
renderer.bindTexture2D("zBuffer", zBuffer);
renderer.bindTexture2D("pauseOverlayTexture", renderer.textures().getTexture("./textures/gui/darker.png"));
// TODO make an underwater pass
// Voxel vox = world.peekSafely(renderingContext.getCamera().getCameraPosition()).getVoxel();
// postProcess.setUniform1f("underwater", vox.getDefinition().isLiquid() ? 1 : 0);
postProcess.setUniform1f("underwater", 0.0f);
// TODO
postProcess.setUniform1f("animationTimer", worldRenderer.getAnimationTimer());
postProcess.setUniform1f("pauseOverlayFade", pauseFade);
if (shadowPass != null && renderer.getClient().getConfiguration().getBooleanOption("client.rendering.shadows")) {
renderer.bindTexture2D("shadowMap", (Texture2D) shadowPass.resolvedOutputs.get("shadowMap"));
// System.out.println((Texture2D) shadowPass.resolvedOutputs.get("shadowMap"));
postProcess.setUniform1f("shadowMapResolution", ((Texture2D) shadowPass.resolvedOutputs.get("shadowMap")).getWidth());
postProcess.setUniform1f("shadowVisiblity", shadowPass.getShadowVisibility());
postProcess.setUniformMatrix4f("shadowMatrix", shadowPass.getShadowMatrix());
}
renderer.getCamera().setupShader(postProcess);
worldRenderer.getSkyRenderer().setupShader(postProcess);
renderer.drawFSQuad();
}
}
use of io.xol.chunkstories.api.rendering.shader.Shader in project chunkstories-core by Hugobros3.
the class ReflectionsPass method render.
@Override
public void render(RenderingInterface renderer) {
Shader reflectionsShader = renderer.useShader("reflections");
// This isn't a depth-buffered pass.
renderer.setDepthTestMode(DepthTestMode.DISABLED);
renderer.setBlendMode(BlendMode.DISABLED);
renderer.getRenderTargetManager().setConfiguration(fbo);
renderer.getRenderTargetManager().clearBoundRenderTargetAll();
// Required to execute SSR
/*renderer.bindTexture2D("shadedBuffer", worldRenderer.renderBuffers.rbShaded);
renderer.bindTexture2D("zBuffer", worldRenderer.renderBuffers.rbZBuffer);
renderer.bindTexture2D("normalBuffer", worldRenderer.renderBuffers.rbNormal);
renderer.bindTexture2D("specularityBuffer", worldRenderer.renderBuffers.rbSpecularity);
renderer.bindTexture2D("voxelLightBuffer", worldRenderer.renderBuffers.rbVoxelLight);*/
// TODO renderer.bindCubemap("environmentCubemap", worldRenderer.renderBuffers.rbEnvironmentMap);
// Matrices for screen-space transformations
renderer.getCamera().setupShader(reflectionsShader);
skyRenderer.setupShader(reflectionsShader);
// Disable depth writing and run the deal
renderer.getRenderTargetManager().setDepthMask(false);
renderer.drawFSQuad();
renderer.getRenderTargetManager().setDepthMask(true);
}
use of io.xol.chunkstories.api.rendering.shader.Shader in project chunkstories-core by Hugobros3.
the class ShadowPass method render.
public void render(RenderingInterface renderingContext) {
if (this.getShadowVisibility() == 0f)
// No shadows at night :)
return;
GameWindow gameWindow = pipeline.getRenderingInterface().getWindow();
// Resize the texture if needed
int shadowMapTextureSize = renderingContext.getClient().getConfiguration().getIntOption("client.rendering.shadowsResolution");
if (shadowDepthTexture.getWidth() != shadowMapTextureSize) {
fbo.resize(shadowMapTextureSize, shadowMapTextureSize);
}
// The size of the shadow range depends on the shadowmap resolution
int shadowRange = 128;
if (shadowMapTextureSize > 1024)
shadowRange = 192;
else if (shadowMapTextureSize > 2048)
shadowRange = 256;
int shadowDepthRange = 200;
// Builds the shadow matrix
// MatrixHelper.getOrthographicMatrix(-shadowRange, shadowRange, -shadowRange, shadowRange, -shadowDepthRange, shadowDepthRange);
Matrix4f depthProjectionMatrix = new Matrix4f().ortho(-shadowRange, shadowRange, -shadowRange, shadowRange, -shadowDepthRange, shadowDepthRange);
Matrix4f depthViewMatrix = new Matrix4f().lookAt(skyRenderer.getSunPosition(), new Vector3f(0, 0, 0), new Vector3f(0, 1, 0));
Matrix4f shadowMVP = new Matrix4f();
depthProjectionMatrix.mul(depthViewMatrix, shadowMVP);
// Matrix4f.mul(depthProjectionMatrix, depthViewMatrix, shadowMVP);
shadowMatrix = new Matrix4f(shadowMVP);
Vector3dc posd = renderingContext.getCamera().getCameraPosition();
Vector3f pos = new Vector3f((float) posd.x(), (float) posd.y(), (float) posd.z());
pos.negate();
shadowMVP.translate(pos);
// Set appropriate fixed function stuff
renderingContext.setCullingMode(CullingMode.COUNTERCLOCKWISE);
renderingContext.setBlendMode(BlendMode.DISABLED);
renderingContext.setDepthTestMode(DepthTestMode.LESS_OR_EQUAL);
// Bind relevant FBO and clear it
renderingContext.getRenderTargetManager().setConfiguration(fbo);
renderingContext.getRenderTargetManager().clearBoundRenderTargetZ(1.0f);
Shader shadowsPassShader = renderingContext.useShader("shadows");
shadowsPassShader.setUniform1f("animationTimer", worldRenderer.getAnimationTimer());
shadowsPassShader.setUniformMatrix4f("depthMVP", shadowMVP);
shadowsPassShader.setUniform1f("isUsingInstancedData", 0f);
shadowsPassShader.setUniform1f("useVoxelCoordinates", 1f);
Texture2D blocksAlbedoTexture = gameWindow.getClient().getContent().voxels().textures().getDiffuseAtlasTexture();
renderingContext.bindAlbedoTexture(blocksAlbedoTexture);
renderingContext.setObjectMatrix(null);
// We render the world from that perspective
// Hackish way of enabling the shader input for the fake "wind" effect vegetation can have
shadowsPassShader.setUniform1f("allowForWavyStuff", 1);
worldRenderer.getChunksRenderer().renderChunks(renderingContext);
// In turn, disabling it while we do the entities
shadowsPassShader.setUniform1f("allowForWavyStuff", 0);
worldRenderer.getEntitiesRenderer().renderEntities(renderingContext);
}
use of io.xol.chunkstories.api.rendering.shader.Shader in project chunkstories-core by Hugobros3.
the class WaterPass method render.
@Override
public void render(RenderingInterface renderer) {
// if(true)
// return;
renderer.setBlendMode(BlendMode.MIX);
renderer.setCullingMode(CullingMode.DISABLED);
GameWindow gameWindow = pipeline.getRenderingInterface().getWindow();
// one for computing the refracted color and putting it in shaded buffer, and another one to read it back and blend it
for (int pass = 1; pass <= 2; pass++) {
Shader liquidBlocksShader = renderer.useShader("blocks_liquid_pass" + pass);
liquidBlocksShader.setUniform1f("viewDistance", world.getClient().getConfiguration().getIntOption("client.rendering.viewDistance"));
renderer.bindTexture2D("waterNormalDeep", renderer.textures().getTexture("./textures/water/deep.png"));
renderer.bindTexture2D("waterNormalShallow", renderer.textures().getTexture("./textures/water/shallow.png"));
renderer.bindTexture2D("lightColors", renderer.textures().getTexture("./textures/environement/light.png"));
Texture2D blocksAlbedoTexture = gameWindow.getClient().getContent().voxels().textures().getDiffuseAtlasTexture();
renderer.bindAlbedoTexture(blocksAlbedoTexture);
liquidBlocksShader.setUniform2f("screenSize", gameWindow.getWidth(), gameWindow.getHeight());
skyRenderer.setupShader(liquidBlocksShader);
liquidBlocksShader.setUniform1f("animationTimer", worldRenderer.getAnimationTimer());
renderer.getCamera().setupShader(liquidBlocksShader);
// Underwater flag
Voxel vox = world.peekSafely(renderer.getCamera().getCameraPosition()).getVoxel();
liquidBlocksShader.setUniform1f("underwater", vox.getDefinition().isLiquid() ? 1 : 0);
if (pass == 1) {
renderer.getRenderTargetManager().setConfiguration(waterRefractionFbo);
renderer.getRenderTargetManager().clearBoundRenderTargetAll();
renderer.bindTexture2D("readbackAlbedoBufferTemp", albedoBuffer);
renderer.bindTexture2D("readbackVoxelLightBufferTemp", voxelLightBuffer);
renderer.bindTexture2D("readbackDepthBufferTemp", zBuffer);
renderer.getRenderTargetManager().setDepthMask(false);
} else if (pass == 2) {
renderer.getRenderTargetManager().setConfiguration(fboGBuffers);
renderer.setBlendMode(BlendMode.DISABLED);
renderer.bindTexture2D("readbackShadedBufferTemp", waterTempTexture);
renderer.getRenderTargetManager().setDepthMask(true);
}
renderer.setObjectMatrix(new Matrix4f());
worldRenderer.getChunksRenderer().renderChunks(renderer);
}
}
Aggregations