Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit b2ffbe1
Author: coderbot <coderbot16@gmail.com>
Date:   Tue Mar 23 12:40:08 2021 -0700

    Fix the placeholder normal map texture having incorrect content

commit 306b490
Author: coderbot <coderbot16@gmail.com>
Date:   Tue Mar 23 12:05:14 2021 -0700

    Add placeholder PBR textures fixing many issues with many shaderpacks (IrisShaders#130)

commit 503952c
Author: coderbot <coderbot16@gmail.com>
Date:   Tue Mar 23 10:05:28 2021 -0700

    Fix ArrayIndexOutOfBoundsException when parsing buffer clear directives
  • Loading branch information
OverlordsIII committed Mar 23, 2021
1 parent b6547d7 commit a80c001
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.coderbot.iris.layer.GbufferProgram;
import net.coderbot.iris.postprocess.CompositeRenderer;
import net.coderbot.iris.rendertarget.BuiltinNoiseTexture;
import net.coderbot.iris.rendertarget.SingleColorTexture;
import net.coderbot.iris.rendertarget.RenderTargets;
import net.coderbot.iris.shaderpack.ProgramSet;
import net.coderbot.iris.shaderpack.ProgramSource;
Expand Down Expand Up @@ -73,6 +74,8 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline {

private final EmptyShadowMapRenderer shadowMapRenderer;
private final CompositeRenderer compositeRenderer;
private final SingleColorTexture normals;
private final SingleColorTexture specular;

private final int waterId;

Expand Down Expand Up @@ -108,6 +111,25 @@ public DeferredWorldRenderingPipeline(ProgramSet programs) {
this.clearMainBuffers = renderTargets.createFramebufferWritingToMain(buffersToBeCleared);
this.baseline = renderTargets.createFramebufferWritingToMain(new int[] {0});

// Don't clobber anything in texture unit 0. It probably won't cause issues, but we're just being cautious here.
GlStateManager.activeTexture(GL20C.GL_TEXTURE2);

// Ensure that the pixel storage mode is in a sane state, otherwise the uploaded texture data will be quite
// incorrect.
//
// It is likely that this also avoids the crashes on AMD that I previously experienced with texture creation.
//
// This code is from Canvas: https://github.com/grondag/canvas/commit/f0ab652d7a8b7cc9febf0209bee15cffce9eac83
GlStateManager.pixelStore(GL20C.GL_UNPACK_ROW_LENGTH, 0);
GlStateManager.pixelStore(GL20C.GL_UNPACK_SKIP_ROWS, 0);
GlStateManager.pixelStore(GL20C.GL_UNPACK_SKIP_PIXELS, 0);
GlStateManager.pixelStore(GL20C.GL_UNPACK_ALIGNMENT, 4);

// Create some placeholder PBR textures for now
normals = new SingleColorTexture(127, 127, 255, 255);
specular = new SingleColorTexture(0, 0, 0, 0);
GlStateManager.activeTexture(GL20C.GL_TEXTURE0);

this.shadowMapRenderer = new EmptyShadowMapRenderer(2048);
this.compositeRenderer = new CompositeRenderer(programs, renderTargets, shadowMapRenderer);
}
Expand Down Expand Up @@ -337,6 +359,10 @@ public void use() {
// a given program and bind the required textures instead.
GlStateManager.activeTexture(GL15C.GL_TEXTURE15);
BuiltinNoiseTexture.bind();
GlStateManager.activeTexture(GL15C.GL_TEXTURE2);
GlStateManager.bindTexture(normals.getTextureId());
GlStateManager.activeTexture(GL15C.GL_TEXTURE3);
GlStateManager.bindTexture(specular.getTextureId());
GlStateManager.activeTexture(GL15C.GL_TEXTURE4);
GlStateManager.bindTexture(shadowMapRenderer.getDepthTextureId());
GlStateManager.activeTexture(GL15C.GL_TEXTURE5);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package net.coderbot.iris.rendertarget;

import com.mojang.blaze3d.platform.GlStateManager;
import net.coderbot.iris.gl.GlResource;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11C;
import org.lwjgl.opengl.GL13C;

import java.nio.ByteBuffer;

public class SingleColorTexture extends GlResource {
public SingleColorTexture(int red, int green, int blue, int alpha) {
super(GL11C.glGenTextures());
GlStateManager.bindTexture(getGlId());

ByteBuffer pixel = BufferUtils.createByteBuffer(4);
pixel.put((byte) red);
pixel.put((byte) green);
pixel.put((byte) blue);
pixel.put((byte) alpha);
pixel.position(0);

GL11C.glTexParameteri(GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MIN_FILTER, GL11C.GL_LINEAR);
GL11C.glTexParameteri(GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MAG_FILTER, GL11C.GL_LINEAR);
GL11C.glTexParameteri(GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_S, GL13C.GL_REPEAT);
GL11C.glTexParameteri(GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_T, GL13C.GL_REPEAT);
GL11C.glTexImage2D(GL11C.GL_TEXTURE_2D, 0, GL11C.GL_RGBA, 1, 1, 0, GL11C.GL_RGBA, GL11C.GL_UNSIGNED_BYTE, pixel);

GlStateManager.bindTexture(0);
}

public int getTextureId() {
return getGlId();
}

@Override
protected void destroyInternal() {
GL11C.glDeleteTextures(getGlId());
}
}
24 changes: 16 additions & 8 deletions src/main/java/net/coderbot/iris/shaderpack/PackDirectives.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,32 @@
import it.unimi.dsi.fastutil.ints.IntList;
import net.coderbot.iris.Iris;
import net.coderbot.iris.gl.texture.InternalTextureFormat;
import net.coderbot.iris.rendertarget.RenderTargets;

import java.util.Arrays;
import java.util.OptionalInt;

public class PackDirectives {
private InternalTextureFormat[] requestedTextureFormats;
private IntList buffersToBeCleared;
private boolean[] clearBuffers;

PackDirectives() {
requestedTextureFormats = new InternalTextureFormat[8];
requestedTextureFormats = new InternalTextureFormat[RenderTargets.MAX_RENDER_TARGETS];
Arrays.fill(requestedTextureFormats, InternalTextureFormat.RGBA);

// TODO: Don't assume that there are only 8 buffers
buffersToBeCleared = new IntArrayList(new int[]{0, 1, 2, 3, 4, 5, 6, 7});
clearBuffers = new boolean[RenderTargets.MAX_RENDER_TARGETS];
Arrays.fill(clearBuffers, true);
}

// TODO: These are currently hardcoded to work with Sildur's. They will need to be properly parsed from shaders.properties.
// Some of these values also come from individual shader files, such as the requested buffer formats.

public IntList getBuffersToBeCleared() {
IntList buffersToBeCleared = new IntArrayList();

for (int i = 0; i < clearBuffers.length; i++) {
if (clearBuffers[i]) {
buffersToBeCleared.add(i);
}
}

return buffersToBeCleared;
}

Expand All @@ -49,7 +55,9 @@ void accept(ConstDirectiveParser.ConstDirective directive) {
} else if (type == ConstDirectiveParser.Type.BOOL && key.endsWith("Clear") && value.equals("false")) {
String bufferName = key.substring(0, key.length() - "Clear".length());

bufferNameToIndex(bufferName).ifPresent(buffersToBeCleared::removeInt);
bufferNameToIndex(bufferName).ifPresent(index -> {
clearBuffers[index] = false;
});
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/coderbot/iris/texunits/TextureUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
public enum TextureUnit {
TERRAIN(0),
LIGHTMAP(1),
// TODO: Relocate this to a different texture unit, this is used by the normal map for normal shaders
OVERLAY(2);
// TODO: Relocate this to a different texture unit, this is used by depthtex0...
OVERLAY(6);

private final int samplerId;
private final int unitId;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/coderbot/iris/uniforms/CommonUniforms.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public static void addCommonUniforms(UniformHolder uniforms, IdMap idMap) {
.uniform1i(ONCE, "lightmap", TextureUnit.LIGHTMAP::getSamplerId)
.uniform1b(PER_FRAME, "hideGUI", () -> client.options.hudHidden)
.uniform1i(ONCE, "noisetex", () -> 15)
.uniform1i(ONCE, "normals", () -> 2)
.uniform1i(ONCE, "specular", () -> 3)
.uniform1i(ONCE, "shadowtex0", () -> 4)
.uniform1i(ONCE, "shadowtex1", () -> 5)
.uniform1f(PER_FRAME, "eyeAltitude", () -> Objects.requireNonNull(client.getCameraEntity()).getEyeY())
Expand Down

0 comments on commit a80c001

Please sign in to comment.