public static void create(){ init(); camera = new GLCamera(); window = new GLWindow(); resources = new GLResources(); if (!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW"); // create OpenGL Context window.create(); log.info("OpenGL version: " + GL11.glGetString(GL11.GL_VERSION)); // log.info("Max Geometry Uniform Blocks: " + GL11.glGetInteger(GL31.GL_MAX_GEOMETRY_UNIFORM_BLOCKS)); // log.info("Max Geometry Shader Invocations: " + GL11.glGetInteger(GL40.GL_MAX_GEOMETRY_SHADER_INVOCATIONS)); // log.info("Max Uniform Buffer Bindings: " + GL11.glGetInteger(GL31.GL_MAX_UNIFORM_BUFFER_BINDINGS)); // log.info("Max Uniform Block Size: " + GL11.glGetInteger(GL31.GL_MAX_UNIFORM_BLOCK_SIZE) + " bytes"); // log.info("Max SSBO Block Size: " + GL11.glGetInteger(GL43.GL_MAX_SHADER_STORAGE_BLOCK_SIZE) + " bytes"); // log.info("Max Image Bindings: " + GL11.glGetInteger(GL42.GL_MAX_IMAGE_UNITS)); GLUtil.init(); }
public void getTerrainPosition(){ if (isActive() && glfwGetMouseButton(BaseContext.getWindow().getId(),1) == GLFW_PRESS){ Vec3f pos = new Vec3f(0,0,0); DoubleBuffer xPos = BufferUtils.createDoubleBuffer(1); DoubleBuffer yPos = BufferUtils.createDoubleBuffer(1); glfwGetCursorPos(BaseContext.getWindow().getId(), xPos, yPos); Vec2f screenPos = new Vec2f((float) xPos.get(),(float) yPos.get()); float depth = depthmapBuffer.get((int) (BaseContext.getWindow().getWidth() * screenPos.getY() + screenPos.getX())); Vec2f w = new Vec2f(screenPos.getX()/BaseContext.getWindow().getWidth(), screenPos.getY()/BaseContext.getWindow().getHeight());
public boolean onClick() { DoubleBuffer xPos = BufferUtils.createDoubleBuffer(1); DoubleBuffer yPos = BufferUtils.createDoubleBuffer(1); glfwGetCursorPos(BaseContext.getWindow().getId(), xPos, yPos); Vec2f mousePos = new Vec2f((float) xPos.get(),(float) yPos.get()); if(pos[0].getX() < mousePos.getX() && pos[1].getX() < mousePos.getX() && pos[2].getX() > mousePos.getX() && pos[3].getX() > mousePos.getX() && pos[0].getY() < BaseContext.getWindow().getHeight() - mousePos.getY() && pos[3].getY() < BaseContext.getWindow().getHeight() - mousePos.getY() && pos[1].getY() > BaseContext.getWindow().getHeight() - mousePos.getY() && pos[2].getY() > BaseContext.getWindow().getHeight() - mousePos.getY()) { return true; } else return false; }
int err = glfwCreateWindowSurface(vkInstance.getHandle(), BaseContext.getWindow().getId(), null, pSurface);
public MotionBlur() { pixelVelocityTexture = new Texture2DNoFilterRGBA32F(BaseContext.getWindow().getWidth(), BaseContext.getWindow().getHeight()); motionBlurSceneTexture = new Texture2DStorageRGBA16F(BaseContext.getWindow().getWidth(), BaseContext.getWindow().getHeight(),1); pixelVelocityShader = PixelVelocityShader.getInstance(); motionBlurShader = MotionBlurShader.getInstance(); }
public SunLightScattering() { lightScatteringShader = SunLightScatteringShader.getInstance(); additiveBlendShader = SunLightScatteringAdditiveBlendShader.getInstance(); sunLightScatteringTexture = new Texture2DBilinearFilterRGBA16F(BaseContext.getWindow().getWidth(), BaseContext.getWindow().getHeight()); sunLightScatteringTexture.bind(); sunLightScatteringTexture.clampToEdge(); sunLightScatteringTexture.unbind(); sunLightScatteringSceneTexture = new Texture2DBilinearFilterRGBA16F(BaseContext.getWindow().getWidth(), BaseContext.getWindow().getHeight()); sunLightScatteringSceneTexture.bind(); sunLightScatteringSceneTexture.clampToEdge(); sunLightScatteringSceneTexture.unbind(); }
public DepthOfFieldBlur() { horizontalBlurShader = DepthOfFieldHorizontalBlurShader.getInstance(); verticalBlurShader = DepthOfFieldVerticalBlurShader.getInstance(); fullScreenQuad = new FullScreenQuad(); horizontalBlurSceneTexture = new Texture2DStorageRGBA16F(BaseContext.getWindow().getWidth(), BaseContext.getWindow().getHeight(),1); verticalBlurSceneTexture = new Texture2DStorageRGBA16F(BaseContext.getWindow().getWidth(), BaseContext.getWindow().getHeight(),1); lowResSceneSampler = new Texture2DBilinearFilterRGBA16F((int)(BaseContext.getWindow().getWidth()/1.2f), (int)(BaseContext.getWindow().getHeight()/1.2f)); lowResSceneSampler.bind(); lowResSceneSampler.clampToEdge(); lowResSceneSampler.unbind(); lowResFbo = new GLFramebuffer(); lowResFbo.bind(); lowResFbo.createColorTextureAttachment(lowResSceneSampler.getHandle(), 0); lowResFbo.checkStatus(); lowResFbo.unbind(); }
public void updateUniforms(GLTexture texture) { glActiveTexture(GL_TEXTURE0); texture.bind(); setUniformi("texture", 0); setUniformi("width", BaseContext.getWindow().getWidth()); setUniformi("height", BaseContext.getWindow().getHeight()); setUniformi("multisamples", BaseContext.getConfig().getMultisamples()); } }
public void render(GLTexture sceneSampler, GLTexture lightScatteringMask) { lightScatteringShader.bind(); glBindImageTexture(0, lightScatteringMask.getHandle(), 0, false, 0, GL_READ_ONLY, GL_RGBA16F); glBindImageTexture(1, sunLightScatteringTexture.getHandle(), 0, false, 0, GL_WRITE_ONLY, GL_RGBA16F); lightScatteringShader.updateUniforms(BaseContext.getWindow().getWidth(), BaseContext.getWindow().getHeight(), BaseContext.getCamera().getViewProjectionMatrix()); glDispatchCompute(BaseContext.getWindow().getWidth()/8, BaseContext.getWindow().getHeight()/8, 1); glFinish(); additiveBlendShader.bind(); glBindImageTexture(0, sunLightScatteringTexture.getHandle(), 0, false, 0, GL_READ_ONLY, GL_RGBA16F); glBindImageTexture(1, sceneSampler.getHandle(), 0, false, 0, GL_READ_ONLY, GL_RGBA16F); glBindImageTexture(2, sunLightScatteringSceneTexture.getHandle(), 0, false, 0, GL_WRITE_ONLY, GL_RGBA16F); glDispatchCompute(BaseContext.getWindow().getWidth()/8, BaseContext.getWindow().getHeight()/8, 1); glFinish(); }
public void render(GLTexture sceneSampler) { contrastShader.bind(); glBindImageTexture(0, sceneSampler.getHandle(), 0, false, 0, GL_READ_ONLY, GL_RGBA16F); glBindImageTexture(1, contrastTexture.getHandle(), 0, false, 0, GL_WRITE_ONLY, GL_RGBA16F); contrastShader.updateUniforms(contrastFactor, brightnessFactor); glDispatchCompute(BaseContext.getWindow().getWidth()/16, BaseContext.getWindow().getHeight()/16, 1); glFinish(); }
glBindImageTexture(0, sceneSampler.getHandle(), 0, false, 0, GL_READ_ONLY, GL_RGBA16F); glBindImageTexture(1, sceneBrightnessTexture.getHandle(), 0, false, 0, GL_WRITE_ONLY, GL_RGBA16F); glDispatchCompute(BaseContext.getWindow().getWidth()/8, BaseContext.getWindow().getHeight()/8, 1); glFinish(); horizontalBlurShader.updateUniforms(sceneBrightnessTexture, BaseContext.getWindow().getWidth()/2, BaseContext.getWindow().getHeight()/2); glDispatchCompute(BaseContext.getWindow().getWidth()/8, BaseContext.getWindow().getHeight()/8, 1); glFinish(); verticalBlurShader.updateUniforms(horizontalBloomBlurTexture_div2, BaseContext.getWindow().getWidth()/2, BaseContext.getWindow().getHeight()/2); glDispatchCompute(BaseContext.getWindow().getWidth()/8, BaseContext.getWindow().getHeight()/8, 1); glFinish(); horizontalBlurShader.updateUniforms(sceneBrightnessTexture, BaseContext.getWindow().getWidth()/4, BaseContext.getWindow().getHeight()/4); glDispatchCompute(BaseContext.getWindow().getWidth()/8, BaseContext.getWindow().getHeight()/8, 1); glFinish(); verticalBlurShader.updateUniforms(horizontalBloomBlurTexture_div4, BaseContext.getWindow().getWidth()/4, BaseContext.getWindow().getHeight()/4); glDispatchCompute(BaseContext.getWindow().getWidth()/8, BaseContext.getWindow().getHeight()/8, 1); glFinish(); horizontalBlurShader.updateUniforms(sceneBrightnessTexture, BaseContext.getWindow().getWidth()/8, BaseContext.getWindow().getHeight()/8); glDispatchCompute(BaseContext.getWindow().getWidth()/8, BaseContext.getWindow().getHeight()/8, 1); glFinish(); verticalBlurShader.updateUniforms(horizontalBloomBlurTexture_div8, BaseContext.getWindow().getWidth()/8, BaseContext.getWindow().getHeight()/8); glDispatchCompute(BaseContext.getWindow().getWidth()/8, BaseContext.getWindow().getHeight()/8, 1); glFinish();
public void updateUniforms(Matrix4f projectionMatrix, Matrix4f inverseViewProjectionMatrix, Matrix4f previousViewProjectionMatrix, GLTexture depthmap) { glActiveTexture(GL_TEXTURE0); depthmap.bind(); setUniformi("depthmap", 0); setUniformf("windowWidth", BaseContext.getWindow().getWidth()); setUniformf("windowHeight", BaseContext.getWindow().getHeight()); setUniform("projectionMatrix", projectionMatrix); setUniform("inverseViewProjectionMatrix", inverseViewProjectionMatrix); setUniform("previousViewProjectionMatrix", previousViewProjectionMatrix); } }
sceneBrightnessTexture = new Texture2DStorageRGBA16F(BaseContext.getWindow().getWidth(), BaseContext.getWindow().getHeight(), 1); sceneBrightnessTexture.bind(); sceneBrightnessTexture.clampToEdge(); sceneBrightnessTexture.unbind(); additiveBlendBloomTexture = new Texture2DStorageRGBA16F(BaseContext.getWindow().getWidth(), BaseContext.getWindow().getHeight(), 1); bloomSceneTexture = new Texture2DStorageRGBA16F(BaseContext.getWindow().getWidth(), BaseContext.getWindow().getHeight(), 1); horizontalBloomBlurTexture_div2 = new Texture2DNoFilterRGBA16F(BaseContext.getWindow().getWidth()/2, BaseContext.getWindow().getHeight()/2); horizontalBloomBlurTexture_div2.bind(); horizontalBloomBlurTexture_div2.clampToEdge(); horizontalBloomBlurTexture_div2.unbind(); verticalBloomBlurTexture_div2 = new Texture2DStorageRGBA16F(BaseContext.getWindow().getWidth()/2, BaseContext.getWindow().getHeight()/2, 1); verticalBloomBlurTexture_div2.bind(); verticalBloomBlurTexture_div2.clampToEdge(); verticalBloomBlurTexture_div2.unbind(); horizontalBloomBlurTexture_div4 = new Texture2DStorageRGBA16F(BaseContext.getWindow().getWidth()/4, BaseContext.getWindow().getHeight()/4, 1); horizontalBloomBlurTexture_div4.bind(); horizontalBloomBlurTexture_div4.clampToEdge(); horizontalBloomBlurTexture_div4.unbind();