mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-28 07:55:53 +00:00
Support for custom uniforms (#902)
* wip backport of custom uniforms * Functioning custom uniforms maybe? * Workon separating dynamic/non-dynamic uniforms and making variables available to custom uniforms (currently the JVM dies horribly) * wip * It no longer crashes horrifically * star imports
This commit is contained in:
1 parent
6fa973dbc8
commit
bed724ba59
89 files changed
+4622
-266
No files matched your search
@@ -2,6 +2,7 @@ package net.coderbot.iris.gl.uniform;
|
||||
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector4f;
|
||||
import org.joml.Vector4i;
|
||||
|
||||
@@ -42,12 +43,23 @@ public interface DynamicLocationalUniformHolder extends LocationalUniformHolder,
|
||||
return this;
|
||||
}
|
||||
|
||||
default DynamicUniformHolder uniform3i(String name, Supplier<Vector3i> value, ValueUpdateNotifier notifier) {
|
||||
location(name, UniformType.VEC3I).ifPresent(id -> addDynamicUniform(new Vector3IntegerJomlUniform(id, value, notifier), notifier));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
default DynamicUniformHolder uniform4f(String name, Supplier<Vector4f> value, ValueUpdateNotifier notifier) {
|
||||
location(name, UniformType.VEC4).ifPresent(id -> addDynamicUniform(new Vector4Uniform(id, value, notifier), notifier));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
default DynamicUniformHolder uniform4fArray(String name, Supplier<float[]> value, ValueUpdateNotifier notifier) {
|
||||
location(name, UniformType.VEC4).ifPresent(id -> addDynamicUniform(new Vector4ArrayUniform(id, value, notifier), notifier));
|
||||
return this;
|
||||
}
|
||||
|
||||
default DynamicUniformHolder uniform4i(String name, Supplier<Vector4i> value, ValueUpdateNotifier notifier) {
|
||||
location(name, UniformType.VEC4I).ifPresent(id -> addDynamicUniform(new Vector4IntegerJomlUniform(id, value, notifier), notifier));
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.coderbot.iris.gl.uniform;
|
||||
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector4f;
|
||||
import org.joml.Vector4i;
|
||||
|
||||
@@ -15,6 +16,8 @@ public interface DynamicUniformHolder extends UniformHolder {
|
||||
DynamicUniformHolder uniform1f(String name, DoubleSupplier value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform1i(String name, IntSupplier value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform2i(String name, Supplier<Vector2i> value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform3i(String name, Supplier<Vector3i> value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform4f(String name, Supplier<Vector4f> value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform4fArray(String name, Supplier<float[]> value, ValueUpdateNotifier notifier);
|
||||
DynamicUniformHolder uniform4i(String name, Supplier<Vector4i> value, ValueUpdateNotifier notifier);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import org.joml.Vector2f;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
@@ -75,6 +76,13 @@ public interface LocationalUniformHolder extends UniformHolder {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
default LocationalUniformHolder uniform3i(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector3i> value) {
|
||||
location(name, UniformType.VEC3I).ifPresent(id -> addUniform(updateFrequency, new Vector3IntegerJomlUniform(id, value)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
default LocationalUniformHolder uniformVanilla3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vec3> value) {
|
||||
location(name, UniformType.VEC3).ifPresent(id -> addUniform(updateFrequency, new VanillaVector3Uniform(id, value)));
|
||||
@@ -103,6 +111,13 @@ public interface LocationalUniformHolder extends UniformHolder {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
default LocationalUniformHolder uniform4fArray(UniformUpdateFrequency updateFrequency, String name, Supplier<float[]> value) {
|
||||
location(name, UniformType.VEC4).ifPresent(id -> addUniform(updateFrequency, new Vector4ArrayUniform(id, value)));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
default LocationalUniformHolder uniformMatrix(UniformUpdateFrequency updateFrequency, String name, Supplier<Matrix4f> value) {
|
||||
location(name, UniformType.MAT4).ifPresent(id -> addUniform(updateFrequency, new MatrixUniform(id, value)));
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.joml.Vector2f;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3i;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
@@ -30,6 +31,8 @@ public interface UniformHolder {
|
||||
|
||||
UniformHolder uniform3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector3f> value);
|
||||
|
||||
UniformHolder uniform3i(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector3i> value);
|
||||
|
||||
UniformHolder uniformVanilla3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vec3> value);
|
||||
|
||||
UniformHolder uniformTruncated3f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4f> value);
|
||||
@@ -38,6 +41,8 @@ public interface UniformHolder {
|
||||
|
||||
UniformHolder uniform4f(UniformUpdateFrequency updateFrequency, String name, Supplier<Vector4f> value);
|
||||
|
||||
UniformHolder uniform4fArray(UniformUpdateFrequency updateFrequency, String name, Supplier<float[]> value);
|
||||
|
||||
UniformHolder uniformMatrix(UniformUpdateFrequency updateFrequency, String name, Supplier<Matrix4f> value);
|
||||
|
||||
UniformHolder uniformMatrixFromArray(UniformUpdateFrequency updateFrequency, String name, Supplier<float[]> value);
|
||||
|
||||
@@ -7,6 +7,7 @@ public enum UniformType {
|
||||
VEC2,
|
||||
VEC2I,
|
||||
VEC3,
|
||||
VEC3I,
|
||||
VEC4,
|
||||
VEC4I
|
||||
}
|
||||
@@ -3,5 +3,6 @@ package net.coderbot.iris.gl.uniform;
|
||||
public enum UniformUpdateFrequency {
|
||||
ONCE,
|
||||
PER_TICK,
|
||||
PER_FRAME
|
||||
PER_FRAME,
|
||||
CUSTOM
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.coderbot.iris.gl.uniform;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Vector3IntegerJomlUniform extends Uniform {
|
||||
private Vector3i cachedValue;
|
||||
private final Supplier<Vector3i> value;
|
||||
|
||||
Vector3IntegerJomlUniform(int location, Supplier<Vector3i> value) {
|
||||
this(location, value, null);
|
||||
}
|
||||
|
||||
Vector3IntegerJomlUniform(int location, Supplier<Vector3i> value, ValueUpdateNotifier notifier) {
|
||||
super(location, notifier);
|
||||
|
||||
this.cachedValue = null;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
updateValue();
|
||||
|
||||
if (notifier != null) {
|
||||
notifier.setListener(this::updateValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateValue() {
|
||||
Vector3i newValue = value.get();
|
||||
|
||||
if (cachedValue == null || !newValue.equals(cachedValue)) {
|
||||
cachedValue = newValue;
|
||||
RenderSystem.uniform3i(this.location, newValue.x, newValue.y, newValue.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.coderbot.iris.gl.uniform;
|
||||
|
||||
import com.gtnewhorizons.angelica.glsm.RenderSystem;
|
||||
import net.coderbot.iris.gl.state.ValueUpdateNotifier;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Vector4ArrayUniform extends Uniform {
|
||||
private final Supplier<float[]> value;
|
||||
private float[] cachedValue;
|
||||
|
||||
Vector4ArrayUniform(int location, Supplier<float[]> value) {
|
||||
this(location, value, null);
|
||||
}
|
||||
|
||||
Vector4ArrayUniform(int location, Supplier<float[]> value, ValueUpdateNotifier notifier) {
|
||||
super(location, notifier);
|
||||
|
||||
this.cachedValue = new float[4];
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
updateValue();
|
||||
|
||||
if (notifier != null) {
|
||||
notifier.setListener(this::updateValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateValue() {
|
||||
float[] newValue = value.get();
|
||||
|
||||
if (!Arrays.equals(newValue, cachedValue)) {
|
||||
cachedValue = newValue;
|
||||
RenderSystem.uniform4f(location, cachedValue[0], cachedValue[1], cachedValue[2], cachedValue[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user