Skip to content

Commit

Permalink
Merge pull request #147 from Lyzev/146-bug-drop-shadow-alpha
Browse files Browse the repository at this point in the history
fixed bug
  • Loading branch information
Lyzev authored Jun 15, 2024
2 parents 3de92c9 + 9398d5c commit 7c932c9
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 61 deletions.
21 changes: 18 additions & 3 deletions src/main/kotlin/dev/lyzev/api/imgui/render/ImGuiRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ object ImGuiRenderer : EventListener {
/**
* The framebuffer used for rendering the blur.
*/
private val fbo = WrappedFramebuffer()
private val bloom = WrappedFramebuffer()
private val fbo = WrappedFramebuffer("ImGuiRendererFBO")
private val mask = WrappedFramebuffer("ImGuiRendererMask")

/**
* Renders ImGui.
Expand Down Expand Up @@ -86,7 +86,21 @@ object ImGuiRenderer : EventListener {
if (ModuleToggleableBlur.isEnabled) {
fbo.endWrite()

BlurHelper.draw(fbo, false, true)
RenderSystem.disableCull()
RenderSystem.defaultBlendFunc()
RenderSystem.enableBlend()
mask.clear()
mask.beginWrite(false)
ShaderPassThrough.bind()
RenderSystem.activeTexture(GL13.GL_TEXTURE0)
fbo.beginRead()
ShaderPassThrough["Tex0"] = 0
ShaderPassThrough["Scale"] = 1f
ShaderPassThrough["Alpha"] = false
Shader.drawFullScreen()
ShaderPassThrough.unbind()

BlurHelper.draw(mask, useDefaultFbo = true)

RenderSystem.disableCull()
RenderSystem.defaultBlendFunc()
Expand All @@ -99,6 +113,7 @@ object ImGuiRenderer : EventListener {
fbo.beginRead()
ShaderPassThrough["Tex0"] = 0
ShaderPassThrough["Scale"] = 1f
ShaderPassThrough["Alpha"] = true
Shader.drawFullScreen()
ShaderPassThrough.unbind()

Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/dev/lyzev/api/opengl/shader/Shader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ abstract class ShaderCompute(
RenderSystem.bindTexture(texture)
ShaderPassThrough["Tex0"] = 0
ShaderPassThrough["Scale"] = 1f
ShaderPassThrough["Alpha"] = true
drawFullScreen()
ShaderPassThrough.unbind()
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/dev/lyzev/api/opengl/shader/Shaders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ object ShaderLinearizeDepth : ShaderVertexFragment("LinearizeDepth")

object ShaderThreshold : ShaderVertexFragment("Threshold")
object ShaderBlend : ShaderVertexFragment("Blend")
object ShaderFlip : ShaderVertexFragment("Flip")

object ShaderReflection : ShaderVertexFragment("Reflection")

Expand Down Expand Up @@ -268,6 +267,7 @@ object ShaderGameOfLife : ShaderCompute("GameOfLife", 32, 1, 1) {
after.beginRead()
ShaderPassThrough["Tex0"] = 0
ShaderPassThrough["Scale"] = 1f
ShaderPassThrough["Alpha"] = true
drawFullScreen()
ShaderPassThrough.unbind()
}
Expand Down Expand Up @@ -307,8 +307,8 @@ object ShaderGameOfLife : ShaderCompute("GameOfLife", 32, 1, 1) {

override fun init() {
super.init()
before = WrappedFramebuffer(size, linear = false)
after = WrappedFramebuffer(size, linear = false)
before = WrappedFramebuffer("GameOfLife+Before", size, linear = false)
after = WrappedFramebuffer("GameOfLife+After", size, linear = false)
queueGenPixels = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ object ModuleToggleableMediaPlayer : ModuleToggleableRenderImGuiContent(
BlurHelper.mode.blur.output.beginRead()
ShaderPassThrough["Tex0"] = 0
ShaderPassThrough["Scale"] = 1f
ShaderPassThrough["Alpha"] = true
Shader.drawFullScreen()
ShaderPassThrough.unbind()
mc.framebuffer.beginWrite(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@

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

import com.mojang.blaze3d.systems.RenderSystem
import dev.lyzev.api.opengl.WrappedFramebuffer
import dev.lyzev.api.opengl.clear
import dev.lyzev.api.opengl.shader.Shader
import dev.lyzev.api.opengl.shader.ShaderFlip
import dev.lyzev.api.setting.settings.slider
import dev.lyzev.schizoid.Schizoid
import dev.lyzev.schizoid.feature.IFeature
Expand All @@ -18,7 +15,6 @@ import imgui.ImGui.*
import net.fabricmc.loader.api.FabricLoader
import net.minecraft.client.MinecraftClient
import net.minecraft.util.Util
import org.lwjgl.opengl.GL13
import kotlin.math.ceil

object ModuleToggleableRearView :
Expand All @@ -31,7 +27,6 @@ object ModuleToggleableRearView :
val size by slider("Size", "The size of the rear view.", 15, 5, 100, "%%")

private val rearView = WrappedFramebuffer(useDepth = true)
private val flippedRearView = WrappedFramebuffer()

// net/minecraft/client/MinecraftClient takePanorama (Ljava/io/File;II)Lnet/minecraft/text/Text;
private fun renderRearView(width: Int, height: Int) {
Expand All @@ -57,30 +52,13 @@ object ModuleToggleableRearView :

if (rearView.viewportWidth != width || rearView.viewportHeight != height)
rearView.resize(width, height, MinecraftClient.IS_SYSTEM_MAC)
if (flippedRearView.viewportWidth != width || flippedRearView.viewportHeight != height)
flippedRearView.resize(width, height, MinecraftClient.IS_SYSTEM_MAC)

rearView.clear()
rearView.beginWrite(true)
mc.gameRenderer.renderWorld(
if (mc.paused) mc.pausedTickDelta else mc.renderTickCounter.tickDelta,
Util.getMeasuringTimeNano()
)

RenderSystem.disableCull()
RenderSystem.defaultBlendFunc()
RenderSystem.enableBlend()

flippedRearView.clear()
flippedRearView.beginWrite(true)
ShaderFlip.bind()
RenderSystem.activeTexture(GL13.GL_TEXTURE0)
rearView.beginRead()
ShaderFlip["Tex0"] = 0
Shader.drawFullScreen()
ShaderFlip.unbind()

RenderSystem.enableCull()
} catch (e: Exception) {
Schizoid.logger.error(e)
} finally {
Expand All @@ -103,7 +81,7 @@ object ModuleToggleableRearView :
renderRearView(width.toInt(), height.toInt())
val cursorPos = getCursorScreenPos()
dummy(width, height)
getWindowDrawList().addImageRounded(flippedRearView.colorAttachment, cursorPos.x, cursorPos.y, cursorPos.x + width, cursorPos.y + height, 0f, 0f, 1f, 1f, -1, 5f)
getWindowDrawList().addImageRounded(rearView.colorAttachment, cursorPos.x, cursorPos.y, cursorPos.x + width, cursorPos.y + height, 0f, 1f, 1f, 0f, -1, 5f)
}

override val shouldHandleEvents: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ uniform bool Alpha;

void main() {
color = texture(Tex1, uv);
if (color.a == 0) {
if (color.a == 0.0) {
color = texture(Tex0, uv);
}
if (!Alpha && color.a > 0) {
color.a = 1;
if (!Alpha && color.a > 0.0) {
color.a = 1.0;
}
}
15 changes: 0 additions & 15 deletions src/main/resources/assets/schizoid/shaders/core/Flip/Flip_FP.glsl

This file was deleted.

14 changes: 0 additions & 14 deletions src/main/resources/assets/schizoid/shaders/core/Flip/Flip_VP.glsl

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ in vec2 uv;
out vec4 color;

uniform sampler2D Tex0;
uniform bool Alpha;

void main() {
color = texture(Tex0, uv);
if (!Alpha && color.a > 0.0) {
color.a = 1.0;
}
}

0 comments on commit 7c932c9

Please sign in to comment.