Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

89 suggestion depth texture screenshot #90

Merged
merged 2 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/kotlin/dev/lyzev/api/opengl/shader/Shaders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ object ShaderAdd : ShaderVertexFragment("Add")
object ShaderPassThrough : ShaderVertexFragment("PassThrough")

object ShaderDepth : ShaderVertexFragment("Depth")
object ShaderLinearizeDepth : ShaderVertexFragment("LinearizeDepth")

object ShaderThreshold : ShaderVertexFragment("Threshold")
object ShaderBlend : ShaderVertexFragment("Blend")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2024. Schizoid
* All rights reserved.
*/

package dev.lyzev.schizoid.feature.features.module.modules.util

import com.mojang.blaze3d.systems.RenderSystem
import dev.lyzev.api.events.Event
import dev.lyzev.api.events.EventListener
import dev.lyzev.api.events.EventRenderWorld
import dev.lyzev.api.events.on
import dev.lyzev.api.opengl.Render
import dev.lyzev.api.opengl.WrappedFramebuffer
import dev.lyzev.api.opengl.clear
import dev.lyzev.api.opengl.save
import dev.lyzev.api.opengl.shader.Shader
import dev.lyzev.api.opengl.shader.ShaderLinearizeDepth
import dev.lyzev.api.setting.settings.text
import dev.lyzev.schizoid.feature.IFeature
import dev.lyzev.schizoid.feature.features.module.ModuleRunnable
import net.minecraft.client.render.GameRenderer
import org.lwjgl.opengl.GL13.GL_TEXTURE0

object ModuleRunnableDepthTextureScreenshot : ModuleRunnable(
"Depth Texture Screenshot", "Takes a screenshot of the depth texture.", category = IFeature.Category.UTIL
), EventListener {

private val fbo = WrappedFramebuffer()
private var isTakingScreenshot = false

override fun invoke(): String? {
if (isTakingScreenshot) {
return "Already taking a screenshot."
} else
isTakingScreenshot = true
return null
}

override val shouldHandleEvents: Boolean
get() = isTakingScreenshot

init {
on<EventRenderWorld>(Event.Priority.HIGHEST) {
isTakingScreenshot = false
Render.store()
RenderSystem.disableCull()
RenderSystem.defaultBlendFunc()
RenderSystem.enableBlend()

fbo.clear()
fbo.beginWrite(true)

ShaderLinearizeDepth.bind()
RenderSystem.activeTexture(GL_TEXTURE0)
RenderSystem.bindTexture(mc.framebuffer.depthAttachment)
ShaderLinearizeDepth["Tex0"] = 0
ShaderLinearizeDepth["Near"] = GameRenderer.CAMERA_DEPTH
ShaderLinearizeDepth["Far"] = mc.gameRenderer.farPlaneDistance
Shader.drawFullScreen()
ShaderLinearizeDepth.unbind()

RenderSystem.enableCull()
Render.restore()

fbo.save()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2023. Schizoid
* All rights reserved.
*/

#version 330

#include "Depth.glsl"

in vec2 uv;
out vec4 color;

uniform sampler2D Tex0;
uniform float Near;
uniform float Far;

void main() {
// Read in depth value from depth texture
float depthValue = texture(Tex0, uv).x;

// Convert depth value to distance
float distance = linearizeDepth(depthValue, Near, Far) / Far;

color = vec4(vec3(distance), 1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2023. Schizoid
* All rights reserved.
*/

#version 330

in vec2 position;
out vec2 uv;

void main() {
gl_Position = vec4(position, 0, 1);
uv = position * .5 + .5;
}
Loading