Skip to content

Commit

Permalink
yp (#12)
Browse files Browse the repository at this point in the history
* Ensure depth test is configured when rendering clouds

The state of the depth test prior to cloud rendering is
undefined. After rendering, it is expected to be
disabled again.

* Fix rounding error in ColorMixer#mix

Rounding of the values now happens after the 16-bit
intermediaries are added together.

This affected some animated textures, causing them to
exhibit flickering behavior.

* Add additional optimized block models

This covers the following additional blocks:
- Cauldrons
- Brewing Stands
- Bells

Co-authored-by: JellySquid <[email protected]>

* Avoid marking the section graph as dirty if state didn't change (CaffeineMC#2886)

Avoids rebuilding the render lists and doing a graph search
more often than necessary by checking if the section actually
changed in a way that's relevant to the graph search.

For worlds that update their blocks frequently (every tick or
every redstone tick) this avoids half the graph searches. Some
graph searches are still necessary to schedule rebuild tasks,
but when the task results come back, this doesn't do another
graph search unless the section's visibility data or build state
changed in a way that needs the render list to be updated.

* Use larger bounding box for nearby sections in frustum check (CaffeineMC#2879)

This fixes some problems where very large block entities in
nearby sections may be incorrectly culled. But it does not
comprehensively fix the problem for all other sections,
since that would require visiting the 27-neighborhood of
every section, which is too slow.

* Bump version to 0.6.1

* Bump dependency versions

* Update mod manifest

* Ensure ItemRenderContext.isDefaultTranslucent is initialized

* Update compatible mods listing

* Update mod manifest to restrict Minecraft versions

* Update to Minecraft 1.21.4

* Update NeoForge manifest for Minecraft 1.21.4

* Fix glyph effect orientation

* Fix hidden surface elimination in fluid rendering for waterlogged blocks (CaffeineMC#2907)

* Fix detection for specific Intel OpenGL ICDs

The OpenGL ICD name now includes the file extension,
which the regex expressions were not matching.

* Avoid showing the incompatible driver error in some cases

For systems with hybrid graphics, it may be the case
that an incompatible graphics driver is installed, but that
it isn't used for the OpenGL context.

We can avoid showing errors in this situation by checking
the vendor string of the context immediately after
creation.

This is not the most robust check, but in practice, a single
system should not have multiple graphics drivers installed
from the same vendor, so checking the string should be
relatively safe.

* Fix lambda mappings

* Bump version and dependency requirements

* Use correct coordinates for sorting chunk sections (CaffeineMC#2924)

Fix section and region sorting by using the correct section coordinate instead of the integer part of the camera transform, which is incorrect near the origin.

Closes CaffeineMC#2918

* Update README.md

* Update textures for Leaves variants

* Added "Pale Oak Leaves" for Minecraft 1.21.4.
* Reduced the file size of all block textures.

* Clean up BitArray class

* Use link.caffeinemc.net domain for some URLs

* Use ShellExecuteW from message box callbacks

This fixes a regression caused by 26f4263.

The underlying problem is that accessing Java's AWT *after*
LWJGL3 has initialized is not possible.

Minecraft has a utility class which uses rundll32 internally,
but we cannot access that due to classloader restrictions on
NeoForge.

That leaves us with having to implement the call ourselves,
and simply using Shell32 directly (like we do for other
Windows APIs) seems easiest.

* Do not bake ambient lighting into cached per-face light data

Fixes CaffeineMC#2806

* Switch to Parchment mappings 2024.12.07

* Bump version and dependencies

* Do not cache ambient brightness at initialization

The world may not be assigned to the renderer at
initialization, which is the case for non-terrain
rendering (i.e. block entities.)

Likely, there is no performance benefit to caching
this data in the first place, so the easiest solution
is to just remove the code.

* Bump version to 0.6.5

* Fix transforms not being run on fast path

* Bump version to 0.6.6

* Rename model texture references to match Vanilla (CaffeineMC#2958)

Custom models which extended these base models would not properly have their textures applied, as the texture references were accidentally changed.

* Do not apply optimizations to sprites with special tickers

* Aggressively optimize entity rendering

This is anywhere from 10 to 15% faster depending
on what entities are being rendered.

Most of the improvements come from more efficiently
laying out the cuboid data and coalescing neighboring
32-bit values into 64-bit words.

Furthermore, vertex positions are calculated by
extracting vectors from the pose matrix and adding
them to the origin vertex, which avoids many
matrix multiplications.

Co-authored-by: MoePus <[email protected]>

* Avoid quaternion transforms in particle rendering

The billboard geometry can be computed using the
camera's left and up vectors, saving some cycles.

When rendering thousands of billboard particles, this
was ~10% faster than baseline in my observation.

Co-authored-by: MoePus <[email protected]>

* Add shader source line annotations (CaffeineMC#2691)

---------

Co-authored-by: JellySquid <[email protected]>
Co-authored-by: muzikbike <[email protected]>
Co-authored-by: douira <[email protected]>
Co-authored-by: IMS212 <[email protected]>
Co-authored-by: MoePus <[email protected]>
  • Loading branch information
6 people authored Jan 3, 2025
1 parent a5fabd4 commit 12a092e
Show file tree
Hide file tree
Showing 111 changed files with 2,628 additions and 1,129 deletions.
83 changes: 53 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,53 @@
Sodium is a powerful rendering engine and optimization mod for the Minecraft client which improves frame rates and reduces
micro-stutter, while fixing many graphical issues in Minecraft.

### 📥 Installation
**This mod is the result of thousands of hours of development, and is made possible thanks to players like you.** If you
would like to show a token of your appreciation for my work, and help support the development of Sodium in the process,
then consider [buying me a coffee](https://caffeinemc.net/donate).

The latest version of Sodium can be downloaded from our official [Modrinth](https://modrinth.com/mod/sodium) and
[CurseForge](https://www.curseforge.com/minecraft/mc-mods/sodium) pages.
<a href="https://caffeinemc.net/donate"><img src="https://storage.ko-fi.com/cdn/kofi2.png?v=3" width="180"/></a>

---

### 📥 Downloads

#### Stable builds

The latest stable release of Sodium can be downloaded from our official [Modrinth](https://modrinth.com/mod/sodium) and
[CurseForge](https://www.curseforge.com/minecraft/mc-mods/sodium) pages.

#### Nightly builds (for developers)

We also provide bleeding-edge builds ("nightlies") which are useful for testing the very latest changes before they're
packaged into a release. These builds are only provided for other mod developers and users with expert skills, and do
not come with any support or warranty. It is often the case they have issues and lack compatibility with other mods.

The latest nightly build for each current branch of development can be downloaded below.

- Minecraft 1.21.4 (latest): [Download nightly](https://nightly.link/CaffeineMC/sodium/workflows/build-commit/dev/sodium-artifacts-dev.zip) or [View all builds](https://github.com/CaffeineMC/sodium/actions/workflows/build-commit.yml?query=branch%3Adev)
- Minecraft 1.21.3: [Download nightly](https://nightly.link/CaffeineMC/sodium/workflows/build-commit/1.21.3%2Fstable/sodium-artifacts-1.21.3-stable.zip) or [View all builds](https://github.com/CaffeineMC/sodium/actions/workflows/build-commit.yml?query=branch%3A1.21.3%2Fstable)
- Minecraft 1.21.1: [Download nightly](https://nightly.link/CaffeineMC/sodium/workflows/build-commit/1.21.1%2Fstable/sodium-artifacts-1.21.1-stable.zip) or [View all builds](https://github.com/CaffeineMC/sodium/actions/workflows/build-commit.yml?query=branch%3A1.21.1%2Fstable)

### 🖥️ Installation

Since the release of Sodium 0.6.0, both the _Fabric_ and _NeoForge_ mod loaders are supported. We generally recommend
that new users prefer to use the _Fabric_ mod loader, since it is more lightweight and stable (for the time being.)

For more information about downloading and installing the mod, please refer to our [Installation Guide](https://github.com/CaffeineMC/sodium/wiki/Installation).

### 🐛 Reporting Issues
### 🙇 Getting Help

You can report bugs and crashes by opening an issue on our [issue tracker](https://github.com/CaffeineMC/sodium/issues).
Before opening a new issue, use the search tool to make sure that your issue has not already been reported and ensure
that you have completely filled out the issue template. Issues that are duplicates or do not contain the necessary
information to triage and debug may be closed.
For technical support (including help with mod installation problems and game crashes), please use our
[official Discord server](https://caffeinemc.net/discord).

### 📬 Reporting Issues

If you do not need technical support and would like to report an issue (bug, crash, etc.) or otherwise request changes
(for mod compatibility, new features, etc.), then we encourage you to open an issue on the
[project issue tracker](https://github.com/CaffeineMC/sodium/issues).

Please note that while the issue tracker is open to feature requests, development is primarily focused on
improving hardware compatibility, performance, and finishing any unimplemented features necessary for parity with
improving compatibility, performance, and finishing any unimplemented features necessary for parity with
the vanilla renderer.

### 💬 Join the Community
Expand All @@ -36,45 +64,40 @@ We have an [official Discord community](https://caffeinemc.net/discord) for all

## ✅ Hardware Compatibility

We only provide support for graphics cards which have up-to-date drivers for OpenGL 4.6. Most graphics cards which have
been released since year 2010 are supported, such as the...
We only provide official support for graphics cards which have up-to-date drivers that are compatible with OpenGL 4.5
or newer. Most graphics cards released in the past 12 years will meet these requirements, including the following:

- AMD Radeon HD 7000 Series (GCN 1) or newer
- NVIDIA GeForce 400 Series (Fermi) or newer
- Intel HD Graphics 500 Series (Skylake) or newer

In some cases, older graphics cards may also work (so long as they have up-to-date drivers which have support for
OpenGL 3.3), but they are not officially supported, and may not be compatible with future versions of Sodium.
Nearly all graphics cards that are already compatible with Minecraft (which requires OpenGL 3.3) should also work
with Sodium. But our team cannot ensure compatibility or provide support for older graphics cards, and they may
not work with future versions of Sodium.

#### OpenGL Compatibility Layers

Devices which need to use OpenGL translation layers (such as GL4ES, ANGLE, etc) are not supported and will very likely
not work with Sodium. These translation layers do not implement required functionality and they suffer from underlying
driver bugs which cannot be worked around.

## 🛠️ Developer Guide

### Building from sources
## 🛠️ Building from sources

Sodium uses a typical Gradle project structure and can be compiled by simply running the default `build` task. The build
artifacts (typical mod binaries, and their sources) can be found in the `build/libs` directory.
Sodium uses the [Gradle build tool](https://gradle.org/) and can be built with the `gradle build` command. The build
artifacts (production binaries and their source bundles) can be found in the `build/mods` directory.

#### Requirements
The [Gradle wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html#sec:using_wrapper) is provided for ease of use and will automatically download and install the
appropriate version of Gradle for the project build. To use the Gradle wrapper, substitute `gradle` in build commands
with `./gradlew.bat` (Windows) or `./gradlew` (macOS and Linux).

We recommend using a package manager (such as [SDKMAN](https://sdkman.io/)) to manage toolchain dependencies and keep
them up to date. For many Linux distributions, these dependencies will be standard packages in your software
repositories.
### Build Requirements

- OpenJDK 21
- We recommend using the [Eclipse Temurin](https://adoptium.net/) distribution, as it's known to be high quality
and to work without issues.
- Gradle 8.6.x (optional)
- The [Gradle wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html#sec:using_wrapper) is provided
in this repository can be used instead of installing a suitable version of Gradle yourself. However, if you are
building many projects, you may prefer to install it yourself through a suitable package manager as to save disk
space and to avoid many different Gradle daemons sitting around in memory.
- We recommend using the [Eclipse Temurin](https://adoptium.net/) distribution as it's regularly tested by our developers and known
to be of high quality.
- Gradle 8.10.x
- Typically, newer versions of Gradle will work without issues, but the build script is only tested against the
version specified by the wrapper script.
version used by the [wrapper script](/gradle/wrapper/gradle-wrapper.properties).

## 📜 License

Expand Down
13 changes: 6 additions & 7 deletions buildSrc/src/main/kotlin/BuildConfig.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import org.gradle.api.Project
import org.gradle.api.Project

object BuildConfig {
val MINECRAFT_VERSION: String = "1.21.3"
val NEOFORGE_VERSION: String = "21.3.40-beta"
val MINECRAFT_VERSION: String = "1.21.4"
val NEOFORGE_VERSION: String = "21.4.30-beta"
val FABRIC_LOADER_VERSION: String = "0.16.9"
val FABRIC_API_VERSION: String = "0.109.0+1.21.3"
val FABRIC_API_VERSION: String = "0.112.1+1.21.4"

// This value can be set to null to disable Parchment.
// TODO: Re-add Parchment
val PARCHMENT_VERSION: String? = null
val PARCHMENT_VERSION: String? = "2024.12.07"

// https://semver.org/
var MOD_VERSION: String = "0.6.0"
var MOD_VERSION: String = "0.6.6"

fun createVersionString(project: Project): String {
val builder = StringBuilder()
Expand Down
2 changes: 0 additions & 2 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ dependencies {
addDependentFabricModule("fabric-renderer-api-v1")
addDependentFabricModule("fabric-rendering-data-attachment-v1")

modCompileOnly("net.fabricmc.fabric-api:fabric-renderer-api-v1:3.2.9+1172e897d7")

// We need to be careful during pre-launch that we don't touch any Minecraft classes, since other mods
// will not yet have an opportunity to apply transformations.
configurationPreLaunch("org.lwjgl:lwjgl:3.3.3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,33 @@
public class ColorMixer {
/**
* <p>Linearly interpolate between the {@param start} and {@param end} points, represented as packed unsigned 8-bit
* values within a 32-bit integer. The result is computed as <pre>(start * weight) + (end * (255 - weight))</pre>.</p>
* values within a 32-bit integer. The result is computed as <pre>(start * weight) + (end * (255 - weight))</pre>
* using fixed-point arithmetic and round-to-nearest behavior.</p>
*
* <p>The results are undefined if {@param weight} is not within the interval [0, 255].</p>
* @param start The start of the range to interpolate
* @param end The end of the range to interpolate
*
* <p>If {@param start} and {@param end} are the same value, the result of this function will always be that value,
* regardless of {@param weight}.</p>
*
* @param start The value at the start of the range to interpolate
* @param end The value at the end of the range to interpolate
* @param weight The weight value used to interpolate between color values (in 0..255 range)
* @return The color that was interpolated between the start and end points
*/
public static int mix(int start, int end, int weight) {
// Overflow is not possible, so adding the values is fine.
return mul(start, weight) + mul(end, ColorU8.COMPONENT_MASK - weight);
// De-interleave the 8-bit component lanes into high and low halves for each point.
// Multiply the start point by alpha, and the end point by 1-alpha, to produce Q8.8 fixed-point intermediates.
// Add the Q8.8 fixed-point intermediaries together to obtain the mixed values.
final long hi = ((start & 0x00FF00FFL) * weight) + ((end & 0x00FF00FFL) * (ColorU8.COMPONENT_MASK - weight));
final long lo = ((start & 0xFF00FF00L) * weight) + ((end & 0xFF00FF00L) * (ColorU8.COMPONENT_MASK - weight));

// Round the fixed-point values to the nearest integer, and interleave the high and low halves to
// produce the final packed result.
final long result =
(((hi + 0x00FF00FFL) >>> 8) & 0x00FF00FFL) |
(((lo + 0xFF00FF00L) >>> 8) & 0xFF00FF00L);

return (int) result;
}

/**
Expand Down Expand Up @@ -104,10 +119,19 @@ public static int mulComponentWise(int color0, int color1) {
* @return The result of the multiplication
*/
public static int mul(int color, int factor) {
final long result = (((((color & 0x00FF00FFL) * factor) + 0x00FF00FFL) >>> 8) & 0x00FF00FFL) |
(((((color & 0xFF00FF00L) * factor) + 0xFF00FF00L) >>> 8) & 0xFF00FF00L);
// De-interleave the 8-bit component lanes into high and low halves.
// Perform 8-bit multiplication to produce Q8.8 fixed-point intermediaries.
final long hi = (color & 0x00FF00FFL) * factor;
final long lo = (color & 0xFF00FF00L) * factor;

// Round the Q8.8 fixed-point values to the nearest integer, and interleave the high and low halves to
// produce the packed result.
final long result =
(((hi + 0x00FF00FFL) >>> 8) & 0x00FF00FFL) |
(((lo + 0xFF00FF00L) >>> 8) & 0xFF00FF00L);

return (int) result;

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class ColorAttribute {
public static void set(long ptr, int color) {
MemoryUtil.memPutInt(ptr + 0, color);
MemoryUtil.memPutInt(ptr, color);
}

public static int get(long ptr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class NormalAttribute {
public static void set(long ptr, int normal) {
MemoryUtil.memPutInt(ptr + 0, normal);
MemoryUtil.memPutInt(ptr, normal);
}

public static int get(long ptr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

public class PositionAttribute {
public static void put(long ptr, float x, float y, float z) {
MemoryUtil.memPutFloat(ptr + 0, x);
MemoryUtil.memPutFloat(ptr + 4, y);
MemoryUtil.memPutFloat(ptr + 8, z);
MemoryUtil.memPutFloat(ptr + 0L, x);
MemoryUtil.memPutFloat(ptr + 4L, y);
MemoryUtil.memPutFloat(ptr + 8L, z);
}

public static float getX(long ptr) {
return MemoryUtil.memGetFloat(ptr + 0);
return MemoryUtil.memGetFloat(ptr + 0L);
}

public static float getY(long ptr) {
return MemoryUtil.memGetFloat(ptr + 4);
return MemoryUtil.memGetFloat(ptr + 4L);
}

public static float getZ(long ptr) {
return MemoryUtil.memGetFloat(ptr + 8);
return MemoryUtil.memGetFloat(ptr + 8L);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.io.IOException;

public class LaunchWarn {
private static final String HELP_URL = "https://github.com/CaffeineMC/sodium/wiki/Installation";
private static final String HELP_URL = "https://link.caffeinemc.net/guides/sodium/installation";

private static final String RICH_MESSAGE =
"<html>" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public record SodiumResourcePackMetadata(List<String> ignoredShaders) {
.apply(instance, SodiumResourcePackMetadata::new)
);
public static final MetadataSectionType<SodiumResourcePackMetadata> SERIALIZER =
MetadataSectionType.fromCodec("sodium", CODEC);
new MetadataSectionType<>("sodium", CODEC);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.apache.logging.log4j.Logger;
import org.lwjgl.opengl.GL20C;

import java.util.Arrays;

/**
* A compiled OpenGL shader object.
*/
Expand All @@ -15,17 +17,18 @@ public class GlShader extends GlObject {

private final ResourceLocation name;

public GlShader(ShaderType type, ResourceLocation name, String src) {
public GlShader(ShaderType type, ResourceLocation name, ShaderParser.ParsedShader parsedShader) {
this.name = name;

int handle = GL20C.glCreateShader(type.id);
ShaderWorkarounds.safeShaderSource(handle, src);
ShaderWorkarounds.safeShaderSource(handle, parsedShader.src());
GL20C.glCompileShader(handle);

String log = GL20C.glGetShaderInfoLog(handle);

if (!log.isEmpty()) {
LOGGER.warn("Shader compilation log for " + this.name + ": " + log);
LOGGER.warn("Shader compilation log for {}: {}", this.name, log);
LOGGER.warn("Include table: {}", Arrays.toString(parsedShader.includeIds()));
}

int result = GlStateManager.glGetShaderi(handle, GL20C.GL_COMPILE_STATUS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package net.caffeinemc.mods.sodium.client.gl.shader;

import net.caffeinemc.mods.sodium.client.services.PlatformRuntimeInformation;
import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import net.minecraft.resources.ResourceLocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ShaderLoader {
private static final Logger LOGGER = LoggerFactory.getLogger("Sodium-ShaderLoader");

/**
* Creates an OpenGL shader from GLSL sources. The GLSL source file should be made available on the classpath at the
* path of `/assets/{namespace}/shaders/{path}`. User defines can be used to declare variables in the shader source
Expand All @@ -19,7 +24,12 @@ public class ShaderLoader {
* @return An OpenGL shader object compiled with the given user defines
*/
public static GlShader loadShader(ShaderType type, ResourceLocation name, ShaderConstants constants) {
return new GlShader(type, name, ShaderParser.parseShader(getShaderSource(name), constants));
var parsedShader = ShaderParser.parseShader(getShaderSource(name), constants);
if (PlatformRuntimeInformation.INSTANCE.isDevelopmentEnvironment()) {
LOGGER.info("Loaded shader {} with constants {}", name, constants);
LOGGER.info(parsedShader.src());
}
return new GlShader(type, name, parsedShader);
}

public static String getShaderSource(ResourceLocation name) {
Expand Down
Loading

0 comments on commit 12a092e

Please sign in to comment.