Skip to content

Commit

Permalink
Moving from core shaders to Satin Managed Core Shaders (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kir-Antipov committed Jun 1, 2022
1 parent 2f4d6e8 commit 0c55e88
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 75 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ dependencies {

modImplementation(include("de.guntram.mcmod:crowdin-translate:${project.crowdin_translate_version}"))
modImplementation(include("teamreborn:energy:${project.tr_energy_version}"))
modImplementation(include("io.github.ladysnake:satin:${project.satin_version}"))
modImplementation(include("maven.modrinth:smart-recipes:${project.smartrecipes_version}"))
modImplementation(include("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_version}"), {
exclude group: "net.fabricmc.fabric-api"
Expand All @@ -114,6 +115,7 @@ processResources {
"minecraft": ">=${minecraftDependencyVersion}",
"smart_recipes": project.smartrecipes_version,
"cloth_config": project.cloth_version,
"satin_api": project.satin_version,
"crowdin_translate": project.crowdin_translate_version,
"team_reborn_energy": project.tr_energy_version,
"modmenu": ">=${project.modmenu_version}",
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ archives_base_name=sync
# Dependencies
fabric_version=0.47.8+1.18.2
tr_energy_version=2.2.0
satin_version=1.7.2
cloth_version=6.2.57
modmenu_version=3.1.1
trinkets_version=3.3.0
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dev/kir/sync/Sync.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.kir.sync;

import de.guntram.mcmod.crowdintranslate.CrowdinTranslate;
import dev.kir.sync.client.render.CustomGameRenderer;
import dev.kir.sync.networking.SyncPackets;
import dev.kir.sync.block.SyncBlocks;
import dev.kir.sync.block.entity.SyncBlockEntities;
Expand Down Expand Up @@ -41,6 +42,7 @@ public void onInitialize() {
@Override
@Environment(EnvType.CLIENT)
public void onInitializeClient() {
CustomGameRenderer.initClient();
SyncRenderers.initClient();
SyncPackets.initClient();

Expand Down
38 changes: 27 additions & 11 deletions src/main/java/dev/kir/sync/client/render/CustomGameRenderer.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
package dev.kir.sync.client.render;

import dev.kir.sync.Sync;
import ladysnake.satin.api.managed.ManagedCoreShader;
import ladysnake.satin.api.managed.ShaderEffectManager;
import ladysnake.satin.api.managed.uniform.Uniform1f;
import ladysnake.satin.api.managed.uniform.UniformMat4;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BufferBuilderStorage;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.Shader;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.math.Matrix4f;

@Environment(EnvType.CLIENT)
public final class CustomGameRenderer extends GameRenderer {
private static Shader renderTypeEntityTranslucentPartiallyTexturedShader = null;
private static Shader renderTypeVoxelShader = null;
private static final ManagedCoreShader RENDER_TYPE_ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED_SHADER;
private static final Uniform1f RENDER_TYPE_ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED_SHADER_UNIFORM_CUTOUT_Y;
private static final UniformMat4 RENDER_TYPE_ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED_SHADER_UNIFORM_MODEL_MAT;

private static final ManagedCoreShader RENDER_TYPE_VOXEL_SHADER;

private CustomGameRenderer(MinecraftClient client, ResourceManager resourceManager, BufferBuilderStorage buffers) {
super(client, resourceManager, buffers);
}

public static void setRenderTypeEntityTranslucentPartiallyTexturedShader(Shader shader) {
renderTypeEntityTranslucentPartiallyTexturedShader = shader;
public static void initRenderTypeEntityTranslucentPartiallyTexturedShader(float cutoutY, Matrix4f modelMatrix) {
RENDER_TYPE_ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED_SHADER_UNIFORM_CUTOUT_Y.set(cutoutY);
RENDER_TYPE_ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED_SHADER_UNIFORM_MODEL_MAT.set(modelMatrix);
}

public static Shader getRenderTypeEntityTranslucentPartiallyTexturedShader() {
return renderTypeEntityTranslucentPartiallyTexturedShader;
public static ManagedCoreShader getRenderTypeEntityTranslucentPartiallyTexturedShader() {
return RENDER_TYPE_ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED_SHADER;
}

public static void setRenderTypeVoxelShader(Shader shader) {
renderTypeVoxelShader = shader;
public static ManagedCoreShader getRenderTypeVoxelShader() {
return RENDER_TYPE_VOXEL_SHADER;
}

public static Shader getRenderTypeVoxelShader() {
return renderTypeVoxelShader;
public static void initClient() { }

static {
RENDER_TYPE_ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED_SHADER = ShaderEffectManager.getInstance().manageCoreShader(Sync.locate("rendertype_entity_translucent_partially_textured"), VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL);
RENDER_TYPE_ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED_SHADER_UNIFORM_CUTOUT_Y = RENDER_TYPE_ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED_SHADER.findUniform1f("CutoutY");
RENDER_TYPE_ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED_SHADER_UNIFORM_MODEL_MAT = RENDER_TYPE_ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED_SHADER.findUniformMat4("ModelMat");

RENDER_TYPE_VOXEL_SHADER = ShaderEffectManager.getInstance().manageCoreShader(Sync.locate("rendertype_voxel"), CustomVertexFormats.POSITION_COLOR_OVERLAY_LIGHT_NORMAL);
}
}
15 changes: 3 additions & 12 deletions src/main/java/dev/kir/sync/client/render/CustomRenderLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderPhase;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;

import java.util.function.BiFunction;

@Environment(EnvType.CLIENT)
public final class CustomRenderLayer extends RenderLayer {
private static final Shader ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED_SHADER;
private static final Shader VOXEL_SHADER;

private static final RenderLayer VOXELS;
private static final BiFunction<Identifier, Boolean, RenderLayer> ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED;

Expand All @@ -32,17 +28,12 @@ public static RenderLayer getEntityTranslucentPartiallyTextured(Identifier textu
}

public static RenderLayer getEntityTranslucentPartiallyTextured(Identifier textureId, float cutoutY, boolean affectsOutline) {
net.minecraft.client.render.Shader shader = CustomGameRenderer.getRenderTypeEntityTranslucentPartiallyTexturedShader();
shader.getUniformOrDefault("CutoutY").set(cutoutY);
shader.getUniformOrDefault("ModelMat").set(MatrixStackStorage.getModelMatrixStack().peek().getPositionMatrix());
CustomGameRenderer.initRenderTypeEntityTranslucentPartiallyTexturedShader(cutoutY, MatrixStackStorage.getModelMatrixStack().peek().getPositionMatrix());
return ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED.apply(textureId, affectsOutline);
}

static {
ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED_SHADER = new Shader(CustomGameRenderer::getRenderTypeEntityTranslucentPartiallyTexturedShader);
VOXEL_SHADER = new Shader(CustomGameRenderer::getRenderTypeVoxelShader);

VOXELS = of("voxels", CustomVertexFormats.POSITION_COLOR_OVERLAY_LIGHT_NORMAL, VertexFormat.DrawMode.QUADS, 256, false, false, RenderLayer.MultiPhaseParameters.builder().shader(VOXEL_SHADER).transparency(NO_TRANSPARENCY).cull(DISABLE_CULLING).lightmap(ENABLE_LIGHTMAP).overlay(ENABLE_OVERLAY_COLOR).build(true));
ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED = Util.memoize((id, outline) -> RenderLayer.of("entity_translucent_partially_textured", VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL, VertexFormat.DrawMode.QUADS, 256, true, true, RenderLayer.MultiPhaseParameters.builder().shader(ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED_SHADER).texture(new RenderPhase.Texture(id, false, false)).transparency(RenderLayer.TRANSLUCENT_TRANSPARENCY).cull(RenderLayer.DISABLE_CULLING).lightmap(RenderLayer.ENABLE_LIGHTMAP).overlay(RenderLayer.ENABLE_OVERLAY_COLOR).build(outline)));
VOXELS = CustomGameRenderer.getRenderTypeVoxelShader().getRenderLayer(of("voxels", CustomVertexFormats.POSITION_COLOR_OVERLAY_LIGHT_NORMAL, VertexFormat.DrawMode.QUADS, 256, false, false, RenderLayer.MultiPhaseParameters.builder().shader(RenderPhase.SOLID_SHADER).transparency(NO_TRANSPARENCY).cull(DISABLE_CULLING).lightmap(ENABLE_LIGHTMAP).overlay(ENABLE_OVERLAY_COLOR).build(true)));
ENTITY_TRANSLUCENT_PARTIALLY_TEXTURED = Util.memoize((id, outline) -> CustomGameRenderer.getRenderTypeEntityTranslucentPartiallyTexturedShader().getRenderLayer(RenderLayer.getEntityTranslucent(id, outline)));
}
}
47 changes: 0 additions & 47 deletions src/main/java/dev/kir/sync/mixin/GameRendererMixin.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"srcrgb": "srcalpha",
"dstrgb": "1-srcalpha"
},
"vertex": "rendertype_entity_translucent_partially_textured",
"fragment": "rendertype_entity_translucent_partially_textured",
"vertex": "sync:rendertype_entity_translucent_partially_textured",
"fragment": "sync:rendertype_entity_translucent_partially_textured",
"attributes": [
"Position",
"Color",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"srcrgb": "srcalpha",
"dstrgb": "1-srcalpha"
},
"vertex": "rendertype_voxel",
"fragment": "rendertype_voxel",
"vertex": "sync:rendertype_voxel",
"fragment": "sync:rendertype_voxel",
"attributes": [
"Position",
"Color",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"includes": {
"smart-recipes": "${smart_recipes}",
"cloth-config": "${cloth_config}",
"satin-api": "${satin_api}",
"crowdin-translate": "${crowdin_translate}",
"team_reborn_energy": "${team_reborn_energy}"
},
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/sync.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"ClientPlayerEntityMixin",
"ClientPlayerInteractionManagerMixin",
"EntityRenderDispatcherMixin",
"GameRendererMixin",
"MinecraftClientMixin",
"PlayerEntityModelMixin",
"WorldRendererMixin"
Expand Down

0 comments on commit 0c55e88

Please sign in to comment.