mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-08 13:26:39 +01:00
Merge remote-tracking branch 'origin/1.20/next' into 1.20/next
# Conflicts: # src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawSet.java # src/main/resources/assets/flywheel/flywheel/internal/block.vert # src/main/resources/assets/flywheel/flywheel/layout/pos_tex_normal.vert
This commit is contained in:
commit
c74fbda15f
30 changed files with 785 additions and 594 deletions
|
@ -0,0 +1,13 @@
|
||||||
|
package com.jozufozu.flywheel.api.material;
|
||||||
|
|
||||||
|
public enum DepthTest {
|
||||||
|
OFF,
|
||||||
|
NEVER,
|
||||||
|
LESS,
|
||||||
|
EQUAL,
|
||||||
|
LEQUAL,
|
||||||
|
GREATER,
|
||||||
|
NOTEQUAL,
|
||||||
|
GEQUAL,
|
||||||
|
ALWAYS,
|
||||||
|
}
|
|
@ -10,22 +10,12 @@ public interface Material {
|
||||||
|
|
||||||
MaterialShaders shaders();
|
MaterialShaders shaders();
|
||||||
|
|
||||||
|
FogShader fog();
|
||||||
|
|
||||||
|
CutoutShader cutout();
|
||||||
|
|
||||||
ResourceLocation baseTexture();
|
ResourceLocation baseTexture();
|
||||||
|
|
||||||
/**
|
|
||||||
* Should this material be rendered with diffuse lighting?
|
|
||||||
*
|
|
||||||
* @return {@code true} if this material should be rendered with diffuse lighting.
|
|
||||||
*/
|
|
||||||
boolean diffuse();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should this material be rendered with block/sky lighting?
|
|
||||||
*
|
|
||||||
* @return {@code true} if this material should be rendered with block/sky lighting.
|
|
||||||
*/
|
|
||||||
boolean lighting();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should this material have linear filtering applied to the diffuse sampler?
|
* Should this material have linear filtering applied to the diffuse sampler?
|
||||||
*
|
*
|
||||||
|
@ -33,22 +23,36 @@ public interface Material {
|
||||||
*/
|
*/
|
||||||
boolean blur();
|
boolean blur();
|
||||||
|
|
||||||
|
boolean mipmap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should this material be rendered with backface culling?
|
* Should this material be rendered with backface culling?
|
||||||
*
|
*
|
||||||
* @return {@code true} if this material should be rendered with backface culling.
|
* @return {@code true} if this material should be rendered with backface culling.
|
||||||
*/
|
*/
|
||||||
boolean backfaceCull();
|
boolean backfaceCulling();
|
||||||
|
|
||||||
boolean polygonOffset();
|
boolean polygonOffset();
|
||||||
|
|
||||||
boolean mip();
|
DepthTest depthTest();
|
||||||
|
|
||||||
FogShader fog();
|
|
||||||
|
|
||||||
CutoutShader cutout();
|
|
||||||
|
|
||||||
Transparency transparency();
|
Transparency transparency();
|
||||||
|
|
||||||
WriteMask writeMask();
|
WriteMask writeMask();
|
||||||
|
|
||||||
|
boolean useOverlay();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should this material be rendered with block/sky lighting?
|
||||||
|
*
|
||||||
|
* @return {@code true} if this material should be rendered with block/sky lighting.
|
||||||
|
*/
|
||||||
|
boolean useLight();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should this material be rendered with diffuse lighting?
|
||||||
|
*
|
||||||
|
* @return {@code true} if this material should be rendered with diffuse lighting.
|
||||||
|
*/
|
||||||
|
boolean diffuse();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
package com.jozufozu.flywheel.backend;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.api.material.DepthTest;
|
||||||
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
|
import com.jozufozu.flywheel.api.material.Transparency;
|
||||||
|
import com.jozufozu.flywheel.api.material.WriteMask;
|
||||||
|
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
|
||||||
|
// Materials are unpacked in "flywheel:flywheel/internal/material.glsl"
|
||||||
|
public final class MaterialEncoder {
|
||||||
|
// The number of bits each property takes up
|
||||||
|
private static final int BLUR_LENGTH = 1;
|
||||||
|
private static final int MIPMAP_LENGTH = 1;
|
||||||
|
private static final int BACKFACE_CULLING_LENGTH = 1;
|
||||||
|
private static final int POLYGON_OFFSET_LENGTH = 1;
|
||||||
|
private static final int DEPTH_TEST_LENGTH = Mth.ceillog2(DepthTest.values().length);
|
||||||
|
private static final int TRANSPARENCY_LENGTH = Mth.ceillog2(Transparency.values().length);
|
||||||
|
private static final int WRITE_MASK_LENGTH = Mth.ceillog2(WriteMask.values().length);
|
||||||
|
private static final int USE_OVERLAY_LENGTH = 1;
|
||||||
|
private static final int USE_LIGHT_LENGTH = 1;
|
||||||
|
private static final int DIFFUSE_LENGTH = 1;
|
||||||
|
|
||||||
|
// The bit offset of each property
|
||||||
|
private static final int BLUR_OFFSET = 0;
|
||||||
|
private static final int MIPMAP_OFFSET = BLUR_OFFSET + BLUR_LENGTH;
|
||||||
|
private static final int BACKFACE_CULLING_OFFSET = MIPMAP_OFFSET + MIPMAP_LENGTH;
|
||||||
|
private static final int POLYGON_OFFSET_OFFSET = BACKFACE_CULLING_OFFSET + BACKFACE_CULLING_LENGTH;
|
||||||
|
private static final int DEPTH_TEST_OFFSET = POLYGON_OFFSET_OFFSET + POLYGON_OFFSET_LENGTH;
|
||||||
|
private static final int TRANSPARENCY_OFFSET = DEPTH_TEST_OFFSET + DEPTH_TEST_LENGTH;
|
||||||
|
private static final int WRITE_MASK_OFFSET = TRANSPARENCY_OFFSET + TRANSPARENCY_LENGTH;
|
||||||
|
private static final int USE_OVERLAY_OFFSET = WRITE_MASK_OFFSET + WRITE_MASK_LENGTH;
|
||||||
|
private static final int USE_LIGHT_OFFSET = USE_OVERLAY_OFFSET + USE_OVERLAY_LENGTH;
|
||||||
|
private static final int DIFFUSE_OFFSET = USE_LIGHT_OFFSET + USE_LIGHT_LENGTH;
|
||||||
|
|
||||||
|
// The bit mask for each property
|
||||||
|
private static final int BLUR_MASK = bitMask(BLUR_LENGTH, BLUR_OFFSET);
|
||||||
|
private static final int MIPMAP_MASK = bitMask(MIPMAP_LENGTH, MIPMAP_OFFSET);
|
||||||
|
private static final int BACKFACE_CULLING_MASK = bitMask(BACKFACE_CULLING_LENGTH, BACKFACE_CULLING_OFFSET);
|
||||||
|
private static final int POLYGON_OFFSET_MASK = bitMask(POLYGON_OFFSET_LENGTH, POLYGON_OFFSET_OFFSET);
|
||||||
|
private static final int DEPTH_TEST_MASK = bitMask(DEPTH_TEST_LENGTH, DEPTH_TEST_OFFSET);
|
||||||
|
private static final int TRANSPARENCY_MASK = bitMask(TRANSPARENCY_LENGTH, TRANSPARENCY_OFFSET);
|
||||||
|
private static final int WRITE_MASK_MASK = bitMask(WRITE_MASK_LENGTH, WRITE_MASK_OFFSET);
|
||||||
|
private static final int USE_OVERLAY_MASK = bitMask(USE_OVERLAY_LENGTH, USE_OVERLAY_OFFSET);
|
||||||
|
private static final int USE_LIGHT_MASK = bitMask(USE_LIGHT_LENGTH, USE_LIGHT_OFFSET);
|
||||||
|
private static final int DIFFUSE_MASK = bitMask(DIFFUSE_LENGTH, DIFFUSE_OFFSET);
|
||||||
|
|
||||||
|
private MaterialEncoder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int bitMask(int bitLength, int bitOffset) {
|
||||||
|
return ((1 << bitLength) - 1) << bitOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int packFogAndCutout(Material material) {
|
||||||
|
var fog = ShaderIndices.fog()
|
||||||
|
.index(material.fog()
|
||||||
|
.source());
|
||||||
|
var cutout = ShaderIndices.cutout()
|
||||||
|
.index(material.cutout()
|
||||||
|
.source());
|
||||||
|
|
||||||
|
return fog & 0xFFFF | (cutout & 0xFFFF) << 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Packed format:
|
||||||
|
// diffuse[1] | useOverlay[1] | useLight[1] | writeMask[2] | transparency[3] | depthTest[4] | polygonOffset[1] | backfaceCulling[1] | mipmap[1] | blur[1]
|
||||||
|
public static int packProperties(Material material) {
|
||||||
|
int bits = 0;
|
||||||
|
|
||||||
|
if (material.blur()) bits |= BLUR_MASK;
|
||||||
|
if (material.mipmap()) bits |= MIPMAP_MASK;
|
||||||
|
if (material.backfaceCulling()) bits |= BACKFACE_CULLING_MASK;
|
||||||
|
if (material.polygonOffset()) bits |= POLYGON_OFFSET_MASK;
|
||||||
|
bits |= (material.depthTest().ordinal() << DEPTH_TEST_OFFSET) & DEPTH_TEST_MASK;
|
||||||
|
bits |= (material.transparency().ordinal() << TRANSPARENCY_OFFSET) & TRANSPARENCY_MASK;
|
||||||
|
bits |= (material.writeMask().ordinal() << WRITE_MASK_OFFSET) & WRITE_MASK_MASK;
|
||||||
|
if (material.useOverlay()) bits |= USE_OVERLAY_MASK;
|
||||||
|
if (material.useLight()) bits |= USE_LIGHT_MASK;
|
||||||
|
if (material.diffuse()) bits |= DIFFUSE_MASK;
|
||||||
|
|
||||||
|
return bits;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,180 @@
|
||||||
|
package com.jozufozu.flywheel.backend;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.api.material.DepthTest;
|
||||||
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
|
import com.jozufozu.flywheel.api.material.Transparency;
|
||||||
|
import com.jozufozu.flywheel.api.material.WriteMask;
|
||||||
|
import com.jozufozu.flywheel.gl.GlTextureUnit;
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.texture.AbstractTexture;
|
||||||
|
|
||||||
|
public final class MaterialRenderState {
|
||||||
|
public static final Comparator<Material> COMPARATOR = Comparator.comparing(Material::baseTexture)
|
||||||
|
.thenComparing(Material::blur)
|
||||||
|
.thenComparing(Material::mipmap)
|
||||||
|
.thenComparing(Material::backfaceCulling)
|
||||||
|
.thenComparing(Material::polygonOffset)
|
||||||
|
.thenComparing(Material::depthTest)
|
||||||
|
.thenComparing(Material::transparency)
|
||||||
|
.thenComparing(Material::writeMask);
|
||||||
|
|
||||||
|
private MaterialRenderState() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setup(Material material) {
|
||||||
|
setupTexture(material);
|
||||||
|
setupBackfaceCulling(material.backfaceCulling());
|
||||||
|
setupPolygonOffset(material.polygonOffset());
|
||||||
|
setupDepthTest(material.depthTest());
|
||||||
|
setupTransparency(material.transparency());
|
||||||
|
setupWriteMask(material.writeMask());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setupTexture(Material material) {
|
||||||
|
GlTextureUnit.T0.makeActive();
|
||||||
|
AbstractTexture texture = Minecraft.getInstance()
|
||||||
|
.getTextureManager()
|
||||||
|
.getTexture(material.baseTexture());
|
||||||
|
texture.setFilter(material.blur(), material.mipmap());
|
||||||
|
var textureId = texture.getId();
|
||||||
|
RenderSystem.setShaderTexture(0, textureId);
|
||||||
|
RenderSystem.bindTexture(textureId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setupBackfaceCulling(boolean backfaceCulling) {
|
||||||
|
if (backfaceCulling) {
|
||||||
|
RenderSystem.enableCull();
|
||||||
|
} else {
|
||||||
|
RenderSystem.disableCull();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setupPolygonOffset(boolean polygonOffset) {
|
||||||
|
if (polygonOffset) {
|
||||||
|
RenderSystem.polygonOffset(-1.0F, -10.0F);
|
||||||
|
RenderSystem.enablePolygonOffset();
|
||||||
|
} else {
|
||||||
|
RenderSystem.polygonOffset(0.0F, 0.0F);
|
||||||
|
RenderSystem.enablePolygonOffset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setupDepthTest(DepthTest depthTest) {
|
||||||
|
switch (depthTest) {
|
||||||
|
case OFF -> {
|
||||||
|
RenderSystem.disableDepthTest();
|
||||||
|
}
|
||||||
|
case NEVER -> {
|
||||||
|
RenderSystem.enableDepthTest();
|
||||||
|
RenderSystem.depthFunc(GL11.GL_NEVER);
|
||||||
|
}
|
||||||
|
case LESS -> {
|
||||||
|
RenderSystem.enableDepthTest();
|
||||||
|
RenderSystem.depthFunc(GL11.GL_LESS);
|
||||||
|
}
|
||||||
|
case EQUAL -> {
|
||||||
|
RenderSystem.enableDepthTest();
|
||||||
|
RenderSystem.depthFunc(GL11.GL_EQUAL);
|
||||||
|
}
|
||||||
|
case LEQUAL -> {
|
||||||
|
RenderSystem.enableDepthTest();
|
||||||
|
RenderSystem.depthFunc(GL11.GL_LEQUAL);
|
||||||
|
}
|
||||||
|
case GREATER -> {
|
||||||
|
RenderSystem.enableDepthTest();
|
||||||
|
RenderSystem.depthFunc(GL11.GL_GREATER);
|
||||||
|
}
|
||||||
|
case NOTEQUAL -> {
|
||||||
|
RenderSystem.enableDepthTest();
|
||||||
|
RenderSystem.depthFunc(GL11.GL_NOTEQUAL);
|
||||||
|
}
|
||||||
|
case GEQUAL -> {
|
||||||
|
RenderSystem.enableDepthTest();
|
||||||
|
RenderSystem.depthFunc(GL11.GL_GEQUAL);
|
||||||
|
}
|
||||||
|
case ALWAYS -> {
|
||||||
|
RenderSystem.enableDepthTest();
|
||||||
|
RenderSystem.depthFunc(GL11.GL_ALWAYS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setupTransparency(Transparency transparency) {
|
||||||
|
switch (transparency) {
|
||||||
|
case OPAQUE -> {
|
||||||
|
RenderSystem.disableBlend();
|
||||||
|
}
|
||||||
|
case ADDITIVE -> {
|
||||||
|
RenderSystem.enableBlend();
|
||||||
|
RenderSystem.blendFunc(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE);
|
||||||
|
}
|
||||||
|
case LIGHTING -> {
|
||||||
|
RenderSystem.enableBlend();
|
||||||
|
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
|
||||||
|
}
|
||||||
|
case GLINT -> {
|
||||||
|
RenderSystem.enableBlend();
|
||||||
|
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_COLOR, GlStateManager.DestFactor.ONE, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE);
|
||||||
|
}
|
||||||
|
case CRUMBLING -> {
|
||||||
|
RenderSystem.enableBlend();
|
||||||
|
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.DST_COLOR, GlStateManager.DestFactor.SRC_COLOR, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||||
|
}
|
||||||
|
case TRANSLUCENT -> {
|
||||||
|
RenderSystem.enableBlend();
|
||||||
|
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setupWriteMask(WriteMask mask) {
|
||||||
|
RenderSystem.depthMask(mask.depth());
|
||||||
|
boolean writeColor = mask.color();
|
||||||
|
RenderSystem.colorMask(writeColor, writeColor, writeColor, writeColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reset() {
|
||||||
|
resetTexture();
|
||||||
|
resetBackfaceCulling();
|
||||||
|
resetPolygonOffset();
|
||||||
|
resetDepthTest();
|
||||||
|
resetTransparency();
|
||||||
|
resetWriteMask();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void resetTexture() {
|
||||||
|
GlTextureUnit.T0.makeActive();
|
||||||
|
RenderSystem.setShaderTexture(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void resetBackfaceCulling() {
|
||||||
|
RenderSystem.enableCull();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void resetPolygonOffset() {
|
||||||
|
RenderSystem.polygonOffset(0.0F, 0.0F);
|
||||||
|
RenderSystem.disablePolygonOffset();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void resetDepthTest() {
|
||||||
|
RenderSystem.disableDepthTest();
|
||||||
|
RenderSystem.depthFunc(GL11.GL_LEQUAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void resetTransparency() {
|
||||||
|
RenderSystem.disableBlend();
|
||||||
|
RenderSystem.defaultBlendFunc();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void resetWriteMask() {
|
||||||
|
RenderSystem.depthMask(true);
|
||||||
|
RenderSystem.colorMask(true, true, true, true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,147 +0,0 @@
|
||||||
package com.jozufozu.flywheel.backend;
|
|
||||||
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
|
||||||
import com.jozufozu.flywheel.api.material.Transparency;
|
|
||||||
import com.jozufozu.flywheel.api.material.WriteMask;
|
|
||||||
import com.jozufozu.flywheel.gl.GlTextureUnit;
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.texture.AbstractTexture;
|
|
||||||
|
|
||||||
public class MaterialUtil {
|
|
||||||
public static final Comparator<Material> BY_STATE = Comparator.comparing(Material::baseTexture)
|
|
||||||
.thenComparing(Material::mip)
|
|
||||||
.thenComparing(Material::blur)
|
|
||||||
.thenComparing(Material::backfaceCull)
|
|
||||||
.thenComparing(Material::polygonOffset)
|
|
||||||
.thenComparing(Material::writeMask);
|
|
||||||
|
|
||||||
public static void setup(Material material) {
|
|
||||||
setupTexture(material);
|
|
||||||
|
|
||||||
setupBackfaceCull(material.backfaceCull());
|
|
||||||
setupTransparency(material.transparency());
|
|
||||||
setupWriteMask(material.writeMask());
|
|
||||||
setupPolygonOffset(material.polygonOffset());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setupPolygonOffset(boolean polygonOffset) {
|
|
||||||
if (polygonOffset) {
|
|
||||||
RenderSystem.polygonOffset(-1.0F, -10.0F);
|
|
||||||
RenderSystem.enablePolygonOffset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setupWriteMask(WriteMask mask) {
|
|
||||||
RenderSystem.depthMask(mask.depth());
|
|
||||||
boolean writeColor = mask.color();
|
|
||||||
RenderSystem.colorMask(writeColor, writeColor, writeColor, writeColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setupTransparency(Transparency transparency) {
|
|
||||||
if (transparency != Transparency.OPAQUE) {
|
|
||||||
RenderSystem.enableBlend();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (transparency) {
|
|
||||||
case ADDITIVE -> RenderSystem.blendFunc(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE);
|
|
||||||
case LIGHTING -> RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
|
|
||||||
case GLINT ->
|
|
||||||
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_COLOR, GlStateManager.DestFactor.ONE, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE);
|
|
||||||
case CRUMBLING ->
|
|
||||||
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.DST_COLOR, GlStateManager.DestFactor.SRC_COLOR, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
|
||||||
case TRANSLUCENT ->
|
|
||||||
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setupBackfaceCull(boolean backfaceCull) {
|
|
||||||
if (!backfaceCull) {
|
|
||||||
RenderSystem.disableCull();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setupTexture(Material material) {
|
|
||||||
GlTextureUnit.T0.makeActive();
|
|
||||||
AbstractTexture texture = Minecraft.getInstance()
|
|
||||||
.getTextureManager()
|
|
||||||
.getTexture(material.baseTexture());
|
|
||||||
var textureId = texture.getId();
|
|
||||||
texture.setFilter(material.blur(), material.mip());
|
|
||||||
RenderSystem.setShaderTexture(0, textureId);
|
|
||||||
RenderSystem.bindTexture(textureId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void reset() {
|
|
||||||
resetDiffuse();
|
|
||||||
resetBackfaceCull();
|
|
||||||
resetTransparency();
|
|
||||||
resetWriteMask();
|
|
||||||
resetPolygonOffset();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void resetPolygonOffset() {
|
|
||||||
RenderSystem.polygonOffset(0.0F, 0.0F);
|
|
||||||
RenderSystem.disablePolygonOffset();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void resetWriteMask() {
|
|
||||||
RenderSystem.depthMask(true);
|
|
||||||
RenderSystem.colorMask(true, true, true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void resetTransparency() {
|
|
||||||
RenderSystem.disableBlend();
|
|
||||||
RenderSystem.defaultBlendFunc();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void resetBackfaceCull() {
|
|
||||||
RenderSystem.enableCull();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void resetDiffuse() {
|
|
||||||
GlTextureUnit.T0.makeActive();
|
|
||||||
RenderSystem.setShaderTexture(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final int DIFFUSE_MASK = 1;
|
|
||||||
public static final int LIGHTING_MASK = 1 << 1;
|
|
||||||
public static final int BLUR_MASK = 1 << 2;
|
|
||||||
public static final int BACKFACE_CULL_MASK = 1 << 3;
|
|
||||||
public static final int POLYGON_OFFSET_MASK = 1 << 4;
|
|
||||||
public static final int MIP_MASK = 1 << 5;
|
|
||||||
|
|
||||||
public static int packProperties(Material material) {
|
|
||||||
int out = 0;
|
|
||||||
|
|
||||||
if (material.diffuse()) out |= DIFFUSE_MASK;
|
|
||||||
if (material.lighting()) out |= LIGHTING_MASK;
|
|
||||||
if (material.blur()) out |= BLUR_MASK;
|
|
||||||
if (material.backfaceCull()) out |= BACKFACE_CULL_MASK;
|
|
||||||
if (material.polygonOffset()) out |= POLYGON_OFFSET_MASK;
|
|
||||||
if (material.mip()) out |= MIP_MASK;
|
|
||||||
|
|
||||||
out |= (material.writeMask()
|
|
||||||
.ordinal() & 0x3) << 6;
|
|
||||||
|
|
||||||
out |= (material.transparency()
|
|
||||||
.ordinal() & 0x7) << 8;
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int packFogAndCutout(Material material) {
|
|
||||||
var fog = ShaderIndices.fog()
|
|
||||||
.index(material.fog()
|
|
||||||
.source());
|
|
||||||
var cutout = ShaderIndices.cutout()
|
|
||||||
.index(material.cutout()
|
|
||||||
.source());
|
|
||||||
|
|
||||||
return fog & 0xFFFF | (cutout & 0xFFFF) << 16;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -19,8 +19,8 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
public final class ShaderIndices {
|
public final class ShaderIndices {
|
||||||
private static Index vertexShaders;
|
private static Index vertexShaders;
|
||||||
private static Index fragmentShaders;
|
private static Index fragmentShaders;
|
||||||
private static Index cutoutShaders;
|
|
||||||
private static Index fogShaders;
|
private static Index fogShaders;
|
||||||
|
private static Index cutoutShaders;
|
||||||
|
|
||||||
private ShaderIndices() {
|
private ShaderIndices() {
|
||||||
}
|
}
|
||||||
|
@ -39,13 +39,6 @@ public final class ShaderIndices {
|
||||||
return fragmentShaders;
|
return fragmentShaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Index cutout() {
|
|
||||||
if (cutoutShaders == null) {
|
|
||||||
throw new IllegalStateException("Not initialized!");
|
|
||||||
}
|
|
||||||
return cutoutShaders;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Index fog() {
|
public static Index fog() {
|
||||||
if (fogShaders == null) {
|
if (fogShaders == null) {
|
||||||
throw new IllegalStateException("Not initialized!");
|
throw new IllegalStateException("Not initialized!");
|
||||||
|
@ -53,12 +46,11 @@ public final class ShaderIndices {
|
||||||
return fogShaders;
|
return fogShaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getCutoutShaderIndex(CutoutShader cutoutShader) {
|
public static Index cutout() {
|
||||||
return cutout().index(cutoutShader.source());
|
if (cutoutShaders == null) {
|
||||||
|
throw new IllegalStateException("Not initialized!");
|
||||||
}
|
}
|
||||||
|
return cutoutShaders;
|
||||||
public static int getFogShaderIndex(FogShader fogShader) {
|
|
||||||
return fog().index(fogShader.source());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getVertexShaderIndex(MaterialShaders shaders) {
|
public static int getVertexShaderIndex(MaterialShaders shaders) {
|
||||||
|
@ -69,6 +61,14 @@ public final class ShaderIndices {
|
||||||
return materialFragment().index(shaders.fragmentShader());
|
return materialFragment().index(shaders.fragmentShader());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getFogShaderIndex(FogShader fogShader) {
|
||||||
|
return fog().index(fogShader.source());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getCutoutShaderIndex(CutoutShader cutoutShader) {
|
||||||
|
return cutout().index(cutoutShader.source());
|
||||||
|
}
|
||||||
|
|
||||||
private static void initMaterialShaders() {
|
private static void initMaterialShaders() {
|
||||||
int amount = MaterialShaders.REGISTRY.getAll()
|
int amount = MaterialShaders.REGISTRY.getAll()
|
||||||
.size();
|
.size();
|
||||||
|
@ -85,19 +85,6 @@ public final class ShaderIndices {
|
||||||
ShaderIndices.fragmentShaders = fragmentShaders.build();
|
ShaderIndices.fragmentShaders = fragmentShaders.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initCutoutShaders() {
|
|
||||||
int amount = CutoutShader.REGISTRY.getAll()
|
|
||||||
.size();
|
|
||||||
|
|
||||||
var cutout = new IndexBuilder(amount);
|
|
||||||
|
|
||||||
for (CutoutShader shaders : CutoutShader.REGISTRY) {
|
|
||||||
cutout.add(shaders.source());
|
|
||||||
}
|
|
||||||
|
|
||||||
ShaderIndices.cutoutShaders = cutout.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void initFogShaders() {
|
private static void initFogShaders() {
|
||||||
int amount = FogShader.REGISTRY.getAll()
|
int amount = FogShader.REGISTRY.getAll()
|
||||||
.size();
|
.size();
|
||||||
|
@ -111,10 +98,23 @@ public final class ShaderIndices {
|
||||||
ShaderIndices.fogShaders = fog.build();
|
ShaderIndices.fogShaders = fog.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void initCutoutShaders() {
|
||||||
|
int amount = CutoutShader.REGISTRY.getAll()
|
||||||
|
.size();
|
||||||
|
|
||||||
|
var cutout = new IndexBuilder(amount);
|
||||||
|
|
||||||
|
for (CutoutShader shaders : CutoutShader.REGISTRY) {
|
||||||
|
cutout.add(shaders.source());
|
||||||
|
}
|
||||||
|
|
||||||
|
ShaderIndices.cutoutShaders = cutout.build();
|
||||||
|
}
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
MaterialShaders.REGISTRY.addFreezeCallback(ShaderIndices::initMaterialShaders);
|
MaterialShaders.REGISTRY.addFreezeCallback(ShaderIndices::initMaterialShaders);
|
||||||
CutoutShader.REGISTRY.addFreezeCallback(ShaderIndices::initCutoutShaders);
|
|
||||||
FogShader.REGISTRY.addFreezeCallback(ShaderIndices::initFogShaders);
|
FogShader.REGISTRY.addFreezeCallback(ShaderIndices::initFogShaders);
|
||||||
|
CutoutShader.REGISTRY.addFreezeCallback(ShaderIndices::initCutoutShaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Index {
|
public static class Index {
|
||||||
|
@ -163,21 +163,3 @@ public final class ShaderIndices {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import org.joml.Vector3f;
|
||||||
import org.joml.Vector4f;
|
import org.joml.Vector4f;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
|
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
|
||||||
import com.jozufozu.flywheel.api.vertex.ReusableVertexList;
|
|
||||||
import com.jozufozu.flywheel.lib.vertex.VertexTransformations;
|
import com.jozufozu.flywheel.lib.vertex.VertexTransformations;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.blaze3d.vertex.SheetedDecalTextureGenerator;
|
import com.mojang.blaze3d.vertex.SheetedDecalTextureGenerator;
|
||||||
|
@ -31,7 +30,7 @@ public class BatchingTransforms {
|
||||||
*
|
*
|
||||||
* @param vertexList The vertex list to apply the transformations to.
|
* @param vertexList The vertex list to apply the transformations to.
|
||||||
*/
|
*/
|
||||||
public static void applyDecalUVs(ReusableVertexList vertexList) {
|
public static void applyDecalUVs(MutableVertexList vertexList) {
|
||||||
Vector3f normal = new Vector3f();
|
Vector3f normal = new Vector3f();
|
||||||
Vector4f pos = new Vector4f();
|
Vector4f pos = new Vector4f();
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import com.jozufozu.flywheel.api.instance.InstanceType;
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
import com.jozufozu.flywheel.api.model.Mesh;
|
import com.jozufozu.flywheel.api.model.Mesh;
|
||||||
import com.jozufozu.flywheel.api.model.Model;
|
import com.jozufozu.flywheel.api.model.Model;
|
||||||
import com.jozufozu.flywheel.backend.MaterialUtil;
|
import com.jozufozu.flywheel.backend.MaterialRenderState;
|
||||||
import com.jozufozu.flywheel.backend.compile.IndirectPrograms;
|
import com.jozufozu.flywheel.backend.compile.IndirectPrograms;
|
||||||
import com.jozufozu.flywheel.backend.engine.UniformBuffer;
|
import com.jozufozu.flywheel.backend.engine.UniformBuffer;
|
||||||
import com.jozufozu.flywheel.gl.GlCompat;
|
import com.jozufozu.flywheel.gl.GlCompat;
|
||||||
|
@ -81,7 +81,7 @@ public class IndirectCullingGroup<I extends Instance> {
|
||||||
multiDraws.clear();
|
multiDraws.clear();
|
||||||
// sort by stage, then material
|
// sort by stage, then material
|
||||||
indirectDraws.sort(Comparator.comparing(IndirectDraw::stage)
|
indirectDraws.sort(Comparator.comparing(IndirectDraw::stage)
|
||||||
.thenComparing(IndirectDraw::material, MaterialUtil.BY_STATE));
|
.thenComparing(IndirectDraw::material, MaterialRenderState.COMPARATOR));
|
||||||
|
|
||||||
for (int start = 0, i = 0; i < indirectDraws.size(); i++) {
|
for (int start = 0, i = 0; i < indirectDraws.size(); i++) {
|
||||||
var draw1 = indirectDraws.get(i);
|
var draw1 = indirectDraws.get(i);
|
||||||
|
@ -164,7 +164,6 @@ public class IndirectCullingGroup<I extends Instance> {
|
||||||
glUniform1ui(flwBaseDraw, multiDraw.start);
|
glUniform1ui(flwBaseDraw, multiDraw.start);
|
||||||
multiDraw.submit();
|
multiDraw.submit();
|
||||||
}
|
}
|
||||||
MaterialUtil.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawBarrier() {
|
private void drawBarrier() {
|
||||||
|
@ -233,7 +232,7 @@ public class IndirectCullingGroup<I extends Instance> {
|
||||||
|
|
||||||
private record MultiDraw(Material material, int start, int end) {
|
private record MultiDraw(Material material, int start, int end) {
|
||||||
void submit() {
|
void submit() {
|
||||||
MaterialUtil.setup(material);
|
MaterialRenderState.setup(material);
|
||||||
glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, start * IndirectBuffers.DRAW_COMMAND_STRIDE, end - start, (int) IndirectBuffers.DRAW_COMMAND_STRIDE);
|
glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, start * IndirectBuffers.DRAW_COMMAND_STRIDE, end - start, (int) IndirectBuffers.DRAW_COMMAND_STRIDE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.event.RenderStage;
|
import com.jozufozu.flywheel.api.event.RenderStage;
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
import com.jozufozu.flywheel.backend.MaterialUtil;
|
import com.jozufozu.flywheel.backend.MaterialEncoder;
|
||||||
import com.jozufozu.flywheel.backend.ShaderIndices;
|
import com.jozufozu.flywheel.backend.ShaderIndices;
|
||||||
|
|
||||||
public class IndirectDraw {
|
public class IndirectDraw {
|
||||||
|
@ -26,8 +26,8 @@ public class IndirectDraw {
|
||||||
|
|
||||||
this.vertexMaterialID = ShaderIndices.getVertexShaderIndex(material.shaders());
|
this.vertexMaterialID = ShaderIndices.getVertexShaderIndex(material.shaders());
|
||||||
this.fragmentMaterialID = ShaderIndices.getFragmentShaderIndex(material.shaders());
|
this.fragmentMaterialID = ShaderIndices.getFragmentShaderIndex(material.shaders());
|
||||||
this.packedFogAndCutout = MaterialUtil.packFogAndCutout(material);
|
this.packedFogAndCutout = MaterialEncoder.packFogAndCutout(material);
|
||||||
this.packedMaterialProperties = MaterialUtil.packProperties(material);
|
this.packedMaterialProperties = MaterialEncoder.packProperties(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material material() {
|
public Material material() {
|
||||||
|
|
|
@ -2,12 +2,11 @@ package com.jozufozu.flywheel.backend.engine.indirect;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL32;
|
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.event.RenderContext;
|
import com.jozufozu.flywheel.api.event.RenderContext;
|
||||||
import com.jozufozu.flywheel.api.event.RenderStage;
|
import com.jozufozu.flywheel.api.event.RenderStage;
|
||||||
import com.jozufozu.flywheel.api.task.Plan;
|
import com.jozufozu.flywheel.api.task.Plan;
|
||||||
import com.jozufozu.flywheel.api.task.TaskExecutor;
|
import com.jozufozu.flywheel.api.task.TaskExecutor;
|
||||||
|
import com.jozufozu.flywheel.backend.MaterialRenderState;
|
||||||
import com.jozufozu.flywheel.backend.engine.AbstractEngine;
|
import com.jozufozu.flywheel.backend.engine.AbstractEngine;
|
||||||
import com.jozufozu.flywheel.backend.engine.AbstractInstancer;
|
import com.jozufozu.flywheel.backend.engine.AbstractInstancer;
|
||||||
import com.jozufozu.flywheel.backend.engine.InstancerStorage;
|
import com.jozufozu.flywheel.backend.engine.InstancerStorage;
|
||||||
|
@ -16,6 +15,7 @@ import com.jozufozu.flywheel.gl.GlTextureUnit;
|
||||||
import com.jozufozu.flywheel.lib.task.Flag;
|
import com.jozufozu.flywheel.lib.task.Flag;
|
||||||
import com.jozufozu.flywheel.lib.task.NamedFlag;
|
import com.jozufozu.flywheel.lib.task.NamedFlag;
|
||||||
import com.jozufozu.flywheel.lib.task.SyncedPlan;
|
import com.jozufozu.flywheel.lib.task.SyncedPlan;
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
@ -52,11 +52,24 @@ public class IndirectEngine extends AbstractEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
try (var restoreState = GlStateTracker.getRestoreState()) {
|
try (var restoreState = GlStateTracker.getRestoreState()) {
|
||||||
setup();
|
int prevActiveTexture = GlStateManager._getActiveTexture();
|
||||||
|
Minecraft.getInstance().gameRenderer.overlayTexture().setupOverlayColor();
|
||||||
|
Minecraft.getInstance().gameRenderer.lightTexture().turnOnLightLayer();
|
||||||
|
|
||||||
|
GlTextureUnit.T1.makeActive();
|
||||||
|
RenderSystem.bindTexture(RenderSystem.getShaderTexture(1));
|
||||||
|
GlTextureUnit.T2.makeActive();
|
||||||
|
RenderSystem.bindTexture(RenderSystem.getShaderTexture(2));
|
||||||
|
|
||||||
for (var list : drawManager.renderLists.values()) {
|
for (var list : drawManager.renderLists.values()) {
|
||||||
list.submit(stage);
|
list.submit(stage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MaterialRenderState.reset();
|
||||||
|
|
||||||
|
Minecraft.getInstance().gameRenderer.overlayTexture().teardownOverlayColor();
|
||||||
|
Minecraft.getInstance().gameRenderer.lightTexture().turnOffLightLayer();
|
||||||
|
GlStateManager._activeTexture(prevActiveTexture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,17 +78,6 @@ public class IndirectEngine extends AbstractEngine {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setup() {
|
|
||||||
GlTextureUnit.T2.makeActive();
|
|
||||||
Minecraft.getInstance().gameRenderer.lightTexture().turnOnLightLayer();
|
|
||||||
|
|
||||||
RenderSystem.depthMask(true);
|
|
||||||
RenderSystem.colorMask(true, true, true, true);
|
|
||||||
RenderSystem.enableDepthTest();
|
|
||||||
RenderSystem.depthFunc(GL32.GL_LEQUAL);
|
|
||||||
RenderSystem.enableCull();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected InstancerStorage<? extends AbstractInstancer<?>> getStorage() {
|
protected InstancerStorage<? extends AbstractInstancer<?>> getStorage() {
|
||||||
return drawManager;
|
return drawManager;
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
package com.jozufozu.flywheel.backend.engine.indirect;
|
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL32;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
|
|
||||||
public class Textures {
|
|
||||||
/**
|
|
||||||
* Call this after calling {@link RenderType#setupRenderState()}.
|
|
||||||
*/
|
|
||||||
public static void bindActiveTextures() {
|
|
||||||
for (int i = 0; i < 12; i++) {
|
|
||||||
int shaderTexture = RenderSystem.getShaderTexture(i);
|
|
||||||
RenderSystem.activeTexture(GL32.GL_TEXTURE0 + i);
|
|
||||||
RenderSystem.bindTexture(shaderTexture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,7 +12,7 @@ import com.jozufozu.flywheel.api.instance.Instance;
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
import com.jozufozu.flywheel.api.material.Transparency;
|
import com.jozufozu.flywheel.api.material.Transparency;
|
||||||
import com.jozufozu.flywheel.api.material.WriteMask;
|
import com.jozufozu.flywheel.api.material.WriteMask;
|
||||||
import com.jozufozu.flywheel.backend.MaterialUtil;
|
import com.jozufozu.flywheel.backend.MaterialRenderState;
|
||||||
import com.jozufozu.flywheel.backend.compile.InstancingPrograms;
|
import com.jozufozu.flywheel.backend.compile.InstancingPrograms;
|
||||||
import com.jozufozu.flywheel.backend.engine.InstanceHandleImpl;
|
import com.jozufozu.flywheel.backend.engine.InstanceHandleImpl;
|
||||||
import com.jozufozu.flywheel.backend.engine.UniformBuffer;
|
import com.jozufozu.flywheel.backend.engine.UniformBuffer;
|
||||||
|
@ -50,17 +50,19 @@ public class InstancedCrumbling {
|
||||||
var baseMaterial = shader.material();
|
var baseMaterial = shader.material();
|
||||||
int diffuseTexture = getDiffuseTexture(baseMaterial);
|
int diffuseTexture = getDiffuseTexture(baseMaterial);
|
||||||
|
|
||||||
var crumblingMaterial = SimpleMaterial.from(baseMaterial)
|
var crumblingMaterial = SimpleMaterial.builderOf(baseMaterial)
|
||||||
|
.cutout(CutoutShaders.OFF)
|
||||||
|
.polygonOffset(true)
|
||||||
.transparency(Transparency.CRUMBLING)
|
.transparency(Transparency.CRUMBLING)
|
||||||
.writeMask(WriteMask.COLOR)
|
.writeMask(WriteMask.COLOR)
|
||||||
.polygonOffset(true)
|
.useOverlay(false)
|
||||||
.cutout(CutoutShaders.OFF);
|
.useLight(false);
|
||||||
|
|
||||||
var program = InstancingPrograms.get()
|
var program = InstancingPrograms.get()
|
||||||
.get(shader.instanceType(), Contexts.CRUMBLING);
|
.get(shader.instanceType(), Contexts.CRUMBLING);
|
||||||
UniformBuffer.syncAndBind(program);
|
UniformBuffer.syncAndBind(program);
|
||||||
|
|
||||||
InstancingEngine.uploadMaterialIDUniform(program, crumblingMaterial);
|
InstancingEngine.uploadMaterialUniform(program, crumblingMaterial);
|
||||||
|
|
||||||
for (Int2ObjectMap.Entry<List<Runnable>> progressEntry : byProgress.int2ObjectEntrySet()) {
|
for (Int2ObjectMap.Entry<List<Runnable>> progressEntry : byProgress.int2ObjectEntrySet()) {
|
||||||
var drawCalls = progressEntry.getValue();
|
var drawCalls = progressEntry.getValue();
|
||||||
|
@ -71,17 +73,17 @@ public class InstancedCrumbling {
|
||||||
|
|
||||||
crumblingMaterial.baseTexture(ModelBakery.BREAKING_LOCATIONS.get(progressEntry.getIntKey()));
|
crumblingMaterial.baseTexture(ModelBakery.BREAKING_LOCATIONS.get(progressEntry.getIntKey()));
|
||||||
|
|
||||||
MaterialUtil.setup(crumblingMaterial);
|
MaterialRenderState.setup(crumblingMaterial);
|
||||||
|
|
||||||
RenderSystem.setShaderTexture(1, diffuseTexture);
|
|
||||||
GlTextureUnit.T1.makeActive();
|
GlTextureUnit.T1.makeActive();
|
||||||
|
RenderSystem.setShaderTexture(1, diffuseTexture);
|
||||||
RenderSystem.bindTexture(diffuseTexture);
|
RenderSystem.bindTexture(diffuseTexture);
|
||||||
|
|
||||||
drawCalls.forEach(Runnable::run);
|
drawCalls.forEach(Runnable::run);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialUtil.reset();
|
MaterialRenderState.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,8 @@ import com.jozufozu.flywheel.api.event.RenderStage;
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
import com.jozufozu.flywheel.api.task.Plan;
|
import com.jozufozu.flywheel.api.task.Plan;
|
||||||
import com.jozufozu.flywheel.api.task.TaskExecutor;
|
import com.jozufozu.flywheel.api.task.TaskExecutor;
|
||||||
import com.jozufozu.flywheel.backend.MaterialUtil;
|
import com.jozufozu.flywheel.backend.MaterialEncoder;
|
||||||
|
import com.jozufozu.flywheel.backend.MaterialRenderState;
|
||||||
import com.jozufozu.flywheel.backend.ShaderIndices;
|
import com.jozufozu.flywheel.backend.ShaderIndices;
|
||||||
import com.jozufozu.flywheel.backend.compile.InstancingPrograms;
|
import com.jozufozu.flywheel.backend.compile.InstancingPrograms;
|
||||||
import com.jozufozu.flywheel.backend.engine.AbstractEngine;
|
import com.jozufozu.flywheel.backend.engine.AbstractEngine;
|
||||||
|
@ -23,6 +24,7 @@ import com.jozufozu.flywheel.lib.context.Contexts;
|
||||||
import com.jozufozu.flywheel.lib.task.Flag;
|
import com.jozufozu.flywheel.lib.task.Flag;
|
||||||
import com.jozufozu.flywheel.lib.task.NamedFlag;
|
import com.jozufozu.flywheel.lib.task.NamedFlag;
|
||||||
import com.jozufozu.flywheel.lib.task.SyncedPlan;
|
import com.jozufozu.flywheel.lib.task.SyncedPlan;
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
@ -62,9 +64,20 @@ public class InstancingEngine extends AbstractEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
try (var state = GlStateTracker.getRestoreState()) {
|
try (var state = GlStateTracker.getRestoreState()) {
|
||||||
setup();
|
int prevActiveTexture = GlStateManager._getActiveTexture();
|
||||||
|
Minecraft.getInstance().gameRenderer.overlayTexture().setupOverlayColor();
|
||||||
|
Minecraft.getInstance().gameRenderer.lightTexture().turnOnLightLayer();
|
||||||
|
|
||||||
|
GlTextureUnit.T1.makeActive();
|
||||||
|
RenderSystem.bindTexture(RenderSystem.getShaderTexture(1));
|
||||||
|
GlTextureUnit.T2.makeActive();
|
||||||
|
RenderSystem.bindTexture(RenderSystem.getShaderTexture(2));
|
||||||
|
|
||||||
render(drawSet);
|
render(drawSet);
|
||||||
|
|
||||||
|
Minecraft.getInstance().gameRenderer.overlayTexture().teardownOverlayColor();
|
||||||
|
Minecraft.getInstance().gameRenderer.lightTexture().turnOffLightLayer();
|
||||||
|
GlStateManager._activeTexture(prevActiveTexture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,17 +99,6 @@ public class InstancingEngine extends AbstractEngine {
|
||||||
drawManager.invalidate();
|
drawManager.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setup() {
|
|
||||||
GlTextureUnit.T2.makeActive();
|
|
||||||
Minecraft.getInstance().gameRenderer.lightTexture().turnOnLightLayer();
|
|
||||||
|
|
||||||
RenderSystem.depthMask(true);
|
|
||||||
RenderSystem.colorMask(true, true, true, true);
|
|
||||||
RenderSystem.enableDepthTest();
|
|
||||||
RenderSystem.depthFunc(GL32.GL_LEQUAL);
|
|
||||||
RenderSystem.enableCull();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void render(InstancedDrawManager.DrawSet drawSet) {
|
private void render(InstancedDrawManager.DrawSet drawSet) {
|
||||||
for (var entry : drawSet) {
|
for (var entry : drawSet) {
|
||||||
var shader = entry.getKey();
|
var shader = entry.getKey();
|
||||||
|
@ -112,24 +114,24 @@ public class InstancingEngine extends AbstractEngine {
|
||||||
.get(shader.instanceType(), Contexts.WORLD);
|
.get(shader.instanceType(), Contexts.WORLD);
|
||||||
UniformBuffer.syncAndBind(program);
|
UniformBuffer.syncAndBind(program);
|
||||||
|
|
||||||
uploadMaterialIDUniform(program, shader.material());
|
uploadMaterialUniform(program, shader.material());
|
||||||
|
|
||||||
MaterialUtil.setup(shader.material());
|
MaterialRenderState.setup(shader.material());
|
||||||
|
|
||||||
for (var drawCall : drawCalls) {
|
for (var drawCall : drawCalls) {
|
||||||
drawCall.render();
|
drawCall.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialUtil.reset();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void uploadMaterialIDUniform(GlProgram program, Material material) {
|
MaterialRenderState.reset();
|
||||||
int materialIDUniform = program.getUniformLocation("_flw_material_instancing");
|
}
|
||||||
int vertexID = ShaderIndices.getVertexShaderIndex(material.shaders());
|
|
||||||
int fragmentID = ShaderIndices.getFragmentShaderIndex(material.shaders());
|
public static void uploadMaterialUniform(GlProgram program, Material material) {
|
||||||
int packedFogAndCutout = MaterialUtil.packFogAndCutout(material);
|
int uniformLocation = program.getUniformLocation("_flw_packedMaterial");
|
||||||
int packedMaterialProperties = MaterialUtil.packProperties(material);
|
int vertexIndex = ShaderIndices.getVertexShaderIndex(material.shaders());
|
||||||
GL32.glUniform4ui(materialIDUniform, vertexID, fragmentID, packedFogAndCutout, packedMaterialProperties);
|
int fragmentIndex = ShaderIndices.getFragmentShaderIndex(material.shaders());
|
||||||
|
int packedFogAndCutout = MaterialEncoder.packFogAndCutout(material);
|
||||||
|
int packedMaterialProperties = MaterialEncoder.packProperties(material);
|
||||||
|
GL32.glUniform4ui(uniformLocation, vertexIndex, fragmentIndex, packedFogAndCutout, packedMaterialProperties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,5 +79,4 @@ public class GlProgram extends GlObject {
|
||||||
protected void deleteInternal(int handle) {
|
protected void deleteInternal(int handle) {
|
||||||
glDeleteProgram(handle);
|
glDeleteProgram(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,16 +11,16 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
public final class Contexts {
|
public final class Contexts {
|
||||||
public static final SimpleContext WORLD = Context.REGISTRY.registerAndGet(new SimpleContext(Files.WORLD_VERTEX, Files.WORLD_FRAGMENT, program -> {
|
public static final SimpleContext WORLD = Context.REGISTRY.registerAndGet(new SimpleContext(Files.WORLD_VERTEX, Files.WORLD_FRAGMENT, program -> {
|
||||||
program.bind();
|
program.bind();
|
||||||
program.setSamplerBinding("flw_diffuseTex", 0);
|
program.setSamplerBinding("_flw_diffuseTex", 0);
|
||||||
program.setSamplerBinding("flw_overlayTex", 1);
|
program.setSamplerBinding("_flw_overlayTex", 1);
|
||||||
program.setSamplerBinding("flw_lightTex", 2);
|
program.setSamplerBinding("_flw_lightTex", 2);
|
||||||
GlProgram.unbind();
|
GlProgram.unbind();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
public static final SimpleContext CRUMBLING = Context.REGISTRY.registerAndGet(new SimpleContext(Files.CRUMBLING_VERTEX, Files.CRUMBLING_FRAGMENT, program -> {
|
public static final SimpleContext CRUMBLING = Context.REGISTRY.registerAndGet(new SimpleContext(Files.CRUMBLING_VERTEX, Files.CRUMBLING_FRAGMENT, program -> {
|
||||||
program.bind();
|
program.bind();
|
||||||
program.setSamplerBinding("flw_crumblingTex", 0);
|
program.setSamplerBinding("_flw_crumblingTex", 0);
|
||||||
program.setSamplerBinding("flw_diffuseTex", 1);
|
program.setSamplerBinding("_flw_diffuseTex", 1);
|
||||||
GlProgram.unbind();
|
GlProgram.unbind();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
@ -28,81 +28,91 @@ public final class Materials {
|
||||||
private static final ResourceLocation MINECART_LOCATION = new ResourceLocation("textures/entity/minecart.png");
|
private static final ResourceLocation MINECART_LOCATION = new ResourceLocation("textures/entity/minecart.png");
|
||||||
|
|
||||||
public static final Material CHUNK_SOLID_SHADED = SimpleMaterial.builder()
|
public static final Material CHUNK_SOLID_SHADED = SimpleMaterial.builder()
|
||||||
|
.useOverlay(false)
|
||||||
.fallbackRenderType(RenderType.solid())
|
.fallbackRenderType(RenderType.solid())
|
||||||
.vertexTransformer(SHADING_TRANSFORMER)
|
.vertexTransformer(SHADING_TRANSFORMER)
|
||||||
.build();
|
.build();
|
||||||
public static final Material CHUNK_SOLID_UNSHADED = SimpleMaterial.builder()
|
public static final Material CHUNK_SOLID_UNSHADED = SimpleMaterial.builder()
|
||||||
|
.useOverlay(false)
|
||||||
.diffuse(false)
|
.diffuse(false)
|
||||||
.fallbackRenderType(RenderType.solid())
|
.fallbackRenderType(RenderType.solid())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static final Material CHUNK_CUTOUT_MIPPED_SHADED = SimpleMaterial.builder()
|
public static final Material CHUNK_CUTOUT_MIPPED_SHADED = SimpleMaterial.builder()
|
||||||
.cutout(CutoutShaders.EPSILON)
|
.cutout(CutoutShaders.EPSILON)
|
||||||
|
.useOverlay(false)
|
||||||
.fallbackRenderType(RenderType.cutoutMipped())
|
.fallbackRenderType(RenderType.cutoutMipped())
|
||||||
.vertexTransformer(SHADING_TRANSFORMER)
|
.vertexTransformer(SHADING_TRANSFORMER)
|
||||||
.build();
|
.build();
|
||||||
public static final Material CHUNK_CUTOUT_MIPPED_UNSHADED = SimpleMaterial.builder()
|
public static final Material CHUNK_CUTOUT_MIPPED_UNSHADED = SimpleMaterial.builder()
|
||||||
.diffuse(false)
|
|
||||||
.cutout(CutoutShaders.EPSILON)
|
.cutout(CutoutShaders.EPSILON)
|
||||||
|
.useOverlay(false)
|
||||||
|
.diffuse(false)
|
||||||
.fallbackRenderType(RenderType.cutoutMipped())
|
.fallbackRenderType(RenderType.cutoutMipped())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static final Material CHUNK_CUTOUT_SHADED = SimpleMaterial.builder()
|
public static final Material CHUNK_CUTOUT_SHADED = SimpleMaterial.builder()
|
||||||
.mip(false)
|
|
||||||
.cutout(CutoutShaders.EPSILON)
|
.cutout(CutoutShaders.EPSILON)
|
||||||
|
.mipmap(false)
|
||||||
|
.useOverlay(false)
|
||||||
.fallbackRenderType(RenderType.cutout())
|
.fallbackRenderType(RenderType.cutout())
|
||||||
.vertexTransformer(SHADING_TRANSFORMER)
|
.vertexTransformer(SHADING_TRANSFORMER)
|
||||||
.build();
|
.build();
|
||||||
public static final Material CHUNK_CUTOUT_UNSHADED = SimpleMaterial.builder()
|
public static final Material CHUNK_CUTOUT_UNSHADED = SimpleMaterial.builder()
|
||||||
.diffuse(false)
|
|
||||||
.mip(false)
|
|
||||||
.cutout(CutoutShaders.EPSILON)
|
.cutout(CutoutShaders.EPSILON)
|
||||||
|
.mipmap(false)
|
||||||
|
.useOverlay(false)
|
||||||
|
.diffuse(false)
|
||||||
.fallbackRenderType(RenderType.cutout())
|
.fallbackRenderType(RenderType.cutout())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static final Material CHUNK_TRANSLUCENT_SHADED = SimpleMaterial.builder()
|
public static final Material CHUNK_TRANSLUCENT_SHADED = SimpleMaterial.builder()
|
||||||
.transparency(Transparency.TRANSLUCENT)
|
.transparency(Transparency.TRANSLUCENT)
|
||||||
|
.useOverlay(false)
|
||||||
.fallbackRenderType(RenderType.translucent())
|
.fallbackRenderType(RenderType.translucent())
|
||||||
.vertexTransformer(SHADING_TRANSFORMER)
|
.vertexTransformer(SHADING_TRANSFORMER)
|
||||||
.build();
|
.build();
|
||||||
public static final Material CHUNK_TRANSLUCENT_UNSHADED = SimpleMaterial.builder()
|
public static final Material CHUNK_TRANSLUCENT_UNSHADED = SimpleMaterial.builder()
|
||||||
.diffuse(false)
|
|
||||||
.transparency(Transparency.TRANSLUCENT)
|
.transparency(Transparency.TRANSLUCENT)
|
||||||
|
.useOverlay(false)
|
||||||
|
.diffuse(false)
|
||||||
.fallbackRenderType(RenderType.translucent())
|
.fallbackRenderType(RenderType.translucent())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static final Material CHUNK_TRIPWIRE_SHADED = SimpleMaterial.builder()
|
public static final Material CHUNK_TRIPWIRE_SHADED = SimpleMaterial.builder()
|
||||||
.transparency(Transparency.TRANSLUCENT)
|
|
||||||
.cutout(CutoutShaders.EPSILON)
|
.cutout(CutoutShaders.EPSILON)
|
||||||
|
.transparency(Transparency.TRANSLUCENT)
|
||||||
|
.useOverlay(false)
|
||||||
.fallbackRenderType(RenderType.tripwire())
|
.fallbackRenderType(RenderType.tripwire())
|
||||||
.vertexTransformer(SHADING_TRANSFORMER)
|
.vertexTransformer(SHADING_TRANSFORMER)
|
||||||
.build();
|
.build();
|
||||||
public static final Material CHUNK_TRIPWIRE_UNSHADED = SimpleMaterial.builder()
|
public static final Material CHUNK_TRIPWIRE_UNSHADED = SimpleMaterial.builder()
|
||||||
.diffuse(false)
|
|
||||||
.transparency(Transparency.TRANSLUCENT)
|
|
||||||
.cutout(CutoutShaders.EPSILON)
|
.cutout(CutoutShaders.EPSILON)
|
||||||
|
.transparency(Transparency.TRANSLUCENT)
|
||||||
|
.useOverlay(false)
|
||||||
|
.diffuse(false)
|
||||||
.fallbackRenderType(RenderType.tripwire())
|
.fallbackRenderType(RenderType.tripwire())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static final Material CHEST = SimpleMaterial.builder()
|
public static final Material CHEST = SimpleMaterial.builder()
|
||||||
.baseTexture(Sheets.CHEST_SHEET)
|
.baseTexture(Sheets.CHEST_SHEET)
|
||||||
.mip(false)
|
.mipmap(false)
|
||||||
.fallbackRenderType(Sheets.chestSheet())
|
.fallbackRenderType(Sheets.chestSheet())
|
||||||
.build();
|
.build();
|
||||||
public static final Material SHULKER = SimpleMaterial.builder()
|
public static final Material SHULKER = SimpleMaterial.builder()
|
||||||
.baseTexture(Sheets.SHULKER_SHEET)
|
|
||||||
.mip(false)
|
|
||||||
.backfaceCull(false)
|
|
||||||
.cutout(CutoutShaders.EPSILON)
|
.cutout(CutoutShaders.EPSILON)
|
||||||
|
.baseTexture(Sheets.SHULKER_SHEET)
|
||||||
|
.mipmap(false)
|
||||||
|
.backfaceCulling(false)
|
||||||
.fallbackRenderType(Sheets.shulkerBoxSheet())
|
.fallbackRenderType(Sheets.shulkerBoxSheet())
|
||||||
.build();
|
.build();
|
||||||
public static final Material BELL = SimpleMaterial.builder()
|
public static final Material BELL = SimpleMaterial.builder()
|
||||||
.mip(false)
|
.mipmap(false)
|
||||||
.fallbackRenderType(Sheets.solidBlockSheet())
|
.fallbackRenderType(Sheets.solidBlockSheet())
|
||||||
.build();
|
.build();
|
||||||
public static final Material MINECART = SimpleMaterial.builder()
|
public static final Material MINECART = SimpleMaterial.builder()
|
||||||
.baseTexture(MINECART_LOCATION)
|
.baseTexture(MINECART_LOCATION)
|
||||||
.mip(false)
|
.mipmap(false)
|
||||||
.fallbackRenderType(RenderType.entitySolid(MINECART_LOCATION))
|
.fallbackRenderType(RenderType.entitySolid(MINECART_LOCATION))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.jozufozu.flywheel.lib.material;
|
package com.jozufozu.flywheel.lib.material;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.api.material.CutoutShader;
|
import com.jozufozu.flywheel.api.material.CutoutShader;
|
||||||
|
import com.jozufozu.flywheel.api.material.DepthTest;
|
||||||
import com.jozufozu.flywheel.api.material.FogShader;
|
import com.jozufozu.flywheel.api.material.FogShader;
|
||||||
import com.jozufozu.flywheel.api.material.Material;
|
import com.jozufozu.flywheel.api.material.Material;
|
||||||
import com.jozufozu.flywheel.api.material.MaterialShaders;
|
import com.jozufozu.flywheel.api.material.MaterialShaders;
|
||||||
|
@ -13,52 +14,54 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.inventory.InventoryMenu;
|
import net.minecraft.world.inventory.InventoryMenu;
|
||||||
|
|
||||||
public class SimpleMaterial implements Material {
|
public class SimpleMaterial implements Material {
|
||||||
protected final MaterialShaders shaders;
|
|
||||||
protected final RenderType fallbackRenderType;
|
protected final RenderType fallbackRenderType;
|
||||||
protected final MaterialVertexTransformer vertexTransformer;
|
protected final MaterialVertexTransformer vertexTransformer;
|
||||||
|
|
||||||
protected final ResourceLocation baseTexture;
|
protected final MaterialShaders shaders;
|
||||||
protected final boolean diffuse;
|
|
||||||
protected final boolean lighting;
|
|
||||||
protected final boolean blur;
|
|
||||||
protected final boolean backfaceCull;
|
|
||||||
protected final boolean polygonOffset;
|
|
||||||
protected final boolean mip;
|
|
||||||
protected final FogShader fog;
|
protected final FogShader fog;
|
||||||
protected final Transparency transparency;
|
|
||||||
protected final CutoutShader cutout;
|
protected final CutoutShader cutout;
|
||||||
|
|
||||||
|
protected final ResourceLocation baseTexture;
|
||||||
|
protected final boolean blur;
|
||||||
|
protected final boolean mipmap;
|
||||||
|
|
||||||
|
protected final boolean backfaceCulling;
|
||||||
|
protected final boolean polygonOffset;
|
||||||
|
protected final DepthTest depthTest;
|
||||||
|
protected final Transparency transparency;
|
||||||
protected final WriteMask writeMask;
|
protected final WriteMask writeMask;
|
||||||
|
|
||||||
|
protected final boolean useOverlay;
|
||||||
|
protected final boolean useLight;
|
||||||
|
protected final boolean diffuse;
|
||||||
|
|
||||||
protected SimpleMaterial(Builder builder) {
|
protected SimpleMaterial(Builder builder) {
|
||||||
this.shaders = builder.shaders;
|
fallbackRenderType = builder.getFallbackRenderType();
|
||||||
this.fallbackRenderType = builder.fallbackRenderType;
|
vertexTransformer = builder.getVertexTransformer();
|
||||||
this.vertexTransformer = builder.vertexTransformer;
|
shaders = builder.shaders();
|
||||||
this.baseTexture = builder.baseTexture;
|
fog = builder.fog();
|
||||||
this.diffuse = builder.diffuse;
|
cutout = builder.cutout();
|
||||||
this.lighting = builder.lighting;
|
baseTexture = builder.baseTexture();
|
||||||
this.blur = builder.blur;
|
blur = builder.blur();
|
||||||
this.backfaceCull = builder.backfaceCull;
|
mipmap = builder.mipmap();
|
||||||
this.polygonOffset = builder.polygonOffset;
|
backfaceCulling = builder.backfaceCulling();
|
||||||
this.mip = builder.mip;
|
polygonOffset = builder.polygonOffset();
|
||||||
this.fog = builder.fog;
|
depthTest = builder.depthTest();
|
||||||
this.transparency = builder.transparency;
|
transparency = builder.transparency();
|
||||||
this.cutout = builder.cutout;
|
writeMask = builder.writeMask();
|
||||||
this.writeMask = builder.writeMask;
|
useOverlay = builder.useOverlay();
|
||||||
|
useLight = builder.useLight();
|
||||||
|
diffuse = builder.diffuse();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
return new Builder();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder from(Material material) {
|
public static Builder builderOf(Material material) {
|
||||||
return new Builder(material);
|
return new Builder(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public MaterialShaders shaders() {
|
|
||||||
return shaders;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RenderType getFallbackRenderType() {
|
public RenderType getFallbackRenderType() {
|
||||||
return fallbackRenderType;
|
return fallbackRenderType;
|
||||||
|
@ -70,38 +73,8 @@ public class SimpleMaterial implements Material {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation baseTexture() {
|
public MaterialShaders shaders() {
|
||||||
return baseTexture;
|
return shaders;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean diffuse() {
|
|
||||||
return diffuse;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean lighting() {
|
|
||||||
return lighting;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean blur() {
|
|
||||||
return blur;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean backfaceCull() {
|
|
||||||
return backfaceCull;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean polygonOffset() {
|
|
||||||
return polygonOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mip() {
|
|
||||||
return mip;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -110,13 +83,43 @@ public class SimpleMaterial implements Material {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Transparency transparency() {
|
public CutoutShader cutout() {
|
||||||
return transparency;
|
return cutout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CutoutShader cutout() {
|
public ResourceLocation baseTexture() {
|
||||||
return cutout;
|
return baseTexture;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean blur() {
|
||||||
|
return blur;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mipmap() {
|
||||||
|
return mipmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean backfaceCulling() {
|
||||||
|
return backfaceCulling;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean polygonOffset() {
|
||||||
|
return polygonOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DepthTest depthTest() {
|
||||||
|
return depthTest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Transparency transparency() {
|
||||||
|
return transparency;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -124,55 +127,85 @@ public class SimpleMaterial implements Material {
|
||||||
return writeMask;
|
return writeMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean useOverlay() {
|
||||||
|
return useOverlay;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean useLight() {
|
||||||
|
return useLight;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean diffuse() {
|
||||||
|
return diffuse;
|
||||||
|
}
|
||||||
|
|
||||||
public static class Builder implements Material {
|
public static class Builder implements Material {
|
||||||
protected RenderType fallbackRenderType;
|
protected RenderType fallbackRenderType;
|
||||||
protected MaterialVertexTransformer vertexTransformer;
|
protected MaterialVertexTransformer vertexTransformer;
|
||||||
|
|
||||||
protected MaterialShaders shaders;
|
protected MaterialShaders shaders;
|
||||||
protected ResourceLocation baseTexture;
|
|
||||||
protected boolean diffuse;
|
|
||||||
protected boolean lighting;
|
|
||||||
protected boolean blur;
|
|
||||||
protected boolean backfaceCull;
|
|
||||||
protected boolean polygonOffset;
|
|
||||||
protected boolean mip;
|
|
||||||
protected FogShader fog;
|
protected FogShader fog;
|
||||||
protected Transparency transparency;
|
|
||||||
protected CutoutShader cutout;
|
protected CutoutShader cutout;
|
||||||
|
|
||||||
|
protected ResourceLocation baseTexture;
|
||||||
|
protected boolean blur;
|
||||||
|
protected boolean mipmap;
|
||||||
|
|
||||||
|
protected boolean backfaceCulling;
|
||||||
|
protected boolean polygonOffset;
|
||||||
|
protected DepthTest depthTest;
|
||||||
|
protected Transparency transparency;
|
||||||
protected WriteMask writeMask;
|
protected WriteMask writeMask;
|
||||||
|
|
||||||
|
protected boolean useOverlay;
|
||||||
|
protected boolean useLight;
|
||||||
|
protected boolean diffuse;
|
||||||
|
|
||||||
public Builder() {
|
public Builder() {
|
||||||
fallbackRenderType = RenderType.solid();
|
fallbackRenderType = RenderType.solid();
|
||||||
vertexTransformer = (vertexList, level) -> {
|
vertexTransformer = (vertexList, level) -> {
|
||||||
};
|
};
|
||||||
shaders = StandardMaterialShaders.DEFAULT;
|
shaders = StandardMaterialShaders.DEFAULT;
|
||||||
baseTexture = InventoryMenu.BLOCK_ATLAS;
|
|
||||||
diffuse = true;
|
|
||||||
lighting = true;
|
|
||||||
blur = false;
|
|
||||||
backfaceCull = true;
|
|
||||||
polygonOffset = false;
|
|
||||||
mip = true;
|
|
||||||
fog = FogShaders.LINEAR;
|
fog = FogShaders.LINEAR;
|
||||||
transparency = Transparency.OPAQUE;
|
|
||||||
cutout = CutoutShaders.OFF;
|
cutout = CutoutShaders.OFF;
|
||||||
|
baseTexture = InventoryMenu.BLOCK_ATLAS;
|
||||||
|
blur = false;
|
||||||
|
mipmap = true;
|
||||||
|
backfaceCulling = true;
|
||||||
|
polygonOffset = false;
|
||||||
|
depthTest = DepthTest.LEQUAL;
|
||||||
|
transparency = Transparency.OPAQUE;
|
||||||
writeMask = WriteMask.BOTH;
|
writeMask = WriteMask.BOTH;
|
||||||
|
useOverlay = true;
|
||||||
|
useLight = true;
|
||||||
|
diffuse = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder(Material material) {
|
public Builder(Material material) {
|
||||||
|
copyFrom(material);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder copyFrom(Material material) {
|
||||||
fallbackRenderType = material.getFallbackRenderType();
|
fallbackRenderType = material.getFallbackRenderType();
|
||||||
vertexTransformer = material.getVertexTransformer();
|
vertexTransformer = material.getVertexTransformer();
|
||||||
shaders = material.shaders();
|
shaders = material.shaders();
|
||||||
baseTexture = material.baseTexture();
|
|
||||||
diffuse = material.diffuse();
|
|
||||||
lighting = material.lighting();
|
|
||||||
blur = material.blur();
|
|
||||||
backfaceCull = material.backfaceCull();
|
|
||||||
polygonOffset = material.polygonOffset();
|
|
||||||
mip = material.mip();
|
|
||||||
fog = material.fog();
|
fog = material.fog();
|
||||||
transparency = material.transparency();
|
|
||||||
cutout = material.cutout();
|
cutout = material.cutout();
|
||||||
|
baseTexture = material.baseTexture();
|
||||||
|
blur = material.blur();
|
||||||
|
mipmap = material.mipmap();
|
||||||
|
backfaceCulling = material.backfaceCulling();
|
||||||
|
polygonOffset = material.polygonOffset();
|
||||||
|
depthTest = material.depthTest();
|
||||||
|
transparency = material.transparency();
|
||||||
writeMask = material.writeMask();
|
writeMask = material.writeMask();
|
||||||
|
useOverlay = material.useOverlay();
|
||||||
|
useLight = material.useLight();
|
||||||
|
diffuse = material.diffuse();
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder fallbackRenderType(RenderType type) {
|
public Builder fallbackRenderType(RenderType type) {
|
||||||
|
@ -190,64 +223,69 @@ public class SimpleMaterial implements Material {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder baseTexture(ResourceLocation value) {
|
|
||||||
this.baseTexture = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder diffuse(boolean value) {
|
|
||||||
this.diffuse = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder lighting(boolean value) {
|
|
||||||
this.lighting = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder blur(boolean value) {
|
|
||||||
this.blur = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder backfaceCull(boolean value) {
|
|
||||||
this.backfaceCull = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder polygonOffset(boolean value) {
|
|
||||||
this.polygonOffset = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder mip(boolean value) {
|
|
||||||
this.mip = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder fog(FogShader value) {
|
public Builder fog(FogShader value) {
|
||||||
this.fog = value;
|
this.fog = value;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder transparency(Transparency value) {
|
|
||||||
this.transparency = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder cutout(CutoutShader value) {
|
public Builder cutout(CutoutShader value) {
|
||||||
this.cutout = value;
|
this.cutout = value;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder baseTexture(ResourceLocation value) {
|
||||||
|
this.baseTexture = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder blur(boolean value) {
|
||||||
|
this.blur = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder mipmap(boolean value) {
|
||||||
|
this.mipmap = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder backfaceCulling(boolean value) {
|
||||||
|
this.backfaceCulling = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder polygonOffset(boolean value) {
|
||||||
|
this.polygonOffset = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder depthTest(DepthTest value) {
|
||||||
|
this.depthTest = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder transparency(Transparency value) {
|
||||||
|
this.transparency = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Builder writeMask(WriteMask value) {
|
public Builder writeMask(WriteMask value) {
|
||||||
this.writeMask = value;
|
this.writeMask = value;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public Builder useOverlay(boolean value) {
|
||||||
public MaterialShaders shaders() {
|
this.useOverlay = value;
|
||||||
return shaders;
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder useLight(boolean value) {
|
||||||
|
this.useLight = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder diffuse(boolean value) {
|
||||||
|
this.diffuse = value;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -261,38 +299,8 @@ public class SimpleMaterial implements Material {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation baseTexture() {
|
public MaterialShaders shaders() {
|
||||||
return baseTexture;
|
return shaders;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean diffuse() {
|
|
||||||
return diffuse;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean lighting() {
|
|
||||||
return lighting;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean blur() {
|
|
||||||
return blur;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean backfaceCull() {
|
|
||||||
return backfaceCull;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean polygonOffset() {
|
|
||||||
return polygonOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mip() {
|
|
||||||
return mip;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -301,13 +309,43 @@ public class SimpleMaterial implements Material {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Transparency transparency() {
|
public CutoutShader cutout() {
|
||||||
return transparency;
|
return cutout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CutoutShader cutout() {
|
public ResourceLocation baseTexture() {
|
||||||
return cutout;
|
return baseTexture;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean blur() {
|
||||||
|
return blur;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mipmap() {
|
||||||
|
return mipmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean backfaceCulling() {
|
||||||
|
return backfaceCulling;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean polygonOffset() {
|
||||||
|
return polygonOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DepthTest depthTest() {
|
||||||
|
return depthTest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Transparency transparency() {
|
||||||
|
return transparency;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -315,6 +353,21 @@ public class SimpleMaterial implements Material {
|
||||||
return writeMask;
|
return writeMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean useOverlay() {
|
||||||
|
return useOverlay;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean useLight() {
|
||||||
|
return useLight;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean diffuse() {
|
||||||
|
return diffuse;
|
||||||
|
}
|
||||||
|
|
||||||
public SimpleMaterial build() {
|
public SimpleMaterial build() {
|
||||||
return new SimpleMaterial(this);
|
return new SimpleMaterial(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,10 @@
|
||||||
/*const*/ vec4 flw_var2;
|
/*const*/ vec4 flw_var2;
|
||||||
/*const*/ vec4 flw_var3;
|
/*const*/ vec4 flw_var3;
|
||||||
|
|
||||||
/*const*/ vec4 flw_sampleColor;
|
|
||||||
|
|
||||||
/*const*/ FlwMaterial flw_material;
|
/*const*/ FlwMaterial flw_material;
|
||||||
|
|
||||||
|
/*const*/ vec4 flw_sampleColor;
|
||||||
|
|
||||||
vec4 flw_fragColor;
|
vec4 flw_fragColor;
|
||||||
ivec2 flw_fragOverlay;
|
ivec2 flw_fragOverlay;
|
||||||
vec2 flw_fragLight;
|
vec2 flw_fragLight;
|
||||||
|
|
|
@ -1,22 +1,33 @@
|
||||||
const uint FLW_TRANSPARENCY_OPAQUE = 0u;
|
const uint FLW_MAT_DEPTH_TEST_OFF = 0u;
|
||||||
const uint FLW_TRANSPARENCY_ADDITIVE = 1u;
|
const uint FLW_MAT_DEPTH_TEST_NEVER = 1u;
|
||||||
const uint FLW_TRANSPARENCY_LIGHTING = 2u;
|
const uint FLW_MAT_DEPTH_TEST_LESS = 2u;
|
||||||
const uint FLW_TRANSPARENCY_GLINT = 3u;
|
const uint FLW_MAT_DEPTH_TEST_EQUAL = 3u;
|
||||||
const uint FLW_TRANSPARENCY_CRUMBLING = 4u;
|
const uint FLW_MAT_DEPTH_TEST_LEQUAL = 4u;
|
||||||
const uint FLW_TRANSPARENCY_TRANSLUCENT = 5u;
|
const uint FLW_MAT_DEPTH_TEST_GREATER = 5u;
|
||||||
|
const uint FLW_MAT_DEPTH_TEST_NOTEQUAL = 6u;
|
||||||
|
const uint FLW_MAT_DEPTH_TEST_GEQUAL = 7u;
|
||||||
|
const uint FLW_MAT_DEPTH_TEST_ALWAYS = 8u;
|
||||||
|
|
||||||
const uint FLW_WRITE_MASK_BOTH = 0u;
|
const uint FLW_MAT_TRANSPARENCY_OPAQUE = 0u;
|
||||||
const uint FLW_WRITE_MASK_COLOR = 1u;
|
const uint FLW_MAT_TRANSPARENCY_ADDITIVE = 1u;
|
||||||
const uint FLW_WRITE_MASK_DEPTH = 2u;
|
const uint FLW_MAT_TRANSPARENCY_LIGHTING = 2u;
|
||||||
|
const uint FLW_MAT_TRANSPARENCY_GLINT = 3u;
|
||||||
|
const uint FLW_MAT_TRANSPARENCY_CRUMBLING = 4u;
|
||||||
|
const uint FLW_MAT_TRANSPARENCY_TRANSLUCENT = 5u;
|
||||||
|
|
||||||
|
const uint FLW_MAT_WRITE_MASK_BOTH = 0u;
|
||||||
|
const uint FLW_MAT_WRITE_MASK_COLOR = 1u;
|
||||||
|
const uint FLW_MAT_WRITE_MASK_DEPTH = 2u;
|
||||||
|
|
||||||
struct FlwMaterial {
|
struct FlwMaterial {
|
||||||
bool diffuse;
|
|
||||||
bool lighting;
|
|
||||||
bool blur;
|
bool blur;
|
||||||
bool backfaceCull;
|
bool mipmap;
|
||||||
|
bool backfaceCulling;
|
||||||
bool polygonOffset;
|
bool polygonOffset;
|
||||||
bool mip;
|
uint depthTest;
|
||||||
|
|
||||||
uint writeMask;
|
|
||||||
uint transparency;
|
uint transparency;
|
||||||
|
uint writeMask;
|
||||||
|
bool useOverlay;
|
||||||
|
bool useLight;
|
||||||
|
bool diffuse;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
#include "flywheel:api/fragment.glsl"
|
#include "flywheel:api/fragment.glsl"
|
||||||
|
|
||||||
uniform sampler2D flw_crumblingTex;
|
uniform sampler2D _flw_crumblingTex;
|
||||||
|
|
||||||
in vec2 _flw_crumblingTexCoord;
|
in vec2 crumblingTexCoord;
|
||||||
|
|
||||||
vec4 flw_crumblingSampleColor;
|
vec4 crumblingSampleColor;
|
||||||
|
|
||||||
void flw_beginFragment() {
|
void flw_beginFragment() {
|
||||||
flw_crumblingSampleColor = texture(flw_crumblingTex, _flw_crumblingTexCoord);
|
crumblingSampleColor = texture(_flw_crumblingTex, crumblingTexCoord);
|
||||||
|
|
||||||
// Make the crumbling overlay transparent when the diffuse layer is transparent.
|
// Make the crumbling overlay transparent when the diffuse layer is transparent.
|
||||||
flw_crumblingSampleColor.a *= flw_fragColor.a;
|
crumblingSampleColor.a *= flw_fragColor.a;
|
||||||
|
|
||||||
if (flw_crumblingSampleColor.a < 0.01) {
|
if (crumblingSampleColor.a < 0.01) {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void flw_endFragment() {
|
void flw_endFragment() {
|
||||||
flw_fragColor = flw_crumblingSampleColor;
|
flw_fragColor = crumblingSampleColor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "flywheel:api/vertex.glsl"
|
#include "flywheel:api/vertex.glsl"
|
||||||
#include "flywheel:util/fog.glsl"
|
#include "flywheel:util/fog.glsl"
|
||||||
|
|
||||||
out vec2 _flw_crumblingTexCoord;
|
out vec2 crumblingTexCoord;
|
||||||
|
|
||||||
const int DOWN = 0;
|
const int DOWN = 0;
|
||||||
const int UP = 1;
|
const int UP = 1;
|
||||||
|
@ -66,9 +66,8 @@ vec2 getCrumblingTexCoord() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void flw_beginVertex() {
|
void flw_beginVertex() {
|
||||||
// no-op
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void flw_endVertex() {
|
void flw_endVertex() {
|
||||||
_flw_crumblingTexCoord = getCrumblingTexCoord();
|
crumblingTexCoord = getCrumblingTexCoord();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
#include "flywheel:api/fragment.glsl"
|
#include "flywheel:api/fragment.glsl"
|
||||||
|
|
||||||
void flw_beginFragment() {
|
void flw_beginFragment() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void flw_endFragment() {
|
void flw_endFragment() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,7 @@
|
||||||
#include "flywheel:util/fog.glsl"
|
#include "flywheel:util/fog.glsl"
|
||||||
|
|
||||||
void flw_beginVertex() {
|
void flw_beginVertex() {
|
||||||
// noop
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void flw_endVertex() {
|
void flw_endVertex() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
#include "flywheel:api/vertex.glsl"
|
#include "flywheel:api/vertex.glsl"
|
||||||
|
|
||||||
layout(location = 0) in vec3 _flw_v_pos;
|
layout(location = 0) in vec3 v_pos;
|
||||||
layout(location = 1) in vec4 _flw_v_color;
|
layout(location = 1) in vec4 v_color;
|
||||||
layout(location = 2) in vec2 _flw_v_texCoord;
|
layout(location = 2) in vec2 v_texCoord;
|
||||||
layout(location = 3) in ivec2 _flw_v_light;
|
layout(location = 3) in ivec2 v_light;
|
||||||
layout(location = 4) in vec3 _flw_v_normal;
|
layout(location = 4) in vec3 v_normal;
|
||||||
|
|
||||||
void _flw_layoutVertex() {
|
void _flw_layoutVertex() {
|
||||||
flw_vertexPos = vec4(_flw_v_pos, 1.0);
|
flw_vertexPos = vec4(v_pos, 1.0);
|
||||||
flw_vertexColor = _flw_v_color;
|
flw_vertexColor = v_color;
|
||||||
flw_vertexTexCoord = _flw_v_texCoord;
|
flw_vertexTexCoord = v_texCoord;
|
||||||
flw_vertexOverlay = ivec2(0, 10);
|
flw_vertexOverlay = ivec2(0, 10);
|
||||||
flw_vertexLight = _flw_v_light / 15.0;
|
flw_vertexLight = v_light / 15.0;
|
||||||
flw_vertexNormal = _flw_v_normal;
|
flw_vertexNormal = v_normal;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,14 @@ in vec4 flw_var1;
|
||||||
in vec4 flw_var2;
|
in vec4 flw_var2;
|
||||||
in vec4 flw_var3;
|
in vec4 flw_var3;
|
||||||
|
|
||||||
|
FlwMaterial flw_material;
|
||||||
|
|
||||||
vec4 flw_sampleColor;
|
vec4 flw_sampleColor;
|
||||||
|
|
||||||
vec4 flw_fragColor;
|
vec4 flw_fragColor;
|
||||||
ivec2 flw_fragOverlay;
|
ivec2 flw_fragOverlay;
|
||||||
vec2 flw_fragLight;
|
vec2 flw_fragLight;
|
||||||
|
|
||||||
FlwMaterial flw_material;
|
|
||||||
|
|
||||||
vec4 flw_fogFilter(vec4 color);
|
vec4 flw_fogFilter(vec4 color);
|
||||||
|
|
||||||
bool flw_discardPredicate(vec4 finalColor);
|
bool flw_discardPredicate(vec4 finalColor);
|
||||||
|
|
|
@ -2,27 +2,25 @@
|
||||||
#include "flywheel:internal/material.glsl"
|
#include "flywheel:internal/material.glsl"
|
||||||
|
|
||||||
// optimize discard usage
|
// optimize discard usage
|
||||||
#ifdef ALPHA_DISCARD
|
|
||||||
#ifdef GL_ARB_conservative_depth
|
#ifdef GL_ARB_conservative_depth
|
||||||
layout (depth_greater) out float gl_FragDepth;
|
layout (depth_greater) out float gl_FragDepth;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
uniform sampler2D flw_diffuseTex;
|
uniform sampler2D _flw_diffuseTex;
|
||||||
uniform sampler2D flw_overlayTex;
|
uniform sampler2D _flw_overlayTex;
|
||||||
uniform sampler2D flw_lightTex;
|
uniform sampler2D _flw_lightTex;
|
||||||
|
|
||||||
flat in uvec3 _flw_material;
|
flat in uvec3 _flw_material;
|
||||||
|
|
||||||
out vec4 fragColor;
|
out vec4 _flw_fragColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
_flw_materialFragmentID = _flw_material.x;
|
_flw_materialFragmentID = _flw_material.x;
|
||||||
|
|
||||||
_flw_unpackUint2x16(_flw_material.y, _flw_cutoutID, _flw_fogID);
|
_flw_unpackUint2x16(_flw_material.y, _flw_cutoutID, _flw_fogID);
|
||||||
_flw_unpackMaterial(_flw_material.z, flw_material);
|
_flw_unpackMaterialProperties(_flw_material.z, flw_material);
|
||||||
|
|
||||||
flw_sampleColor = texture(flw_diffuseTex, flw_vertexTexCoord);
|
flw_sampleColor = texture(_flw_diffuseTex, flw_vertexTexCoord);
|
||||||
flw_fragColor = flw_vertexColor * flw_sampleColor;
|
flw_fragColor = flw_vertexColor * flw_sampleColor;
|
||||||
flw_fragOverlay = flw_vertexOverlay;
|
flw_fragOverlay = flw_vertexOverlay;
|
||||||
flw_fragLight = flw_vertexLight;
|
flw_fragLight = flw_vertexLight;
|
||||||
|
@ -31,17 +29,15 @@ void main() {
|
||||||
flw_materialFragment();
|
flw_materialFragment();
|
||||||
flw_endFragment();
|
flw_endFragment();
|
||||||
|
|
||||||
vec4 overlayColor = texelFetch(flw_overlayTex, flw_fragOverlay, 0);
|
|
||||||
vec4 lightColor = texture(flw_lightTex, (flw_fragLight * 15.0 + 0.5) / 16.0);
|
|
||||||
|
|
||||||
vec4 color = flw_fragColor;
|
vec4 color = flw_fragColor;
|
||||||
color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a);
|
|
||||||
|
|
||||||
if (flw_material.lighting) {
|
if (flw_material.useOverlay) {
|
||||||
color *= lightColor;
|
vec4 overlayColor = texelFetch(_flw_overlayTex, flw_fragOverlay, 0);
|
||||||
|
color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flw_material.lighting) {
|
if (flw_material.useLight) {
|
||||||
|
vec4 lightColor = texture(_flw_lightTex, (flw_fragLight * 15.0 + 0.5) / 16.0);
|
||||||
color *= lightColor;
|
color *= lightColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,5 +45,5 @@ void main() {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
|
||||||
fragColor = flw_fogFilter(color);
|
_flw_fragColor = flw_fogFilter(color);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ void main() {
|
||||||
_flw_materialVertexID = drawCommands[batchID].vertexMaterialID;
|
_flw_materialVertexID = drawCommands[batchID].vertexMaterialID;
|
||||||
uint p = drawCommands[batchID].packedMaterialProperties;
|
uint p = drawCommands[batchID].packedMaterialProperties;
|
||||||
|
|
||||||
_flw_unpackMaterial(p, flw_material);
|
_flw_unpackMaterialProperties(p, flw_material);
|
||||||
_flw_material = uvec3(drawCommands[batchID].fragmentMaterialID, drawCommands[batchID].packedFogAndCutout, p);
|
_flw_material = uvec3(drawCommands[batchID].fragmentMaterialID, drawCommands[batchID].packedFogAndCutout, p);
|
||||||
|
|
||||||
_flw_layoutVertex();
|
_flw_layoutVertex();
|
||||||
|
|
|
@ -2,27 +2,25 @@
|
||||||
#include "flywheel:internal/material.glsl"
|
#include "flywheel:internal/material.glsl"
|
||||||
|
|
||||||
// optimize discard usage
|
// optimize discard usage
|
||||||
#ifdef ALPHA_DISCARD
|
|
||||||
#ifdef GL_ARB_conservative_depth
|
#ifdef GL_ARB_conservative_depth
|
||||||
layout (depth_greater) out float gl_FragDepth;
|
layout (depth_greater) out float gl_FragDepth;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
uniform sampler2D flw_diffuseTex;
|
uniform sampler2D _flw_diffuseTex;
|
||||||
uniform sampler2D flw_overlayTex;
|
uniform sampler2D _flw_overlayTex;
|
||||||
uniform sampler2D flw_lightTex;
|
uniform sampler2D _flw_lightTex;
|
||||||
|
|
||||||
uniform uvec4 _flw_material_instancing;
|
uniform uvec4 _flw_packedMaterial;
|
||||||
|
|
||||||
out vec4 fragColor;
|
out vec4 _flw_fragColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
_flw_materialFragmentID = _flw_material_instancing.y;
|
_flw_materialFragmentID = _flw_packedMaterial.y;
|
||||||
|
|
||||||
_flw_unpackUint2x16(_flw_material_instancing.z, _flw_cutoutID, _flw_fogID);
|
_flw_unpackUint2x16(_flw_packedMaterial.z, _flw_cutoutID, _flw_fogID);
|
||||||
_flw_unpackMaterial(_flw_material_instancing.w, flw_material);
|
_flw_unpackMaterialProperties(_flw_packedMaterial.w, flw_material);
|
||||||
|
|
||||||
flw_sampleColor = texture(flw_diffuseTex, flw_vertexTexCoord);
|
flw_sampleColor = texture(_flw_diffuseTex, flw_vertexTexCoord);
|
||||||
flw_fragColor = flw_vertexColor * flw_sampleColor;
|
flw_fragColor = flw_vertexColor * flw_sampleColor;
|
||||||
flw_fragOverlay = flw_vertexOverlay;
|
flw_fragOverlay = flw_vertexOverlay;
|
||||||
flw_fragLight = flw_vertexLight;
|
flw_fragLight = flw_vertexLight;
|
||||||
|
@ -31,13 +29,15 @@ void main() {
|
||||||
flw_materialFragment();
|
flw_materialFragment();
|
||||||
flw_endFragment();
|
flw_endFragment();
|
||||||
|
|
||||||
vec4 overlayColor = texelFetch(flw_overlayTex, flw_fragOverlay, 0);
|
|
||||||
vec4 lightColor = texture(flw_lightTex, (flw_fragLight * 15.0 + 0.5) / 16.0);
|
|
||||||
|
|
||||||
vec4 color = flw_fragColor;
|
vec4 color = flw_fragColor;
|
||||||
color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a);
|
|
||||||
|
|
||||||
if (flw_material.lighting) {
|
if (flw_material.useOverlay) {
|
||||||
|
vec4 overlayColor = texelFetch(_flw_overlayTex, flw_fragOverlay, 0);
|
||||||
|
color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flw_material.useLight) {
|
||||||
|
vec4 lightColor = texture(_flw_lightTex, (flw_fragLight * 15.0 + 0.5) / 16.0);
|
||||||
color *= lightColor;
|
color *= lightColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,5 +45,5 @@ void main() {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
|
||||||
fragColor = flw_fogFilter(color);
|
_flw_fragColor = flw_fogFilter(color);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
#include "flywheel:internal/block.vert"
|
#include "flywheel:internal/block.vert"
|
||||||
#include "flywheel:util/diffuse.glsl"
|
#include "flywheel:util/diffuse.glsl"
|
||||||
|
|
||||||
uniform uvec4 _flw_material_instancing;
|
uniform uvec4 _flw_packedMaterial;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
_flw_materialVertexID = _flw_material_instancing.x;
|
_flw_materialVertexID = _flw_packedMaterial.x;
|
||||||
|
|
||||||
_flw_unpackMaterial(_flw_material_instancing.w, flw_material);
|
_flw_unpackMaterialProperties(_flw_packedMaterial.w, flw_material);
|
||||||
|
|
||||||
FlwInstance i = _flw_unpackInstance();
|
FlwInstance i = _flw_unpackInstance();
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,54 @@
|
||||||
#include "flywheel:api/material.glsl"
|
#include "flywheel:api/material.glsl"
|
||||||
|
|
||||||
|
// The number of bits each property takes up
|
||||||
|
const uint _FLW_BLUR_LENGTH = 1u;
|
||||||
|
const uint _FLW_MIPMAP_LENGTH = 1u;
|
||||||
|
const uint _FLW_BACKFACE_CULLING_LENGTH = 1u;
|
||||||
|
const uint _FLW_POLYGON_OFFSET_LENGTH = 1u;
|
||||||
|
const uint _FLW_DEPTH_TEST_LENGTH = 4u;
|
||||||
|
const uint _FLW_TRANSPARENCY_LENGTH = 3u;
|
||||||
|
const uint _FLW_WRITE_MASK_LENGTH = 2u;
|
||||||
|
const uint _FLW_USE_OVERLAY_LENGTH = 1u;
|
||||||
|
const uint _FLW_USE_LIGHT_LENGTH = 1u;
|
||||||
|
const uint _FLW_DIFFUSE_LENGTH = 1u;
|
||||||
|
|
||||||
|
// The bit offset of each property
|
||||||
|
const uint _FLW_BLUR_OFFSET = 0u;
|
||||||
|
const uint _FLW_MIPMAP_OFFSET = _FLW_BLUR_OFFSET + _FLW_BLUR_LENGTH;
|
||||||
|
const uint _FLW_BACKFACE_CULLING_OFFSET = _FLW_MIPMAP_OFFSET + _FLW_MIPMAP_LENGTH;
|
||||||
|
const uint _FLW_POLYGON_OFFSET_OFFSET = _FLW_BACKFACE_CULLING_OFFSET + _FLW_BACKFACE_CULLING_LENGTH;
|
||||||
|
const uint _FLW_DEPTH_TEST_OFFSET = _FLW_POLYGON_OFFSET_OFFSET + _FLW_POLYGON_OFFSET_LENGTH;
|
||||||
|
const uint _FLW_TRANSPARENCY_OFFSET = _FLW_DEPTH_TEST_OFFSET + _FLW_DEPTH_TEST_LENGTH;
|
||||||
|
const uint _FLW_WRITE_MASK_OFFSET = _FLW_TRANSPARENCY_OFFSET + _FLW_TRANSPARENCY_LENGTH;
|
||||||
|
const uint _FLW_USE_OVERLAY_OFFSET = _FLW_WRITE_MASK_OFFSET + _FLW_WRITE_MASK_LENGTH;
|
||||||
|
const uint _FLW_USE_LIGHT_OFFSET = _FLW_USE_OVERLAY_OFFSET + _FLW_USE_OVERLAY_LENGTH;
|
||||||
|
const uint _FLW_DIFFUSE_OFFSET = _FLW_USE_LIGHT_OFFSET + _FLW_USE_LIGHT_LENGTH;
|
||||||
|
|
||||||
|
// The bit mask for each property
|
||||||
|
const uint _FLW_BLUR_MASK = ((1u << _FLW_BLUR_LENGTH) - 1u) << _FLW_BLUR_OFFSET;
|
||||||
|
const uint _FLW_MIPMAP_MASK = ((1u << _FLW_MIPMAP_LENGTH) - 1u) << _FLW_MIPMAP_OFFSET;
|
||||||
|
const uint _FLW_BACKFACE_CULLING_MASK = ((1u << _FLW_BACKFACE_CULLING_LENGTH) - 1u) << _FLW_BACKFACE_CULLING_OFFSET;
|
||||||
|
const uint _FLW_POLYGON_OFFSET_MASK = ((1u << _FLW_POLYGON_OFFSET_LENGTH) - 1u) << _FLW_POLYGON_OFFSET_OFFSET;
|
||||||
|
const uint _FLW_DEPTH_TEST_MASK = ((1u << _FLW_DEPTH_TEST_LENGTH) - 1u) << _FLW_DEPTH_TEST_OFFSET;
|
||||||
|
const uint _FLW_TRANSPARENCY_MASK = ((1u << _FLW_TRANSPARENCY_LENGTH) - 1u) << _FLW_TRANSPARENCY_OFFSET;
|
||||||
|
const uint _FLW_WRITE_MASK_MASK = ((1u << _FLW_WRITE_MASK_LENGTH) - 1u) << _FLW_WRITE_MASK_OFFSET;
|
||||||
|
const uint _FLW_USE_OVERLAY_MASK = ((1u << _FLW_USE_OVERLAY_LENGTH) - 1u) << _FLW_USE_OVERLAY_OFFSET;
|
||||||
|
const uint _FLW_USE_LIGHT_MASK = ((1u << _FLW_USE_LIGHT_LENGTH) - 1u) << _FLW_USE_LIGHT_OFFSET;
|
||||||
|
const uint _FLW_DIFFUSE_MASK = ((1u << _FLW_DIFFUSE_LENGTH) - 1u) << _FLW_DIFFUSE_OFFSET;
|
||||||
|
|
||||||
// Packed format:
|
// Packed format:
|
||||||
// transparency[3] | writeMask[2] | mip[1] | polygonOffset[1] | backfaceCull[1] | blur[1] | lighting[1] | diffuse[1]
|
// diffuse[1] | useOverlay[1] | useLight[1] | writeMask[2] | transparency[3] | depthTest[4] | polygonOffset[1] | backfaceCulling[1] | mipmap[1] | blur[1]
|
||||||
|
void _flw_unpackMaterialProperties(uint p, out FlwMaterial m) {
|
||||||
const uint DIFFUSE_MASK = 1u;
|
m.blur = (p & _FLW_BLUR_MASK) != 0u;
|
||||||
const uint LIGHTING_MASK = 1u << 1u;
|
m.mipmap = (p & _FLW_MIPMAP_MASK) != 0u;
|
||||||
const uint BLUR_MASK = 1u << 2u;
|
m.backfaceCulling = (p & _FLW_BACKFACE_CULLING_MASK) != 0u;
|
||||||
const uint BACKFACE_CULL_MASK = 1u << 3u;
|
m.polygonOffset = (p & _FLW_POLYGON_OFFSET_MASK) != 0u;
|
||||||
const uint POLYGON_OFFSET_MASK = 1u << 4u;
|
m.depthTest = (p & _FLW_DEPTH_TEST_MASK) >> _FLW_DEPTH_TEST_OFFSET;
|
||||||
const uint MIP_MASK = 1u << 5u;
|
m.transparency = (p & _FLW_TRANSPARENCY_MASK) >> _FLW_TRANSPARENCY_OFFSET;
|
||||||
const uint WRITE_MASK_MASK = 3u << 6u;
|
m.writeMask = (p & _FLW_WRITE_MASK_MASK) >> _FLW_WRITE_MASK_OFFSET;
|
||||||
const uint TRANSPARENCY_MASK = 7u << 8u;
|
m.useOverlay = (p & _FLW_USE_OVERLAY_MASK) != 0u;
|
||||||
|
m.useLight = (p & _FLW_USE_LIGHT_MASK) != 0u;
|
||||||
|
m.diffuse = (p & _FLW_DIFFUSE_MASK) != 0u;
|
||||||
void _flw_unpackMaterial(uint m, out FlwMaterial o) {
|
|
||||||
o.diffuse = (m & DIFFUSE_MASK) != 0u;
|
|
||||||
o.lighting = (m & LIGHTING_MASK) != 0u;
|
|
||||||
o.blur = (m & BLUR_MASK) != 0u;
|
|
||||||
o.backfaceCull = (m & BACKFACE_CULL_MASK) != 0u;
|
|
||||||
o.polygonOffset = (m & POLYGON_OFFSET_MASK) != 0u;
|
|
||||||
o.mip = (m & MIP_MASK) != 0u;
|
|
||||||
o.writeMask = (m & WRITE_MASK_MASK) >> 6;
|
|
||||||
o.transparency = (m & TRANSPARENCY_MASK) >> 8;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _flw_unpackUint2x16(uint s, out uint hi, out uint lo) {
|
void _flw_unpackUint2x16(uint s, out uint hi, out uint lo) {
|
||||||
|
|
Loading…
Reference in a new issue