Compare commits

..

No commits in common. "9b9089ea64c1a3d2a6f3f815485c702b327fa6ea" and "dc928b7b7e74d9b58f59f37c3caddd8370be3271" have entirely different histories.

9 changed files with 33 additions and 51 deletions

View file

@ -19,7 +19,8 @@ public final class InternalVertex {
.vector("position", FloatRepr.FLOAT, 3)
.vector("color", FloatRepr.NORMALIZED_UNSIGNED_BYTE, 4)
.vector("tex", FloatRepr.FLOAT, 2)
.vector("overlay_light", UnsignedIntegerRepr.UNSIGNED_SHORT, 4)
.vector("overlay", UnsignedIntegerRepr.UNSIGNED_SHORT, 2)
.vector("light", UnsignedIntegerRepr.UNSIGNED_SHORT, 2)
.vector("normal", FloatRepr.NORMALIZED_BYTE, 3)
.build();

View file

@ -2,7 +2,6 @@ package com.jozufozu.flywheel.backend.compile;
import java.util.List;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -23,37 +22,26 @@ import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
public final class FlwPrograms {
public static final Logger LOGGER = LoggerFactory.getLogger(Flywheel.ID + "/shaders");
public static final Logger LOGGER = LoggerFactory.getLogger(Flywheel.ID + "/compile");
private FlwPrograms() {
}
private static void reload(ResourceManager resourceManager) {
// Reset the programs in case the ubershader load fails.
InstancingPrograms.setInstance(null);
IndirectPrograms.setInstance(null);
var sources = new ShaderSources(resourceManager);
var stats = new CompilerStats("ubershaders");
var loadChecker = new SourceLoader(sources, stats);
var vertexMaterialComponent = createVertexMaterialComponent(loadChecker);
var fragmentMaterialComponent = createFragmentMaterialComponent(loadChecker);
var fogComponent = createFogComponent(loadChecker);
var cutoutComponent = createCutoutComponent(loadChecker);
if (stats.errored() || vertexMaterialComponent == null || fragmentMaterialComponent == null || fogComponent == null || cutoutComponent == null) {
// Probably means the shader sources are missing.
stats.emitErrorLog();
return;
}
List<SourceComponent> vertexComponents = List.of(vertexMaterialComponent);
List<SourceComponent> fragmentComponents = List.of(fragmentMaterialComponent, fogComponent, cutoutComponent);
var preLoadStats = new CompilerStats("Preload");
var loadChecker = new SourceLoader(sources, preLoadStats);
var pipelineKeys = createPipelineKeys();
List<SourceComponent> vertexComponents = List.of(createVertexMaterialComponent(loadChecker));
List<SourceComponent> fragmentComponents = List.of(createFragmentMaterialComponent(loadChecker), createFogComponent(loadChecker), createCutoutComponent(loadChecker));
InstancingPrograms.reload(sources, pipelineKeys, vertexComponents, fragmentComponents);
IndirectPrograms.reload(sources, pipelineKeys, vertexComponents, fragmentComponents);
if (preLoadStats.errored()) {
preLoadStats.emitErrorLog();
}
}
private static ImmutableList<PipelineProgramKey> createPipelineKeys() {
@ -66,7 +54,6 @@ public final class FlwPrograms {
return builder.build();
}
@Nullable
private static UberShaderComponent createVertexMaterialComponent(SourceLoader loadChecker) {
return UberShaderComponent.builder(Flywheel.rl("uber_material_vertex"))
.materialSources(ShaderIndices.materialVertex()
@ -76,7 +63,6 @@ public final class FlwPrograms {
.build(loadChecker);
}
@Nullable
private static UberShaderComponent createFragmentMaterialComponent(SourceLoader loadChecker) {
return UberShaderComponent.builder(Flywheel.rl("uber_material_fragment"))
.materialSources(ShaderIndices.materialFragment()
@ -86,7 +72,6 @@ public final class FlwPrograms {
.build(loadChecker);
}
@Nullable
private static UberShaderComponent createFogComponent(SourceLoader loadChecker) {
return UberShaderComponent.builder(Flywheel.rl("uber_fog"))
.materialSources(ShaderIndices.fog()
@ -100,7 +85,6 @@ public final class FlwPrograms {
.build(loadChecker);
}
@Nullable
private static UberShaderComponent createCutoutComponent(SourceLoader loadChecker) {
return UberShaderComponent.builder(Flywheel.rl("uber_cutout"))
.materialSources(ShaderIndices.cutout()

View file

@ -3,7 +3,6 @@ package com.jozufozu.flywheel.backend.compile;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import com.google.common.collect.ImmutableList;
@ -103,8 +102,7 @@ public class IndirectPrograms extends AbstractPrograms {
return builder.build();
}
@ApiStatus.Internal
public static void setInstance(@Nullable IndirectPrograms newInstance) {
private static void setInstance(@Nullable IndirectPrograms newInstance) {
if (instance != null) {
instance.release();
}

View file

@ -3,7 +3,6 @@ package com.jozufozu.flywheel.backend.compile;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import com.google.common.collect.ImmutableList;
@ -43,8 +42,7 @@ public class InstancingPrograms extends AbstractPrograms {
setInstance(newInstance);
}
@ApiStatus.Internal
public static void setInstance(@Nullable InstancingPrograms newInstance) {
private static void setInstance(@Nullable InstancingPrograms newInstance) {
if (instance != null) {
instance.release();
}

View file

@ -108,7 +108,6 @@ public class UberShaderComponent implements SourceComponent {
private final ResourceLocation name;
private final List<ResourceLocation> materialSources = new ArrayList<>();
private final List<AdaptedFn> adaptedFunctions = new ArrayList<>();
@Nullable
private GlslExpr switchArg;
public Builder(ResourceLocation name) {
@ -135,7 +134,6 @@ public class UberShaderComponent implements SourceComponent {
return this;
}
@Nullable
public UberShaderComponent build(SourceLoader sources) {
if (switchArg == null) {
throw new NullPointerException("Switch argument must be set");

View file

@ -14,7 +14,8 @@ public final class InstanceTypes {
public static final InstanceType<TransformedInstance> TRANSFORMED = SimpleInstanceType.builder(TransformedInstance::new)
.layout(LayoutBuilder.create()
.vector("color", FloatRepr.NORMALIZED_UNSIGNED_BYTE, 4)
.vector("overlay_light", IntegerRepr.SHORT, 4)
.vector("light", IntegerRepr.SHORT, 2)
.vector("overlay", IntegerRepr.SHORT, 2)
.matrix("pose", FloatRepr.FLOAT, 4)
.matrix("normal", FloatRepr.FLOAT, 3)
.build())
@ -23,9 +24,9 @@ public final class InstanceTypes {
MemoryUtil.memPutByte(ptr + 1, instance.g);
MemoryUtil.memPutByte(ptr + 2, instance.b);
MemoryUtil.memPutByte(ptr + 3, instance.a);
MemoryUtil.memPutInt(ptr + 4, instance.overlay);
MemoryUtil.memPutShort(ptr + 8, instance.blockLight);
MemoryUtil.memPutShort(ptr + 10, instance.skyLight);
MemoryUtil.memPutShort(ptr + 4, instance.blockLight);
MemoryUtil.memPutShort(ptr + 6, instance.skyLight);
MemoryUtil.memPutInt(ptr + 8, instance.overlay);
MatrixMath.writeUnsafe(instance.model, ptr + 12);
MatrixMath.writeUnsafe(instance.normal, ptr + 76);
})
@ -36,7 +37,8 @@ public final class InstanceTypes {
public static final InstanceType<OrientedInstance> ORIENTED = SimpleInstanceType.builder(OrientedInstance::new)
.layout(LayoutBuilder.create()
.vector("color", FloatRepr.NORMALIZED_UNSIGNED_BYTE, 4)
.vector("overlay_light", IntegerRepr.SHORT, 4)
.vector("light", IntegerRepr.SHORT, 2)
.vector("overlay", IntegerRepr.SHORT, 2)
.vector("position", FloatRepr.FLOAT, 3)
.vector("pivot", FloatRepr.FLOAT, 3)
.vector("rotation", FloatRepr.FLOAT, 4)
@ -46,9 +48,9 @@ public final class InstanceTypes {
MemoryUtil.memPutByte(ptr + 1, instance.g);
MemoryUtil.memPutByte(ptr + 2, instance.b);
MemoryUtil.memPutByte(ptr + 3, instance.a);
MemoryUtil.memPutInt(ptr + 4, instance.overlay);
MemoryUtil.memPutShort(ptr + 8, instance.blockLight);
MemoryUtil.memPutShort(ptr + 10, instance.skyLight);
MemoryUtil.memPutShort(ptr + 4, instance.blockLight);
MemoryUtil.memPutShort(ptr + 6, instance.skyLight);
MemoryUtil.memPutInt(ptr + 8, instance.overlay);
MemoryUtil.memPutFloat(ptr + 12, instance.posX);
MemoryUtil.memPutFloat(ptr + 16, instance.posY);
MemoryUtil.memPutFloat(ptr + 20, instance.posZ);

View file

@ -4,6 +4,6 @@ void flw_instanceVertex(in FlwInstance i) {
flw_vertexPos = vec4(rotateByQuaternion(flw_vertexPos.xyz - i.pivot, i.rotation) + i.pivot + i.position, 1.0);
flw_vertexNormal = rotateByQuaternion(flw_vertexNormal, i.rotation);
flw_vertexColor = i.color;
flw_vertexOverlay = i.overlay_light.xy;
flw_vertexLight = i.overlay_light.zw / 15.0;
flw_vertexOverlay = i.overlay;
flw_vertexLight = i.light / 15.0;
}

View file

@ -2,6 +2,6 @@ void flw_instanceVertex(in FlwInstance i) {
flw_vertexPos = i.pose * flw_vertexPos;
flw_vertexNormal = i.normal * flw_vertexNormal;
flw_vertexColor = i.color;
flw_vertexOverlay = i.overlay_light.xy;
flw_vertexLight = i.overlay_light.zw / 15.0;
flw_vertexOverlay = i.overlay;
flw_vertexLight = i.light / 15.0;
}

View file

@ -1,14 +1,15 @@
layout(location = 0) in vec3 _flw_a_pos;
layout(location = 1) in vec4 _flw_a_color;
layout(location = 2) in vec2 _flw_a_texCoord;
layout(location = 3) in ivec4 _flw_a_overlay_light;
layout(location = 4) in vec3 _flw_a_normal;
layout(location = 3) in ivec2 _flw_a_overlay;
layout(location = 4) in ivec2 _flw_a_light;
layout(location = 5) in vec3 _flw_a_normal;
void _flw_layoutVertex() {
flw_vertexPos = vec4(_flw_a_pos, 1.0);
flw_vertexColor = _flw_a_color;
flw_vertexTexCoord = _flw_a_texCoord;
flw_vertexOverlay = _flw_a_overlay_light.xy;
flw_vertexLight = (_flw_a_overlay_light.zw >> 4) / 15.0;
flw_vertexOverlay = _flw_a_overlay;
flw_vertexLight = (_flw_a_light >> 4) / 15.0;
flw_vertexNormal = _flw_a_normal;
}