Some improvements to android glitches
This commit is contained in:
parent
20092b91b2
commit
b645d44b8d
@ -8,6 +8,7 @@ import com.mojang.blaze3d.systems.RenderSystem
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder
|
||||
import com.mojang.blaze3d.vertex.BufferUploader
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat
|
||||
import com.mojang.blaze3d.vertex.VertexBuffer
|
||||
import com.mojang.blaze3d.vertex.VertexFormat
|
||||
import com.mojang.math.Matrix4f
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap
|
||||
@ -299,6 +300,10 @@ object GlitchRenderer {
|
||||
BufferUploader.drawWithShader(builder.end())
|
||||
}
|
||||
|
||||
private val colorGlitchVertexBuffer by lazy {
|
||||
VertexBuffer()
|
||||
}
|
||||
|
||||
private var colorGlitchBuff = arrayOfNulls<VideoGlitchType>(0)
|
||||
private var colorGlitchWidth = 0
|
||||
private var colorGlitchHeight = 0
|
||||
@ -334,23 +339,53 @@ object GlitchRenderer {
|
||||
|
||||
for (xBlock in 0 .. colorGlitchWidth)
|
||||
for (yBlock in 0 .. colorGlitchHeight)
|
||||
if (colorGlitchChanceMultiplier(xBlock, yBlock) < 0.99f && random.nextFloat() > colorGlitchChanceMultiplier(xBlock, yBlock) * 0.999f)
|
||||
if (colorGlitchChanceMultiplier(xBlock, yBlock) < 0.97f && random.nextFloat() > colorGlitchChanceMultiplier(xBlock, yBlock) * 0.999f)
|
||||
colorGlitchBuff[xBlock + yBlock * colorGlitchWidth] = selectGlitch().let { it[random.nextInt(0, it.size)] }
|
||||
|
||||
for (xBlock in 0 .. colorGlitchWidth)
|
||||
for (yBlock in 0 .. colorGlitchHeight)
|
||||
if (colorGlitchChanceMultiplier(xBlock, yBlock) < 0.99f && random.nextFloat() > colorGlitchChanceMultiplier(xBlock, yBlock) * 0.9999f)
|
||||
if (colorGlitchChanceMultiplier(xBlock, yBlock) < 0.97f && random.nextFloat() > colorGlitchChanceMultiplier(xBlock, yBlock) * 0.9999f)
|
||||
putMacroGlitch(xBlock, yBlock, random.nextInt(1, 5), random.nextInt(1, 5), selectGlitchQuad().let { it[random.nextInt(0, it.size)] })
|
||||
|
||||
for (xBlock in 0 .. colorGlitchWidth)
|
||||
for (yBlock in 0 .. colorGlitchHeight)
|
||||
if (colorGlitchChanceMultiplier(xBlock, yBlock) < 0.99f && random.nextFloat() > colorGlitchChanceMultiplier(xBlock, yBlock) * 0.99999f)
|
||||
if (colorGlitchChanceMultiplier(xBlock, yBlock) < 0.97f && random.nextFloat() > colorGlitchChanceMultiplier(xBlock, yBlock) * 0.99999f)
|
||||
putMacroGlitch(xBlock, yBlock, random.nextInt(1, 9), random.nextInt(1, 9), selectGlitchQuad().let { it[random.nextInt(0, it.size)] })
|
||||
|
||||
for (xBlock in 0 .. colorGlitchWidth)
|
||||
for (yBlock in 0 .. colorGlitchHeight)
|
||||
if (colorGlitchChanceMultiplier(xBlock, yBlock) < 0.99f && random.nextFloat() > colorGlitchChanceMultiplier(xBlock, yBlock) * 0.999999f)
|
||||
if (colorGlitchChanceMultiplier(xBlock, yBlock) < 0.97f && random.nextFloat() > colorGlitchChanceMultiplier(xBlock, yBlock) * 0.999999f)
|
||||
putMacroGlitch(xBlock, yBlock, random.nextInt(1, 14), random.nextInt(1, 14), selectGlitchQuad().let { it[random.nextInt(0, it.size)] })
|
||||
|
||||
val blockStepWidth = (GLITCH_BLOCK_SIZE / glitchBuffer.width) * 2.0
|
||||
val blockStepHeight = (GLITCH_BLOCK_SIZE / glitchBuffer.height) * 2.0
|
||||
|
||||
val blockStepWidthUV = GLITCH_BLOCK_SIZE / glitchBuffer.width
|
||||
val blockStepHeightUV = GLITCH_BLOCK_SIZE / glitchBuffer.height
|
||||
|
||||
val builder = tesselator.builder
|
||||
|
||||
builder.begin(VertexFormat.Mode.TRIANGLES, DefaultVertexFormat.POSITION_TEX_COLOR)
|
||||
|
||||
for (xBlock in 0 .. colorGlitchWidth) {
|
||||
for (yBlock in 0 .. colorGlitchHeight) {
|
||||
colorGlitchBuff[xBlock + yBlock * colorGlitchWidth]?.upload(
|
||||
builder = builder,
|
||||
x = -1.0 + xBlock * blockStepWidth,
|
||||
y = -1.0 + yBlock * blockStepHeight,
|
||||
width = blockStepWidth,
|
||||
height = blockStepHeight,
|
||||
u0 = xBlock * blockStepWidthUV,
|
||||
v0 = yBlock * blockStepHeightUV,
|
||||
u1 = (xBlock + 1) * blockStepWidthUV,
|
||||
v1 = (yBlock + 1) * blockStepHeightUV,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val colorGlitchBuffer = builder.end()
|
||||
colorGlitchVertexBuffer.bind()
|
||||
colorGlitchVertexBuffer.upload(colorGlitchBuffer)
|
||||
}
|
||||
|
||||
private fun makeGlitch() {
|
||||
@ -384,14 +419,6 @@ object GlitchRenderer {
|
||||
return
|
||||
}
|
||||
|
||||
if (System.nanoTime() - lastGlitch >= nextGlitch) {
|
||||
makeGlitch()
|
||||
}
|
||||
|
||||
if (System.nanoTime() - lastEncodingGlitch >= nextEncodingGlitch) {
|
||||
makeColorGlitch()
|
||||
}
|
||||
|
||||
val glitchBuffer = glitchBuffer
|
||||
val projection = RenderSystem.getProjectionMatrix()
|
||||
RenderSystem.setProjectionMatrix(Matrix4f().also { it.setIdentity() })
|
||||
@ -407,14 +434,21 @@ object GlitchRenderer {
|
||||
RenderSystem.disableDepthTest()
|
||||
RenderSystem.enableBlend()
|
||||
RenderSystem.enableTexture()
|
||||
RenderSystem.clearColor(0f, 0f, 0f, 1f)
|
||||
|
||||
if (glitchBuffer.width != minecraft.window.width || glitchBuffer.height != minecraft.window.height) {
|
||||
glitchBuffer.resize(minecraft.window.width, minecraft.window.height, Minecraft.ON_OSX)
|
||||
}
|
||||
|
||||
glitchBuffer.bindWrite(true)
|
||||
} else {
|
||||
glitchBuffer.bindWrite(true)
|
||||
RenderSystem.clearColor(0f, 0f, 0f, 1f)
|
||||
RenderSystem.clear(GlConst.GL_COLOR_BUFFER_BIT, Minecraft.ON_OSX)
|
||||
|
||||
if (System.nanoTime() - lastGlitch >= nextGlitch) {
|
||||
makeGlitch()
|
||||
}
|
||||
|
||||
if (System.nanoTime() - lastEncodingGlitch >= nextEncodingGlitch) {
|
||||
makeColorGlitch()
|
||||
}
|
||||
|
||||
// distort colors by sampling main frame buffer (raw stage)
|
||||
@ -451,42 +485,10 @@ object GlitchRenderer {
|
||||
drawVHSLineGap(((-System.currentTimeMillis() - glitchBuffer.height / 3) % glitchBuffer.height).toDouble().absoluteValue, glitchBuffer.height * 0.07)
|
||||
|
||||
// color encoding errors (encoder/transmission glitch)
|
||||
val blocksWidth = ceil(glitchBuffer.width / GLITCH_BLOCK_SIZE).toInt()
|
||||
val blocksHeight = ceil(glitchBuffer.height / GLITCH_BLOCK_SIZE).toInt()
|
||||
|
||||
if (colorGlitchWidth != blocksWidth || colorGlitchHeight != blocksHeight) {
|
||||
makeColorGlitch()
|
||||
}
|
||||
|
||||
val blockStepWidth = (GLITCH_BLOCK_SIZE / glitchBuffer.width) * 2.0
|
||||
val blockStepHeight = (GLITCH_BLOCK_SIZE / glitchBuffer.height) * 2.0
|
||||
|
||||
val blockStepWidthUV = GLITCH_BLOCK_SIZE / glitchBuffer.width
|
||||
val blockStepHeightUV = GLITCH_BLOCK_SIZE / glitchBuffer.height
|
||||
|
||||
val builder = tesselator.builder
|
||||
|
||||
builder.begin(VertexFormat.Mode.TRIANGLES, DefaultVertexFormat.POSITION_TEX_COLOR)
|
||||
|
||||
for (xBlock in 0 .. blocksWidth) {
|
||||
for (yBlock in 0 .. blocksHeight) {
|
||||
colorGlitchBuff[xBlock + yBlock * blocksWidth]?.upload(
|
||||
builder = builder,
|
||||
x = -1.0 + xBlock * blockStepWidth,
|
||||
y = -1.0 + yBlock * blockStepHeight,
|
||||
width = blockStepWidth,
|
||||
height = blockStepHeight,
|
||||
u0 = xBlock * blockStepWidthUV,
|
||||
v0 = yBlock * blockStepHeightUV,
|
||||
u1 = (xBlock + 1) * blockStepWidthUV,
|
||||
v1 = (yBlock + 1) * blockStepHeightUV,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexColorShader)
|
||||
BufferUploader.drawWithShader(builder.end())
|
||||
colorGlitchVertexBuffer.bind()
|
||||
colorGlitchVertexBuffer.drawWithShader(Matrix4f().also { it.setIdentity() }, Matrix4f().also { it.setIdentity() }, GameRenderer.getPositionTexColorShader()!!)
|
||||
|
||||
// upload final result to main frame buffer
|
||||
minecraft.mainRenderTarget.bindWrite(true)
|
||||
|
Loading…
Reference in New Issue
Block a user