Search in sources :

Example 1 with GameWindow

use of io.xol.chunkstories.api.rendering.GameWindow in project chunkstories-core by Hugobros3.

the class GBuffersOpaquePass method render.

@Override
public void render(RenderingInterface renderingInterface) {
    if (fbo != null) {
        GameWindow gameWindow = pipeline.getRenderingInterface().getWindow();
        renderingInterface.getRenderTargetManager().setConfiguration(fbo);
        renderingInterface.getRenderTargetManager().clearBoundRenderTargetAll();
        // Set fixed-function parameters
        renderingInterface.setDepthTestMode(DepthTestMode.LESS_OR_EQUAL);
        renderingInterface.setBlendMode(BlendMode.DISABLED);
        renderingInterface.setCullingMode(CullingMode.COUNTERCLOCKWISE);
        Shader opaqueBlocksShader = renderingInterface.useShader("blocks_opaque");
        Texture2D blocksAlbedoTexture = gameWindow.getClient().getContent().voxels().textures().getDiffuseAtlasTexture();
        Texture2D blocksNormalTexture = gameWindow.getClient().getContent().voxels().textures().getNormalAtlasTexture();
        Texture2D blocksMaterialTexture = gameWindow.getClient().getContent().voxels().textures().getMaterialAtlasTexture();
        renderingInterface.bindAlbedoTexture(blocksAlbedoTexture);
        renderingInterface.bindNormalTexture(blocksNormalTexture);
        renderingInterface.bindMaterialTexture(blocksMaterialTexture);
        renderingInterface.bindTexture2D("lightColors", renderingInterface.textures().getTexture("./textures/environement/light.png"));
        renderingInterface.bindTexture2D("vegetationColorTexture", worldRenderer.getWorld().getGenerator().getEnvironment().getGrassTexture(renderingInterface));
        // renderingInterface.bindTexture2D("vegetationColorTexture", getGrassTexture());
        // Set texturing arguments
        blocksAlbedoTexture.setTextureWrapping(false);
        blocksAlbedoTexture.setLinearFiltering(false);
        blocksAlbedoTexture.setMipMapping(false);
        blocksAlbedoTexture.setMipmapLevelsRange(0, 4);
        blocksNormalTexture.setTextureWrapping(false);
        blocksNormalTexture.setLinearFiltering(false);
        blocksNormalTexture.setMipMapping(false);
        blocksNormalTexture.setMipmapLevelsRange(0, 4);
        blocksMaterialTexture.setTextureWrapping(false);
        blocksMaterialTexture.setLinearFiltering(false);
        blocksMaterialTexture.setMipMapping(false);
        blocksMaterialTexture.setMipmapLevelsRange(0, 4);
        // World stuff
        opaqueBlocksShader.setUniform1f("mapSize", world.getSizeInChunks() * 32);
        opaqueBlocksShader.setUniform1f("overcastFactor", world.getWeather());
        opaqueBlocksShader.setUniform1f("wetness", world.getGenerator().getEnvironment().getWorldWetness(renderingInterface.getCamera().getCameraPosition()));
        opaqueBlocksShader.setUniform1f("time", worldRenderer.getAnimationTimer());
        opaqueBlocksShader.setUniform1f("animationTimer", worldRenderer.getAnimationTimer());
        opaqueBlocksShader.setUniform2f("screenSize", gameWindow.getWidth(), gameWindow.getHeight());
        renderingInterface.getCamera().setupShader(opaqueBlocksShader);
        renderingInterface.setObjectMatrix(new Matrix4f());
        worldRenderer.getChunksRenderer().renderChunks(renderingInterface);
        worldRenderer.getChunksRenderer().renderChunksExtras(renderingInterface);
        worldRenderer.getEntitiesRenderer().renderEntities(renderingInterface);
        worldRenderer.getParticlesRenderer().renderParticles(renderingInterface);
    }
}
Also used : GameWindow(io.xol.chunkstories.api.rendering.GameWindow) Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Matrix4f(org.joml.Matrix4f) Shader(io.xol.chunkstories.api.rendering.shader.Shader)

Example 2 with GameWindow

use of io.xol.chunkstories.api.rendering.GameWindow in project chunkstories by Hugobros3.

the class LoginPrompt method connect.

