mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-29 08:26:37 +01:00
Compare commits
2 commits
dc928b7b7e
...
9b9089ea64
Author | SHA1 | Date | |
---|---|---|---|
|
9b9089ea64 | ||
|
51458c2768 |
9 changed files with 51 additions and 33 deletions
|
@ -19,8 +19,7 @@ public final class InternalVertex {
|
||||||
.vector("position", FloatRepr.FLOAT, 3)
|
.vector("position", FloatRepr.FLOAT, 3)
|
||||||
.vector("color", FloatRepr.NORMALIZED_UNSIGNED_BYTE, 4)
|
.vector("color", FloatRepr.NORMALIZED_UNSIGNED_BYTE, 4)
|
||||||
.vector("tex", FloatRepr.FLOAT, 2)
|
.vector("tex", FloatRepr.FLOAT, 2)
|
||||||
.vector("overlay", UnsignedIntegerRepr.UNSIGNED_SHORT, 2)
|
.vector("overlay_light", UnsignedIntegerRepr.UNSIGNED_SHORT, 4)
|
||||||
.vector("light", UnsignedIntegerRepr.UNSIGNED_SHORT, 2)
|
|
||||||
.vector("normal", FloatRepr.NORMALIZED_BYTE, 3)
|
.vector("normal", FloatRepr.NORMALIZED_BYTE, 3)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.jozufozu.flywheel.backend.compile;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -22,26 +23,37 @@ import net.minecraft.server.packs.resources.ResourceManager;
|
||||||
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
|
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
|
||||||
|
|
||||||
public final class FlwPrograms {
|
public final class FlwPrograms {
|
||||||
public static final Logger LOGGER = LoggerFactory.getLogger(Flywheel.ID + "/compile");
|
public static final Logger LOGGER = LoggerFactory.getLogger(Flywheel.ID + "/shaders");
|
||||||
|
|
||||||
private FlwPrograms() {
|
private FlwPrograms() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void reload(ResourceManager resourceManager) {
|
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 sources = new ShaderSources(resourceManager);
|
||||||
var preLoadStats = new CompilerStats("Preload");
|
var stats = new CompilerStats("ubershaders");
|
||||||
var loadChecker = new SourceLoader(sources, preLoadStats);
|
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 pipelineKeys = createPipelineKeys();
|
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);
|
InstancingPrograms.reload(sources, pipelineKeys, vertexComponents, fragmentComponents);
|
||||||
IndirectPrograms.reload(sources, pipelineKeys, vertexComponents, fragmentComponents);
|
IndirectPrograms.reload(sources, pipelineKeys, vertexComponents, fragmentComponents);
|
||||||
|
|
||||||
if (preLoadStats.errored()) {
|
|
||||||
preLoadStats.emitErrorLog();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ImmutableList<PipelineProgramKey> createPipelineKeys() {
|
private static ImmutableList<PipelineProgramKey> createPipelineKeys() {
|
||||||
|
@ -54,6 +66,7 @@ public final class FlwPrograms {
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private static UberShaderComponent createVertexMaterialComponent(SourceLoader loadChecker) {
|
private static UberShaderComponent createVertexMaterialComponent(SourceLoader loadChecker) {
|
||||||
return UberShaderComponent.builder(Flywheel.rl("uber_material_vertex"))
|
return UberShaderComponent.builder(Flywheel.rl("uber_material_vertex"))
|
||||||
.materialSources(ShaderIndices.materialVertex()
|
.materialSources(ShaderIndices.materialVertex()
|
||||||
|
@ -63,6 +76,7 @@ public final class FlwPrograms {
|
||||||
.build(loadChecker);
|
.build(loadChecker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private static UberShaderComponent createFragmentMaterialComponent(SourceLoader loadChecker) {
|
private static UberShaderComponent createFragmentMaterialComponent(SourceLoader loadChecker) {
|
||||||
return UberShaderComponent.builder(Flywheel.rl("uber_material_fragment"))
|
return UberShaderComponent.builder(Flywheel.rl("uber_material_fragment"))
|
||||||
.materialSources(ShaderIndices.materialFragment()
|
.materialSources(ShaderIndices.materialFragment()
|
||||||
|
@ -72,6 +86,7 @@ public final class FlwPrograms {
|
||||||
.build(loadChecker);
|
.build(loadChecker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private static UberShaderComponent createFogComponent(SourceLoader loadChecker) {
|
private static UberShaderComponent createFogComponent(SourceLoader loadChecker) {
|
||||||
return UberShaderComponent.builder(Flywheel.rl("uber_fog"))
|
return UberShaderComponent.builder(Flywheel.rl("uber_fog"))
|
||||||
.materialSources(ShaderIndices.fog()
|
.materialSources(ShaderIndices.fog()
|
||||||
|
@ -85,6 +100,7 @@ public final class FlwPrograms {
|
||||||
.build(loadChecker);
|
.build(loadChecker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private static UberShaderComponent createCutoutComponent(SourceLoader loadChecker) {
|
private static UberShaderComponent createCutoutComponent(SourceLoader loadChecker) {
|
||||||
return UberShaderComponent.builder(Flywheel.rl("uber_cutout"))
|
return UberShaderComponent.builder(Flywheel.rl("uber_cutout"))
|
||||||
.materialSources(ShaderIndices.cutout()
|
.materialSources(ShaderIndices.cutout()
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.jozufozu.flywheel.backend.compile;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
@ -102,7 +103,8 @@ public class IndirectPrograms extends AbstractPrograms {
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setInstance(@Nullable IndirectPrograms newInstance) {
|
@ApiStatus.Internal
|
||||||
|
public static void setInstance(@Nullable IndirectPrograms newInstance) {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
instance.release();
|
instance.release();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.jozufozu.flywheel.backend.compile;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
@ -42,7 +43,8 @@ public class InstancingPrograms extends AbstractPrograms {
|
||||||
setInstance(newInstance);
|
setInstance(newInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setInstance(@Nullable InstancingPrograms newInstance) {
|
@ApiStatus.Internal
|
||||||
|
public static void setInstance(@Nullable InstancingPrograms newInstance) {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
instance.release();
|
instance.release();
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,6 +108,7 @@ public class UberShaderComponent implements SourceComponent {
|
||||||
private final ResourceLocation name;
|
private final ResourceLocation name;
|
||||||
private final List<ResourceLocation> materialSources = new ArrayList<>();
|
private final List<ResourceLocation> materialSources = new ArrayList<>();
|
||||||
private final List<AdaptedFn> adaptedFunctions = new ArrayList<>();
|
private final List<AdaptedFn> adaptedFunctions = new ArrayList<>();
|
||||||
|
@Nullable
|
||||||
private GlslExpr switchArg;
|
private GlslExpr switchArg;
|
||||||
|
|
||||||
public Builder(ResourceLocation name) {
|
public Builder(ResourceLocation name) {
|
||||||
|
@ -134,6 +135,7 @@ public class UberShaderComponent implements SourceComponent {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public UberShaderComponent build(SourceLoader sources) {
|
public UberShaderComponent build(SourceLoader sources) {
|
||||||
if (switchArg == null) {
|
if (switchArg == null) {
|
||||||
throw new NullPointerException("Switch argument must be set");
|
throw new NullPointerException("Switch argument must be set");
|
||||||
|
|
|
@ -14,8 +14,7 @@ public final class InstanceTypes {
|
||||||
public static final InstanceType<TransformedInstance> TRANSFORMED = SimpleInstanceType.builder(TransformedInstance::new)
|
public static final InstanceType<TransformedInstance> TRANSFORMED = SimpleInstanceType.builder(TransformedInstance::new)
|
||||||
.layout(LayoutBuilder.create()
|
.layout(LayoutBuilder.create()
|
||||||
.vector("color", FloatRepr.NORMALIZED_UNSIGNED_BYTE, 4)
|
.vector("color", FloatRepr.NORMALIZED_UNSIGNED_BYTE, 4)
|
||||||
.vector("light", IntegerRepr.SHORT, 2)
|
.vector("overlay_light", IntegerRepr.SHORT, 4)
|
||||||
.vector("overlay", IntegerRepr.SHORT, 2)
|
|
||||||
.matrix("pose", FloatRepr.FLOAT, 4)
|
.matrix("pose", FloatRepr.FLOAT, 4)
|
||||||
.matrix("normal", FloatRepr.FLOAT, 3)
|
.matrix("normal", FloatRepr.FLOAT, 3)
|
||||||
.build())
|
.build())
|
||||||
|
@ -24,9 +23,9 @@ public final class InstanceTypes {
|
||||||
MemoryUtil.memPutByte(ptr + 1, instance.g);
|
MemoryUtil.memPutByte(ptr + 1, instance.g);
|
||||||
MemoryUtil.memPutByte(ptr + 2, instance.b);
|
MemoryUtil.memPutByte(ptr + 2, instance.b);
|
||||||
MemoryUtil.memPutByte(ptr + 3, instance.a);
|
MemoryUtil.memPutByte(ptr + 3, instance.a);
|
||||||
MemoryUtil.memPutShort(ptr + 4, instance.blockLight);
|
MemoryUtil.memPutInt(ptr + 4, instance.overlay);
|
||||||
MemoryUtil.memPutShort(ptr + 6, instance.skyLight);
|
MemoryUtil.memPutShort(ptr + 8, instance.blockLight);
|
||||||
MemoryUtil.memPutInt(ptr + 8, instance.overlay);
|
MemoryUtil.memPutShort(ptr + 10, instance.skyLight);
|
||||||
MatrixMath.writeUnsafe(instance.model, ptr + 12);
|
MatrixMath.writeUnsafe(instance.model, ptr + 12);
|
||||||
MatrixMath.writeUnsafe(instance.normal, ptr + 76);
|
MatrixMath.writeUnsafe(instance.normal, ptr + 76);
|
||||||
})
|
})
|
||||||
|
@ -37,8 +36,7 @@ public final class InstanceTypes {
|
||||||
public static final InstanceType<OrientedInstance> ORIENTED = SimpleInstanceType.builder(OrientedInstance::new)
|
public static final InstanceType<OrientedInstance> ORIENTED = SimpleInstanceType.builder(OrientedInstance::new)
|
||||||
.layout(LayoutBuilder.create()
|
.layout(LayoutBuilder.create()
|
||||||
.vector("color", FloatRepr.NORMALIZED_UNSIGNED_BYTE, 4)
|
.vector("color", FloatRepr.NORMALIZED_UNSIGNED_BYTE, 4)
|
||||||
.vector("light", IntegerRepr.SHORT, 2)
|
.vector("overlay_light", IntegerRepr.SHORT, 4)
|
||||||
.vector("overlay", IntegerRepr.SHORT, 2)
|
|
||||||
.vector("position", FloatRepr.FLOAT, 3)
|
.vector("position", FloatRepr.FLOAT, 3)
|
||||||
.vector("pivot", FloatRepr.FLOAT, 3)
|
.vector("pivot", FloatRepr.FLOAT, 3)
|
||||||
.vector("rotation", FloatRepr.FLOAT, 4)
|
.vector("rotation", FloatRepr.FLOAT, 4)
|
||||||
|
@ -48,9 +46,9 @@ public final class InstanceTypes {
|
||||||
MemoryUtil.memPutByte(ptr + 1, instance.g);
|
MemoryUtil.memPutByte(ptr + 1, instance.g);
|
||||||
MemoryUtil.memPutByte(ptr + 2, instance.b);
|
MemoryUtil.memPutByte(ptr + 2, instance.b);
|
||||||
MemoryUtil.memPutByte(ptr + 3, instance.a);
|
MemoryUtil.memPutByte(ptr + 3, instance.a);
|
||||||
MemoryUtil.memPutShort(ptr + 4, instance.blockLight);
|
MemoryUtil.memPutInt(ptr + 4, instance.overlay);
|
||||||
MemoryUtil.memPutShort(ptr + 6, instance.skyLight);
|
MemoryUtil.memPutShort(ptr + 8, instance.blockLight);
|
||||||
MemoryUtil.memPutInt(ptr + 8, instance.overlay);
|
MemoryUtil.memPutShort(ptr + 10, instance.skyLight);
|
||||||
MemoryUtil.memPutFloat(ptr + 12, instance.posX);
|
MemoryUtil.memPutFloat(ptr + 12, instance.posX);
|
||||||
MemoryUtil.memPutFloat(ptr + 16, instance.posY);
|
MemoryUtil.memPutFloat(ptr + 16, instance.posY);
|
||||||
MemoryUtil.memPutFloat(ptr + 20, instance.posZ);
|
MemoryUtil.memPutFloat(ptr + 20, instance.posZ);
|
||||||
|
|
|
@ -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_vertexPos = vec4(rotateByQuaternion(flw_vertexPos.xyz - i.pivot, i.rotation) + i.pivot + i.position, 1.0);
|
||||||
flw_vertexNormal = rotateByQuaternion(flw_vertexNormal, i.rotation);
|
flw_vertexNormal = rotateByQuaternion(flw_vertexNormal, i.rotation);
|
||||||
flw_vertexColor = i.color;
|
flw_vertexColor = i.color;
|
||||||
flw_vertexOverlay = i.overlay;
|
flw_vertexOverlay = i.overlay_light.xy;
|
||||||
flw_vertexLight = i.light / 15.0;
|
flw_vertexLight = i.overlay_light.zw / 15.0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,6 @@ void flw_instanceVertex(in FlwInstance i) {
|
||||||
flw_vertexPos = i.pose * flw_vertexPos;
|
flw_vertexPos = i.pose * flw_vertexPos;
|
||||||
flw_vertexNormal = i.normal * flw_vertexNormal;
|
flw_vertexNormal = i.normal * flw_vertexNormal;
|
||||||
flw_vertexColor = i.color;
|
flw_vertexColor = i.color;
|
||||||
flw_vertexOverlay = i.overlay;
|
flw_vertexOverlay = i.overlay_light.xy;
|
||||||
flw_vertexLight = i.light / 15.0;
|
flw_vertexLight = i.overlay_light.zw / 15.0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
layout(location = 0) in vec3 _flw_a_pos;
|
layout(location = 0) in vec3 _flw_a_pos;
|
||||||
layout(location = 1) in vec4 _flw_a_color;
|
layout(location = 1) in vec4 _flw_a_color;
|
||||||
layout(location = 2) in vec2 _flw_a_texCoord;
|
layout(location = 2) in vec2 _flw_a_texCoord;
|
||||||
layout(location = 3) in ivec2 _flw_a_overlay;
|
layout(location = 3) in ivec4 _flw_a_overlay_light;
|
||||||
layout(location = 4) in ivec2 _flw_a_light;
|
layout(location = 4) in vec3 _flw_a_normal;
|
||||||
layout(location = 5) in vec3 _flw_a_normal;
|
|
||||||
|
|
||||||
void _flw_layoutVertex() {
|
void _flw_layoutVertex() {
|
||||||
flw_vertexPos = vec4(_flw_a_pos, 1.0);
|
flw_vertexPos = vec4(_flw_a_pos, 1.0);
|
||||||
flw_vertexColor = _flw_a_color;
|
flw_vertexColor = _flw_a_color;
|
||||||
flw_vertexTexCoord = _flw_a_texCoord;
|
flw_vertexTexCoord = _flw_a_texCoord;
|
||||||
flw_vertexOverlay = _flw_a_overlay;
|
flw_vertexOverlay = _flw_a_overlay_light.xy;
|
||||||
flw_vertexLight = (_flw_a_light >> 4) / 15.0;
|
flw_vertexLight = (_flw_a_overlay_light.zw >> 4) / 15.0;
|
||||||
flw_vertexNormal = _flw_a_normal;
|
flw_vertexNormal = _flw_a_normal;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue