Skip to content

Commit

Permalink
finish porting everything (black screen for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna0x01 committed Jan 5, 2025
1 parent d357556 commit baa6685
Show file tree
Hide file tree
Showing 213 changed files with 684 additions and 6,975 deletions.
6 changes: 3 additions & 3 deletions common/src/api/java/com/mojang/blaze3d/vertex/PoseStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import dev.vexor.radium.compat.mojang.Util;
import dev.vexor.radium.compat.mojang.math.Mth;
import org.joml.Matrix3f;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import net.coderbot.iris.vendored.joml.Matrix3f;
import net.coderbot.iris.vendored.joml.Matrix4f;
import net.coderbot.iris.vendored.joml.Quaternionf;

public class PoseStack {
private final Deque<Pose> poseStack = Util.make(Queues.newArrayDeque(), arrayDeque -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.caffeinemc.mods.sodium.client.gui.options.storage.MinecraftOptionsStorage;
import net.caffeinemc.mods.sodium.client.gui.options.storage.SodiumOptionsStorage;
import net.caffeinemc.mods.sodium.client.services.PlatformRuntimeInformation;
import net.coderbot.iris.compat.sodium.impl.options.IrisSodiumOptions;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.Window;
import net.minecraft.text.TranslatableText;
Expand Down Expand Up @@ -44,6 +45,7 @@ public static OptionPage general() {
.setControl(opt -> new SliderControl(opt, 0, 100, 1, ControlValueFormatter.brightness()))
.setBinding((opts, value) -> opts.gamma = (value * 0.01f), (opts) -> (int) (opts.gamma / 0.01D))
.build())
.add(IrisSodiumOptions.createMaxShadowDistanceSlider(vanillaOpts))
.build());

groups.add(OptionGroup.createBuilder()
Expand Down Expand Up @@ -85,6 +87,7 @@ public static OptionPage general() {
(opts, value) -> opts.vsync = value,
opts -> opts.vsync)
.setImpact(OptionImpact.VARIES)
.setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD)
.build())
.add(OptionImpl.createBuilder(int.class, vanillaOpts)
.setName(new TranslatableText("options.framerateLimit"))
Expand All @@ -93,6 +96,7 @@ public static OptionPage general() {
.setBinding((opts, value) -> {
opts.maxFramerate = (value);
}, opts -> opts.maxFramerate)
.setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD)
.build())
.build());

Expand All @@ -114,16 +118,7 @@ public static OptionPage quality() {
List<OptionGroup> groups = new ArrayList<>();

groups.add(OptionGroup.createBuilder()
.add(OptionImpl.createBuilder(GraphicsMode.class, vanillaOpts)
.setName(new TranslatableText("options.graphics"))
.setTooltip(new TranslatableText("sodium.options.graphics_quality.tooltip"))
.setControl(option -> new CyclingControl<>(option, GraphicsMode.class))
.setBinding(
(opts, value) -> opts.fancyGraphics = value.isFancy(),
opts -> GraphicsMode.fromBoolean(opts.fancyGraphics))
.setImpact(OptionImpact.HIGH)
.setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD)
.build())
.add(IrisSodiumOptions.createLimitedVideoSettingsButton(vanillaOpts))
.build());

groups.add(OptionGroup.createBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.caffeinemc.mods.sodium.client.services.PlatformRuntimeInformation;
import net.caffeinemc.mods.sodium.client.util.FileUtil;
import net.caffeinemc.mods.sodium.client.render.chunk.translucent_sorting.SortBehavior;
import net.coderbot.iris.Iris;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;

Expand Down Expand Up @@ -171,6 +172,14 @@ public static void writeToDisk(SodiumGameOptions config) throws IOException {
}

FileUtil.writeTextRobustly(GSON.toJson(config), path);

try {
if (Iris.getIrisConfig() != null) {
Iris.getIrisConfig().save();
}
} catch (IOException e) {
e.printStackTrace();
}
}

public boolean isReadOnly() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.caffeinemc.mods.sodium.client.gui;

import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.platform.GlStateManager;
import net.caffeinemc.mods.sodium.client.SodiumClientMod;
import net.caffeinemc.mods.sodium.client.data.fingerprint.HashedFingerprint;
Expand All @@ -16,6 +17,7 @@
import net.caffeinemc.mods.sodium.client.gui.widgets.FlatButtonWidget;
import net.caffeinemc.mods.sodium.client.services.PlatformRuntimeInformation;
import net.caffeinemc.mods.sodium.client.util.Dim2i;
import net.coderbot.iris.gui.screen.ShaderPackScreen;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.render.BufferBuilder;
Expand Down Expand Up @@ -57,13 +59,18 @@ public class SodiumOptionsGUI extends RenderableScreen implements ScreenPromptab
protected boolean hasPendingChanges;
private @Nullable ScreenPrompt prompt;

private OptionPage shaderPacks;

public SodiumOptionsGUI(Screen prevScreen) {
this.prevScreen = prevScreen;

this.shaderPacks = new OptionPage(new TranslatableText("options.iris.shaderPackSelection"), ImmutableList.of());

this.pages.add(SodiumGameOptionPages.general());
this.pages.add(SodiumGameOptionPages.quality());
this.pages.add(SodiumGameOptionPages.performance());
this.pages.add(SodiumGameOptionPages.advanced());
this.pages.add(shaderPacks);

this.checkPromptTimers();
}
Expand Down Expand Up @@ -130,6 +137,11 @@ public static Screen createScreen(Screen currentScreen) {
}

public void setPage(OptionPage page) {
if (page == shaderPacks) {
client.setScreen(new ShaderPackScreen(this));
return;
}

this.currentPage = page;

this.rebuildGUI();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class OptionImpl<S, T> implements OptionExtended<T> {
private boolean highlight;
private boolean selected;

private BooleanSupplier iris$dynamicallyEnabled;

private OptionImpl(OptionStorage<S> storage,
Text name,
Expand Down Expand Up @@ -166,6 +167,7 @@ public void setSelected(boolean selected) {
this.selected = selected;
}


public static class Builder<S, T> {
private final OptionStorage<S> storage;
private Text name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.caffeinemc.mods.sodium.client.model.light.data.QuadLightData;
import net.caffeinemc.mods.sodium.client.model.quad.ModelQuadView;
import net.caffeinemc.mods.sodium.client.model.quad.properties.ModelQuadFlags;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;

Expand Down Expand Up @@ -43,7 +44,11 @@ public void calculate(ModelQuadView quad, BlockPos pos, QuadLightData out, Direc
}

Arrays.fill(out.lm, lightmap);
Arrays.fill(out.br, this.lightCache.getLevel().getBrightness(face, true));
if (BlockRenderingSettings.INSTANCE.shouldDisableDirectionalShading()) {
Arrays.fill(out.br, 1f);
} else {
Arrays.fill(out.br, this.lightCache.getLevel().getBrightness(face, true));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.caffeinemc.mods.sodium.client.model.light.data.QuadLightData;
import net.caffeinemc.mods.sodium.client.model.quad.ModelQuadView;
import net.caffeinemc.mods.sodium.client.model.quad.properties.ModelQuadFlags;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
Expand Down Expand Up @@ -216,6 +217,10 @@ private void applyInsetPartialFaceVertex(BlockPos pos, Direction dir, float n1d,
}

private void applySidedBrightness(QuadLightData out, Direction face, boolean shade) {
if (BlockRenderingSettings.INSTANCE.shouldDisableDirectionalShading()) {
return;
}

float brightness = this.lightCache.getLevel().getBrightness(face, shade);
float[] br = out.br;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.caffeinemc.mods.sodium.client.render.chunk;

import com.mojang.blaze3d.vertex.PoseStack;
import org.lwjgl.system.MemoryUtil;
import net.caffeinemc.mods.sodium.client.SodiumClientMod;
import net.caffeinemc.mods.sodium.client.gl.device.CommandList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import net.caffeinemc.mods.sodium.client.world.LevelSlice;
import net.caffeinemc.mods.sodium.client.world.cloned.ChunkRenderContext;
import net.caffeinemc.mods.sodium.client.world.cloned.ClonedChunkSectionCache;
import net.coderbot.iris.Iris;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.world.ClientWorld;
Expand Down Expand Up @@ -152,7 +153,7 @@ private void createTerrainRenderList(Viewport viewport, int frame, boolean spect
private float getSearchDistance() {
float distance;

if (SodiumClientMod.options().performance.useFogOcclusion) {
if (SodiumClientMod.options().performance.useFogOcclusion && Iris.getCurrentPack().isEmpty()) {
distance = this.getEffectiveRenderDistance();
} else {
distance = this.getRenderDistance();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.caffeinemc.mods.sodium.client.render.chunk;

import com.mojang.blaze3d.vertex.PoseStack;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.caffeinemc.mods.sodium.client.gl.attribute.GlVertexFormat;
import net.caffeinemc.mods.sodium.client.gl.device.CommandList;
Expand All @@ -8,8 +9,16 @@
import net.caffeinemc.mods.sodium.client.render.chunk.terrain.TerrainRenderPass;
import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType;
import net.caffeinemc.mods.sodium.client.gl.shader.*;
import net.coderbot.iris.Iris;
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
import net.coderbot.iris.shaderpack.transform.StringTransformations;
import net.coderbot.iris.shaderpack.transform.Transformations;
import net.minecraft.util.Identifier;
import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;

public abstract class ShaderChunkRenderer implements ChunkRenderer {
Expand Down Expand Up @@ -63,6 +72,46 @@ private GlProgram<ChunkShaderInterface> createShader(String path, ChunkShaderOpt
}
}

private static String getShaderPath(Identifier name) {
return String.format("/assets/%s/shaders/%s", name.getNamespace(), name.getPath());
}

private static String getShaderSource(String path) {
try {
InputStream in = ShaderLoader.class.getResourceAsStream(path);
Throwable var2 = null;

String var3;
try {
if (in == null) {
throw new RuntimeException("Shader not found: " + path);
}

var3 = IOUtils.toString(in, StandardCharsets.UTF_8);
} catch (Throwable var13) {
var2 = var13;
throw var13;
} finally {
if (in != null) {
if (var2 != null) {
try {
in.close();
} catch (Throwable var12) {
var2.addSuppressed(var12);
}
} else {
in.close();
}
}

}

return var3;
} catch (IOException var15) {
throw new RuntimeException("Could not read shader sources", var15);
}
}

protected void begin(TerrainRenderPass pass) {
pass.startDrawing();

Expand All @@ -71,10 +120,6 @@ protected void begin(TerrainRenderPass pass) {
WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
GlProgram<ChunkShaderInterface> program = null;

if (pipeline instanceof IrisRenderingPipeline irisRenderingPipeline) {
irisRenderingPipeline.getSodiumPrograms().getFramebuffer(pass).bind();
program = irisRenderingPipeline.getSodiumPrograms().getProgram(pass);
}

if (program == null) {
program = this.compileProgram(options);
Expand All @@ -100,4 +145,6 @@ public void delete(CommandList commandList) {
this.programs.values()
.forEach(GlProgram::delete);
}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.caffeinemc.mods.sodium.client.render.chunk.compile;

import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
import net.caffeinemc.mods.sodium.client.model.quad.properties.ModelQuadFacing;
import net.caffeinemc.mods.sodium.client.render.chunk.compile.buffers.BakedChunkModelBuilder;
Expand All @@ -12,6 +13,11 @@
import net.caffeinemc.mods.sodium.client.render.chunk.vertex.builder.ChunkMeshBufferBuilder;
import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType;
import net.caffeinemc.mods.sodium.client.util.NativeBuffer;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.coderbot.iris.compat.sodium.impl.block_context.BlockContextHolder;
import net.coderbot.iris.compat.sodium.impl.block_context.ChunkBuildBuffersExt;
import net.minecraft.block.BlockState;
import org.spongepowered.asm.mixin.Unique;

import java.nio.ByteBuffer;
import java.util.ArrayList;
Expand All @@ -22,9 +28,12 @@
* passes. This makes a best-effort attempt to pick a suitable size for each scratch buffer, but will never try to
* shrink a buffer.
*/
public class ChunkBuildBuffers {
public class ChunkBuildBuffers implements ChunkBuildBuffersExt {
private final Reference2ReferenceOpenHashMap<TerrainRenderPass, BakedChunkModelBuilder> builders = new Reference2ReferenceOpenHashMap<>();

@Unique
private BlockContextHolder contextHolder;

private final ChunkVertexType vertexType;

public ChunkBuildBuffers(ChunkVertexType vertexType) {
Expand All @@ -39,6 +48,14 @@ public ChunkBuildBuffers(ChunkVertexType vertexType) {

this.builders.put(pass, new BakedChunkModelBuilder(vertexBuffers));
}

Object2IntMap<BlockState> blockStateIds = BlockRenderingSettings.INSTANCE.getBlockStateIds();

if (blockStateIds != null) {
this.contextHolder = new BlockContextHolder(blockStateIds);
} else {
this.contextHolder = new BlockContextHolder();
}
}

public void init(BuiltSectionInfo.Builder renderData, int sectionIndex) {
Expand Down Expand Up @@ -108,4 +125,20 @@ public void destroy() {
builder.destroy();
}
}

@Override
public void iris$setLocalPos(int localPosX, int localPosY, int localPosZ) {
this.contextHolder.setLocalPos(localPosX, localPosY, localPosZ);
}

@Override
public void iris$setMaterialId(BlockState state, short renderType) {
this.contextHolder.set(state, renderType);
}

@Override
public void iris$resetBlockContext() {
this.contextHolder.reset();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.caffeinemc.mods.sodium.client.render.chunk.terrain.material.Material;
import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkVertexEncoder;
import net.caffeinemc.mods.sodium.client.util.DirectionUtil;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
Expand All @@ -42,12 +43,16 @@ public class BlockRenderer {

private final int[] quadColors = new int[4];

private boolean useSeparateAo;

public BlockRenderer(ColorProviderRegistry colorRegistry, LightPipelineProvider lighters) {
this.colorProviderRegistry = colorRegistry;
this.lighters = lighters;

this.occlusionCache = new BlockOcclusionCache();
this.useAmbientOcclusion = MinecraftClient.isAmbientOcclusionEnabled();

this.useSeparateAo = BlockRenderingSettings.INSTANCE.shouldUseSeparateAo();
}

public void renderModel(BlockRenderContext ctx, ChunkBuildBuffers buffers) {
Expand Down
Loading

0 comments on commit baa6685

Please sign in to comment.