private void connect() {
    if (usernameForm.getText().equals("OFFLINE")) {
        Client.offline = true;
        Client.username = "OfflineUser" + (int) (Math.random() * 1000);
        gameWindow.setLayer(new MainMenu(gameWindow, parentLayer));
    } else {
        logging_in = true;
        RequestResultAction postAction = (result) -> {
            gameWindow.getClient().logger().debug("Received login answer");
            logging_in = false;
            if (result == null) {
                failed_login = true;
                message = "Can't connect to server.";
                return;
            }
            if (result.startsWith("ok")) {
                String session = result.split(":")[1];
                Client.username = usernameForm.getText();
                Client.session_key = session;
                Client.getInstance().getConfiguration().getOption("client.login.auto").trySetting("ok");
                Client.getInstance().getConfiguration().getOption("client.login.username").trySetting(usernameForm.getText());
                Client.getInstance().getConfiguration().getOption("client.login.password").trySetting(passwordForm.getText());
                if (Client.username.equals("Gobrosse") || Client.username.equals("kektest")) {
                    ClientLimitations.isDebugAllowed = true;
                }
                // If the user didn't opt-out, look for crash files and upload those
                if (Client.getInstance().getConfiguration().getStringOption("client.game.log-policy").equals("send")) {
                    JavaCrashesUploader t = new JavaCrashesUploader(Client.getInstance());
                    t.start();
                }
                can_next = true;
            } else if (result.startsWith("ko")) {
                failed_login = true;
                String reason = result.split(":")[1];
                if (reason.equals("notpremium"))
                    message = ("User is not premium");
                else if (reason.equals("invalidcredentials"))
                    message = ("Invalid credentials");
            } else {
                message = ("Unknown error");
            }
        };
        new SimplePostRequest("https://chunkstories.xyz/api/login.php", "user=" + usernameForm.getText() + "&pass=" + passwordForm.getText(), postAction);
    }
}
Also used : RequestResultAction(io.xol.chunkstories.net.http.RequestResultAction) JavaCrashesUploader(io.xol.chunkstories.bugsreporter.JavaCrashesUploader) LanguageSelectionScreen(io.xol.chunkstories.gui.layer.config.LanguageSelectionScreen) ObjectRenderer(io.xol.chunkstories.renderer.opengl.util.ObjectRenderer) Layer(io.xol.chunkstories.api.gui.Layer) ClientLimitations(io.xol.chunkstories.client.ClientLimitations) RenderingInterface(io.xol.chunkstories.api.rendering.RenderingInterface) SimplePostRequest(io.xol.chunkstories.net.http.SimplePostRequest) BaseButton(io.xol.chunkstories.api.gui.elements.BaseButton) GuiElement(io.xol.chunkstories.api.gui.GuiElement) InputText(io.xol.chunkstories.api.gui.elements.InputText) Client(io.xol.chunkstories.client.Client) Input(io.xol.chunkstories.api.input.Input) GameWindow(io.xol.chunkstories.api.rendering.GameWindow) FocusableGuiElement(io.xol.chunkstories.api.gui.FocusableGuiElement) Vector4f(org.joml.Vector4f) RequestResultAction(io.xol.chunkstories.net.http.RequestResultAction) SimplePostRequest(io.xol.chunkstories.net.http.SimplePostRequest) JavaCrashesUploader(io.xol.chunkstories.bugsreporter.JavaCrashesUploader)

Example 3 with GameWindow

use of io.xol.chunkstories.api.rendering.GameWindow 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);
}
Also used : GameWindow(io.xol.chunkstories.api.rendering.GameWindow) Vector3dc(org.joml.Vector3dc) Matrix4f(org.joml.Matrix4f) Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Vector3f(org.joml.Vector3f) Shader(io.xol.chunkstories.api.rendering.shader.Shader)

Example 4 with GameWindow

use of io.xol.chunkstories.api.rendering.GameWindow 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);
    }
}
Also used : GameWindow(io.xol.chunkstories.api.rendering.GameWindow) Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Matrix4f(org.joml.Matrix4f) Voxel(io.xol.chunkstories.api.voxel.Voxel) Shader(io.xol.chunkstories.api.rendering.shader.Shader)

Aggregations

GameWindow (io.xol.chunkstories.api.rendering.GameWindow)4 Shader (io.xol.chunkstories.api.rendering.shader.Shader)3 Texture2D (io.xol.chunkstories.api.rendering.textures.Texture2D)3 Matrix4f (org.joml.Matrix4f)3 FocusableGuiElement (io.xol.chunkstories.api.gui.FocusableGuiElement)1 GuiElement (io.xol.chunkstories.api.gui.GuiElement)1 Layer (io.xol.chunkstories.api.gui.Layer)1 BaseButton (io.xol.chunkstories.api.gui.elements.BaseButton)1 InputText (io.xol.chunkstories.api.gui.elements.InputText)1 Input (io.xol.chunkstories.api.input.Input)1 RenderingInterface (io.xol.chunkstories.api.rendering.RenderingInterface)1 Voxel (io.xol.chunkstories.api.voxel.Voxel)1 JavaCrashesUploader (io.xol.chunkstories.bugsreporter.JavaCrashesUploader)1 Client (io.xol.chunkstories.client.Client)1 ClientLimitations (io.xol.chunkstories.client.ClientLimitations)1 LanguageSelectionScreen (io.xol.chunkstories.gui.layer.config.LanguageSelectionScreen)1 RequestResultAction (io.xol.chunkstories.net.http.RequestResultAction)1 SimplePostRequest (io.xol.chunkstories.net.http.SimplePostRequest)1 ObjectRenderer (io.xol.chunkstories.renderer.opengl.util.ObjectRenderer)1 Vector3dc (org.joml.Vector3dc)1