Search in sources :

Example 1 with Vec2

use of org.asassecreations.engine.math.vector.Vec2 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);
}
Also used : Vec2(org.asassecreations.engine.math.vector.Vec2) Vec3(org.asassecreations.engine.math.vector.Vec3) Color(org.asassecreations.engine.render.Color)

Example 2 with Vec2

use of org.asassecreations.engine.math.vector.Vec2 in project Voxel_Game by ASasseCreations.

the class CloudRenderer method begin.

public static final void begin(final Light sun) {
    shader.start();
    shader.loadViewMatrix(GameCamera.view);
    shader.loadLight(sun);
    shader.loadLogSettings(Settings.CURRENT_SKY_COLOR, Settings.CURRENT_FOG_SETTING.x, Settings.CURRENT_FOG_SETTING.y);
    final float time = (float) (Timings.globalTime * 0.02f);
    shader.loadTextureOffsets(new Vec2(time * Wind.DIRECTON.x, time * Wind.DIRECTON.z), new Vec2(0, 0));
    shader.loadProjectionMatrix(GameCamera.projection_primary);
    shader.stop();
    texture.bind(0);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glDepthMask(false);
}
Also used : Vec2(org.asassecreations.engine.math.vector.Vec2)

Example 3 with Vec2

use of org.asassecreations.engine.math.vector.Vec2 in project Voxel_Game by ASasseCreations.

the class GuiSystem method render.

public static final void render() {
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    Renderer.blendFunction(BlendFunction.NORMAL);
    GL11.glDepthMask(false);
    PANEL_SHADER.start();
    GL30.glBindVertexArray(model.id);
    GL20.glEnableVertexAttribArray(0);
    IMAGE_SHADER.start();
    for (final GuiImage image : GuiStorage.getImages()) if (image.isGlobalEnabled() && image.background) {
        IMAGE_SHADER.setTransformation(MatrixCreation.createTransformationMatrix(new Vec2(image.getGlobalX(), image.getGlobalY()), new Vec2(image.getGlobalWidth(), image.getGlobalHeight())));
        IMAGE_SHADER.setFlipYAxis(image.flipYAxis);
        image.texture.bind(0);
        GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, model.vertexCount);
    }
    PANEL_SHADER.start();
    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    for (final GuiPanel panel : GuiStorage.getPanels()) if (panel.isGlobalEnabled()) {
        GL11.glScissor((int) panel.getScreenX(), (int) panel.getScreenY(), (int) panel.getScreenWidth(), (int) panel.getScreenHeight());
        PANEL_SHADER.setTransformation(MatrixCreation.createTransformationMatrix(new Vec2(panel.getGlobalX(), panel.getGlobalY()), new Vec2(panel.getGlobalWidth(), panel.getGlobalHeight())));
        PANEL_SHADER.setColor(panel.color);
        GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, model.vertexCount);
    }
    GL11.glDisable(GL11.GL_SCISSOR_TEST);
    IMAGE_SHADER.start();
    for (final GuiImage image : GuiStorage.getImages()) if (image.isGlobalEnabled() && !image.background) {
        if (image.texture == null)
            continue;
        IMAGE_SHADER.setTransformation(MatrixCreation.createTransformationMatrix(new Vec2(image.getGlobalX(), image.getGlobalY()), new Vec2(image.getGlobalWidth(), image.getGlobalHeight())));
        IMAGE_SHADER.setFlipYAxis(image.flipYAxis);
        image.texture.bind(0);
        GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, model.vertexCount);
    }
    IMAGE_SHADER.stop();
    GL20.glDisableVertexAttribArray(0);
    GL30.glBindVertexArray(0);
    Renderer.blendFunction(null);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthMask(true);
}
Also used : GuiImage(org.asassecreations.engine.gui.GuiImage) Vec2(org.asassecreations.engine.math.vector.Vec2) GuiPanel(org.asassecreations.engine.gui.GuiPanel)

Example 4 with Vec2

use of org.asassecreations.engine.math.vector.Vec2 in project Voxel_Game by ASasseCreations.

the class BlockRaycast method ray.

public static Vec3 ray() {
    final Vec2 normalizedDevice = new Vec2(0, 0);
    final Vec4 clipCoords = new Vec4(normalizedDevice.x, normalizedDevice.y, -1f, 1f);
    final Vec4 eyeSpace = eyeSpace(clipCoords, -1);
    final Vec3 direction = worldSpace(eyeSpace);
    return direction;
}
Also used : Vec2(org.asassecreations.engine.math.vector.Vec2) Vec3(org.asassecreations.engine.math.vector.Vec3) Vec4(org.asassecreations.engine.math.vector.Vec4)

Example 5 with Vec2

use of org.asassecreations.engine.math.vector.Vec2 in project Voxel_Game by ASasseCreations.

the class GameRenderer method get2dPoint.

private static final Vec2 get2dPoint(final Vec3 point3D, final Mat4 viewMatrix, final Mat4 projectionMatrix, final int width, final int height) {
    final Vec4 clipSpacePos = Mat4.transform(projectionMatrix, Mat4.transform(viewMatrix, new Vec4(point3D.x, point3D.y, point3D.z, 1.0f), null), null);
    final Vec3 ndcSpacePos = new Vec3(clipSpacePos.x / clipSpacePos.w, clipSpacePos.y / clipSpacePos.w, clipSpacePos.z / clipSpacePos.w);
    final Vec2 vector = new Vec2(ndcSpacePos.x, ndcSpacePos.y);
    Vec2.add(vector, new Vec2(1, 1), vector);
    vector.x /= 2f;
    vector.y /= 2f;
    return vector;
}
Also used : Vec2(org.asassecreations.engine.math.vector.Vec2) Vec3(org.asassecreations.engine.math.vector.Vec3) Vec4(org.asassecreations.engine.math.vector.Vec4)

Aggregations

Vec2 (org.asassecreations.engine.math.vector.Vec2)5 Vec3 (org.asassecreations.engine.math.vector.Vec3)3 Vec4 (org.asassecreations.engine.math.vector.Vec4)2 GuiImage (org.asassecreations.engine.gui.GuiImage)1 GuiPanel (org.asassecreations.engine.gui.GuiPanel)1 Color (org.asassecreations.engine.render.Color)1