-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from Lyzev/89-suggestion-depth-texture-screenshot
89 suggestion depth texture screenshot
- Loading branch information
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...zev/schizoid/feature/features/module/modules/util/ModuleRunnableDepthTextureScreenshot.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/resources/assets/schizoid/shaders/core/LinearizeDepth/LinearizeDepth_FP.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/resources/assets/schizoid/shaders/core/LinearizeDepth/LinearizeDepth_VP.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |