use of org.asassecreations.engine.math.vector.Vec3 in project Voxel_Game by ASasseCreations.
the class GameRenderer method render.
public static final void render(final Light sun, final Player player, final Inventory inventory) {
// Scale the sky color so that the addition of light rays look good
final Vec3 skyColor = Settings.CURRENT_SKY_COLOR.asVec3();
skyColor.scale(.5f);
// Set the clear color
Renderer.clearColor(new Color(skyColor));
// Calculate sun direction
final Vec3 sunDirection = new Vec3(sun.position);
sunDirection.negate();
sunDirection.normalise();
// Calculate sun position on the screen
final Vec2 point = get2dPoint(SunRenderer.LIGHT_POSITION, GameCamera.view, GameCamera.projection_primary, framebufferLightScatter.width, framebufferLightScatter.height);
// Calculate camera rotation vector
final Vec3 cameraRotation = BlockRaycast.ray();
cameraRotation.normalise();
// Calculate the strength of the light rays based on how much you are
// facing the sun
float strength = Vec3.dot(cameraRotation, sunDirection);
strength = Mathf.constrain(strength, 0, 1);
// Start rendering to the chunk framebuffer
framebufferChunks.bind();
Renderer.clear();
// Render the sun
SunRenderer.begin();
SunRenderer.render(sun);
SunRenderer.end();
// Render the chunks
ChunkRenderer.begin(sun);
ChunkRenderer.render();
ChunkRenderer.end();
// Render the clouds
if (UserSettings.RENDER_CLOUDS) {
CloudRenderer.begin(sun);
CloudRenderer.render(new Vec3(player.position.x, 100, player.position.z), 300);
CloudRenderer.end();
}
// Render the hand
if (UserSettings.RENDER_HAND) {
HandRenderer.begin();
HandRenderer.render(sun);
HandRenderer.end();
}
// Start rendering to the light ray framebuffer
framebufferLightScatter.bind();
// Bind everything for the godray rendering
GL30.glBindVertexArray(model.id);
GL20.glEnableVertexAttribArray(0);
// Load texture of the entire scene rendered in black
StrictTexture.activeTexture(0);
StrictTexture.bindTexture(textureChunkSceneBlack);
// Draw the light rays
lightShader.start();
lightShader.loadCenter(point);
lightShader.loadStrength(strength);
lightShader.loadRes(framebufferLightScatter.width, framebufferLightScatter.height);
// Draw
GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, model.vertexCount);
// Unbind light ray stuff
lightShader.stop();
GL30.glBindVertexArray(0);
GL20.glDisableVertexAttribArray(0);
// Bind main framebuffer for use of combining the color attachments
// together
framebufferChunks.bind();
GL20.glEnableVertexAttribArray(0);
GL30.glBindVertexArray(model.id);
// Bind textures
StrictTexture.activeTexture(0);
StrictTexture.bindTexture(textureChunkScene);
StrictTexture.activeTexture(1);
StrictTexture.bindTexture(textureLightScatter);
// Combine color attachments together
combine.start();
GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, model.vertexCount);
combine.stop();
// Unbind
GL30.glBindVertexArray(0);
GL20.glDisableVertexAttribArray(0);
// Blit the result over to the screen
framebufferChunks.blit(null, GL11.GL_COLOR_BUFFER_BIT, GL11.GL_LINEAR);
// Return to the default framebuffer for guis
FrameBufferObject.unbind();
// Render the minimap
Minimap.render(sun);
// Render other guis
GameStateGuis.render(inventory);
}
use of org.asassecreations.engine.math.vector.Vec3 in project Voxel_Game by ASasseCreations.
the class ChunkSystem method checkLeftClick.
public static final void checkLeftClick(final Inventory inventory) {
final Vec3 block = BlockRaycast.cast();
if (block != null) {
final Chunk chunk = Chunk.getChunk((int) Math.floor(block.x / Chunk.H_SIZE), (int) Math.floor(block.z / Chunk.H_SIZE));
if (chunk != null) {
final Vector3f blockToSet = Chunk.getBlockCoordinates(block.x, block.y, block.z);
if (chunk.blocks[(int) blockToSet.x][(int) blockToSet.y][(int) blockToSet.z] != null && !chunk.blocks[(int) blockToSet.x][(int) blockToSet.y][(int) blockToSet.z].preset.breakable)
return;
inventory.addBlock(chunk.blocks[(int) blockToSet.x][(int) blockToSet.y][(int) blockToSet.z].preset);
chunk.blocks[(int) blockToSet.x][(int) blockToSet.y][(int) blockToSet.z] = null;
chunk.modified.put(new Vector3f((int) blockToSet.x, (int) blockToSet.y, (int) blockToSet.z), -1);
{
final int cx = chunk.x;
final int cz = chunk.z;
addToQueues(chunk);
addToQueues(Chunk.getChunk(cx - 1, cz));
addToQueues(Chunk.getChunk(cx + 1, cz));
addToQueues(Chunk.getChunk(cx, cz - 1));
addToQueues(Chunk.getChunk(cx, cz + 1));
}
}
}
}
use of org.asassecreations.engine.math.vector.Vec3 in project Voxel_Game by ASasseCreations.
the class ChunkMinimapRenderer method render.
public static final void render() {
shader.start();
Renderer.blendFunction(BlendFunction.NONE);
for (final Chunk chunk : Chunk.CHUNKS) {
if (chunk.model == null || !chunk.render)
continue;
GL30.glBindVertexArray(chunk.model.id);
GL20.glEnableVertexAttribArray(0);
GL20.glEnableVertexAttribArray(1);
GL20.glEnableVertexAttribArray(2);
shader.loadTransformationMatrix(MatrixCreation.createTransformationMatrix(new Vec3(chunk.x * Chunk.H_SIZE, 0, chunk.z * Chunk.H_SIZE), new Vec3(), new Vec3(1, 1, 1)));
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, chunk.model.vertexCount);
GL20.glDisableVertexAttribArray(0);
GL20.glDisableVertexAttribArray(1);
GL20.glDisableVertexAttribArray(2);
GL30.glBindVertexArray(0);
}
shader.stop();
}
use of org.asassecreations.engine.math.vector.Vec3 in project Voxel_Game by ASasseCreations.
the class Minimap method render.
public static void render(final Light sun) {
minimapCamera.position = new Vec3(GameCamera.position);
minimapCamera.position.y = GameCamera.position.y + 20;
minimapCamera.rotation.x = 90;
minimapCamera.rotation.y = GameCamera.rotation.y;
final float r = 32;
final float l = -32;
final float n = 1;
final float f = 128;
final float t = 32;
final float b = -32;
final Mat4 matrix = new Mat4();
matrix.setIdentity();
matrix.m00 = 2f / (r - l);
matrix.m11 = 2f / (t - b);
matrix.m22 = -2f / (f - n);
matrix.m30 = -(r + l) / (r - l);
matrix.m31 = -(t + b) / (t - b);
matrix.m32 = -(f + n) / (f - n);
framebuffer.bind();
Renderer.clear();
ChunkMinimapRenderer.begin(sun, matrix, minimapCamera);
ChunkMinimapRenderer.render();
ChunkMinimapRenderer.end();
FrameBufferObject.unbind();
}
use of org.asassecreations.engine.math.vector.Vec3 in project Voxel_Game by ASasseCreations.
the class CloudShader method loadLogSettings.
public final void loadLogSettings(final Color skyColor, final float density, final float gradient) {
loadFloat("density", density);
loadFloat("gradient", gradient);
loadVector("skyColor", new Vec3(skyColor.getRed(), skyColor.getGreen(), skyColor.getBlue()));
}
Aggregations