Start working on the blocks

- Also better control and visuals
This commit is contained in:
JozsefA 2021-04-18 22:23:41 -07:00
parent a6248daf7e
commit e50590f6b7
14 changed files with 302 additions and 94 deletions

View file

@ -113,6 +113,7 @@ import com.simibubi.create.content.contraptions.relays.encased.GearshiftBlock;
import com.simibubi.create.content.contraptions.relays.gauge.GaugeBlock;
import com.simibubi.create.content.contraptions.relays.gauge.GaugeGenerator;
import com.simibubi.create.content.contraptions.relays.gearbox.GearboxBlock;
import com.simibubi.create.content.curiosities.projector.ChromaticProjectorBlock;
import com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelBlock;
import com.simibubi.create.content.logistics.block.belts.tunnel.BrassTunnelBlock;
import com.simibubi.create.content.logistics.block.belts.tunnel.BrassTunnelCTBehaviour;
@ -1332,25 +1333,26 @@ public class AllBlocks {
.blockstate((c, p) -> p.simpleBlock(c.get(), p.models()
.cubeAll(c.getName(), p.modLoc("block/brass_storage_block"))))
.tag(Tags.Blocks.STORAGE_BLOCKS)
.tag(BlockTags.BEACON_BASE_BLOCKS)
.transform(tagBlockAndItem("storage_blocks/brass"))
.tag(Tags.Items.STORAGE_BLOCKS)
.build()
.register();
.tag(BlockTags.BEACON_BASE_BLOCKS)
.transform(tagBlockAndItem("storage_blocks/brass"))
.tag(Tags.Items.STORAGE_BLOCKS)
.build()
.register();
static {
REGISTRATE.startSection(AllSections.CURIOSITIES);
}
public static final BlockEntry<Block> CHROMATIC_PROJECTOR =
REGISTRATE.block("chromatic_projector", Block::new)
.initialProperties(() -> Blocks.IRON_BLOCK)
.item()
.build()
.register();
public static final BlockEntry<ChromaticProjectorBlock> CHROMATIC_PROJECTOR =
REGISTRATE.block("chromatic_projector", ChromaticProjectorBlock::new)
.initialProperties(() -> Blocks.IRON_BLOCK)
.item()
.build()
.register();
// Load this class
public static void register() {}
public static void register() {
}
}

View file

@ -1,5 +1,7 @@
package com.simibubi.create;
import com.simibubi.create.content.curiosities.projector.ChromaticProjectorContainer;
import com.simibubi.create.content.curiosities.projector.ChromaticProjectorScreen;
import com.simibubi.create.content.logistics.block.inventories.AdjustableCrateContainer;
import com.simibubi.create.content.logistics.block.inventories.AdjustableCrateScreen;
import com.simibubi.create.content.logistics.item.filter.AttributeFilterContainer;
@ -32,6 +34,7 @@ public enum AllContainerTypes {
FLEXCRATE(AdjustableCrateContainer::new),
FILTER(FilterContainer::new),
ATTRIBUTE_FILTER(AttributeFilterContainer::new),
CHROMATIC_PROJECTOR(ChromaticProjectorContainer::new),
;
@ -58,6 +61,7 @@ public enum AllContainerTypes {
bind(FLEXCRATE, AdjustableCrateScreen::new);
bind(FILTER, FilterScreen::new);
bind(ATTRIBUTE_FILTER, AttributeFilterScreen::new);
bind(CHROMATIC_PROJECTOR, ChromaticProjectorScreen::new);
}
@OnlyIn(Dist.CLIENT)

View file

@ -116,7 +116,7 @@ import com.simibubi.create.content.contraptions.relays.gearbox.GearboxInstance;
import com.simibubi.create.content.contraptions.relays.gearbox.GearboxRenderer;
import com.simibubi.create.content.contraptions.relays.gearbox.GearboxTileEntity;
import com.simibubi.create.content.contraptions.relays.gearbox.GearshiftTileEntity;
import com.simibubi.create.content.curiosities.ChromaticProjectorTileEntity;
import com.simibubi.create.content.curiosities.projector.ChromaticProjectorTileEntity;
import com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelInstance;
import com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelRenderer;
import com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelTileEntity;

View file

@ -1,27 +0,0 @@
package com.simibubi.create.content.curiosities;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockReader;
import javax.annotation.Nullable;
import com.simibubi.create.AllTileEntities;
public class ChromaticProjectorBlock extends Block {
public ChromaticProjectorBlock(Properties p_i48440_1_) {
super(p_i48440_1_);
}
@Override
public boolean hasTileEntity(BlockState state) {
return true;
}
@Nullable
@Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return AllTileEntities.TESTFX.create();
}
}

View file

@ -1,10 +0,0 @@
package com.simibubi.create.content.curiosities;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
public class ChromaticProjectorTileEntity extends TileEntity {
public ChromaticProjectorTileEntity(TileEntityType<?> te) {
super(te);
}
}

View file

@ -0,0 +1,52 @@
package com.simibubi.create.content.curiosities.projector;
import javax.annotation.Nullable;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.foundation.block.ITE;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks;
public class ChromaticProjectorBlock extends Block implements ITE<ChromaticProjectorTileEntity> {
public ChromaticProjectorBlock(Properties p_i48440_1_) {
super(p_i48440_1_);
}
@Override
public ActionResultType onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
BlockRayTraceResult hit) {
if (worldIn.isRemote)
return ActionResultType.SUCCESS;
withTileEntityDo(worldIn, pos,
te -> NetworkHooks.openGui((ServerPlayerEntity) player, te, te::sendToContainer));
return ActionResultType.SUCCESS;
}
@Override
public boolean hasTileEntity(BlockState state) {
return true;
}
@Nullable
@Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return AllTileEntities.TESTFX.create();
}
@Override
public Class<ChromaticProjectorTileEntity> getTileEntityClass() {
return ChromaticProjectorTileEntity.class;
}
}

View file

@ -0,0 +1,33 @@
package com.simibubi.create.content.curiosities.projector;
import javax.annotation.Nullable;
import com.simibubi.create.AllContainerTypes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.network.PacketBuffer;
public class ChromaticProjectorContainer extends Container {
public ChromaticProjectorContainer(int id, PlayerInventory inv, PacketBuffer extraData) {
super(AllContainerTypes.CHROMATIC_PROJECTOR.type, id);
}
public ChromaticProjectorContainer(int id, PlayerInventory inv, ChromaticProjectorTileEntity te) {
super(AllContainerTypes.CHROMATIC_PROJECTOR.type, id);
}
public ChromaticProjectorContainer(@Nullable ContainerType<?> p_i50105_1_, int p_i50105_2_) {
super(p_i50105_1_, p_i50105_2_);
}
@Override
public boolean canInteractWith(PlayerEntity p_75145_1_) {
return true;
}
}

View file

@ -0,0 +1,62 @@
package com.simibubi.create.content.curiosities.projector;
import java.util.ArrayList;
import java.util.Collections;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen;
import com.simibubi.create.foundation.gui.AllGuiTextures;
import com.simibubi.create.foundation.gui.widgets.ScrollInput;
import com.simibubi.create.foundation.gui.widgets.SelectionScrollInput;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
public class ChromaticProjectorScreen extends AbstractSimiContainerScreen<ChromaticProjectorContainer> {
private ScrollInput filter;
private ScrollInput radius;
private ScrollInput feather;
private ScrollInput fade;
public ChromaticProjectorScreen(ChromaticProjectorContainer container, PlayerInventory inv, ITextComponent title) {
super(container, inv, title);
}
@Override
protected void init() {
super.init();
widgets.clear();
int x = guiLeft + 11;
int y = guiTop + 20;
ArrayList<ITextComponent> filterOptions = new ArrayList<>();
filterOptions.add(new StringTextComponent("Test"));
filterOptions.add(new StringTextComponent("Test1"));
filter = new SelectionScrollInput(x, y, 77, 18)
.forOptions(filterOptions);
y += 20;
radius = new ScrollInput(x, y, 30, 20);
y += 20;
feather = new ScrollInput(x, y, 30, 20);
y += 20;
fade = new ScrollInput(x, y, 30, 20);
y += 20;
Collections.addAll(widgets, filter, radius, feather, fade);
}
@Override
protected void renderWindow(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
//AllGuiTextures.PLAYER_INVENTORY.draw(matrixStack, this, guiLeft - 10, guiTop + 145);
AllGuiTextures.PROJECTOR.draw(matrixStack, this, guiLeft, guiTop);
// BG_TOP.draw(matrixStack, this, guiLeft + 20, guiTop);
// BG_BOTTOM.draw(matrixStack, this, guiLeft + 20, guiTop + BG_TOP.height);
}
}

View file

@ -0,0 +1,40 @@
package com.simibubi.create.content.curiosities.projector;
import javax.annotation.Nullable;
import com.simibubi.create.foundation.render.backend.effects.SphereFilterProgram;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
public class ChromaticProjectorTileEntity extends TileEntity implements INamedContainerProvider {
SphereFilterProgram.FilterSphere filter;
public ChromaticProjectorTileEntity(TileEntityType<?> te) {
super(te);
}
public void sendToContainer(PacketBuffer buffer) {
buffer.writeBlockPos(getPos());
buffer.writeCompoundTag(getUpdateTag());
}
@Override
public ITextComponent getDisplayName() {
return new StringTextComponent("Chromatic Projector");
}
@Nullable
@Override
public Container createMenu(int p_createMenu_1_, PlayerInventory p_createMenu_2_, PlayerEntity p_createMenu_3_) {
return new ChromaticProjectorContainer(p_createMenu_1_, p_createMenu_2_, this);
}
}

View file

@ -56,6 +56,8 @@ public enum AllGuiTextures implements IScreenRenderable {
SEQUENCER_EMPTY("sequencer.png", 0, 102, 162, 22),
SEQUENCER_AWAIT("sequencer.png", 0, 160, 162, 22),
PROJECTOR("projector.png", 173, 159),
// JEI
JEI_SLOT("jei/widgets.png", 18, 18),
JEI_CHANCE_SLOT("jei/widgets.png", 20, 156, 18, 18),

View file

@ -107,7 +107,6 @@ public class EffectsHandler {
inverseView.invert();
program.bindInverseView(inverseView);
Vector3d pos1 = new Vector3d(865.5, 79, -240.5);
Vector3d cameraPos = gameRenderer.getActiveRenderInfo().getProjectedView();
program.setCameraPos(cameraPos.inverse());
@ -123,15 +122,39 @@ public class EffectsHandler {
// .setFilter(ColorMatrices.hueShiftRGB((float) i / n * 360 + i / 2f)));
// }
Matrix4f filter = ColorMatrices.sepia(1f);
program.addSphere(new SphereFilterProgram.FilterSphere()
.setCenter(pos1.subtract(cameraPos))
.setCenter(new Vector3d(865.5, 79, -240.5).subtract(cameraPos))
.setRadius(10f)
.setFeather(3f)
.setFade(1.5f)
.setHsv(false)
.setFilter(filter));
.setFade(1.8f)
.setDensity(1.3f)
.setFilter(ColorMatrices.grayscale()));
program.addSphere(new SphereFilterProgram.FilterSphere()
.setCenter(new Vector3d(858.5, 88, -259.5).subtract(cameraPos))
.setRadius(10f)
.setFeather(3f)
.setFade(1.8f)
.setDensity(1.3f)
.setStrength(1f)
.setFilter(ColorMatrices.sepia(1f)));
Matrix4f test = ColorMatrices.grayscale();
Matrix4f colorize = new Matrix4f();
colorize.a00 = 1f;
colorize.a11 = 0.5f;
colorize.a22 = 0.5f;
colorize.a33 = 1f;
test = colorize;
program.addSphere(new SphereFilterProgram.FilterSphere()
.setCenter(new Vector3d(2310, 60, -954).subtract(cameraPos))
.setRadius(8f)
.setFeather(3f)
.setFade(0.1f)
.setDensity(0.5f)
.setStrength(1f)
.setFilter(test));
program.uploadFilters();

View file

@ -127,8 +127,8 @@ public class SphereFilterProgram extends GlProgram {
public float radius;
public float feather;
public float fade;
public float density = 2;
public float strength = 1;
public boolean hsv;
public Matrix4f filter;
@ -152,13 +152,13 @@ public class SphereFilterProgram extends GlProgram {
return this;
}
public FilterSphere setStrength(float strength) {
this.strength = strength;
public FilterSphere setDensity(float density) {
this.density = density;
return this;
}
public FilterSphere setHsv(boolean hsv) {
this.hsv = hsv;
public FilterSphere setStrength(float strength) {
this.strength = strength;
return this;
}
@ -175,8 +175,8 @@ public class SphereFilterProgram extends GlProgram {
radius,
feather,
fade,
density,
strength,
hsv ? 1f : 0f,
});
buf.put(RenderUtil.writeMatrix(filter));

View file

@ -16,11 +16,35 @@ uniform vec3 uCameraPos;
struct SphereFilter {
vec4 sphere;// <vec3 position, float radius>
vec4 data;// <float feather, float fade, float strength, float hsv marker>
vec4 data;// <float feather, float fade, float density, float strength>
mat4 colorOp;
};
#define N 256
vec3 getPosition(SphereFilter f) {
return f.sphere.xyz;
}
float getRadius(SphereFilter f) {
return f.sphere.w;
}
float getFeather(SphereFilter f) {
return f.data.x;
}
float getFade(SphereFilter f) {
return f.data.y;
}
float getDensity(SphereFilter f) {
return f.data.z;
}
float getStrength(SphereFilter f) {
return f.data.w;
}
#define N 256
layout (std140) uniform Filters {
int uCount;
SphereFilter uSpheres[N];
@ -44,65 +68,68 @@ float getDepth() {
return linearizeDepth(depth, uNearPlane, uFarPlane);
}
float overlayFilterAmount(in vec3 worldPos, in vec4 sphere, in float feather) {
float surfaceFilterStrength(vec3 worldPos, vec4 sphere, float feather) {
float distance = distance(sphere.xyz, worldPos);
return 1 - smoothstep(sphere.w, sphere.w + feather, distance);
}
float sphereFilterAmount(in vec3 worldDir, in float depth, in vec4 sphere, in vec4 data) {
float feathering = 1 - smoothstep(sphere.w + data.x, sphere.w + data.x + data.y, length(sphere.xyz));
feathering += overlayFilterAmount(worldDir * depth, sphere, data.x);
vec3 oc = -sphere.xyz;
float bubbleFilterStrength(vec3 worldDir, float depth, vec4 sphere, float feather, float density) {
vec3 position = sphere.xyz;
float rayLengthSqr = dot(worldDir, worldDir);
float b = 2.0 * dot(-sphere.xyz, worldDir);
float sphereDistSqr = dot(sphere.xyz, sphere.xyz);
float b = 2.0 * dot(-position, worldDir);
float sphereDistSqr = dot(position, position);
float b2 = b*b;
float d = 4. * rayLengthSqr;
float e = 1. / (2.0*rayLengthSqr);
float radius = sphere.w + data.x;
float radius = sphere.w + feather;
float c = sphereDistSqr - radius*radius;
float discriminant = b2 - d * c;
float hitDepth = (-b - sqrt(discriminant)) * e;
float strength = 0.;
if (discriminant > 0 && hitDepth > 0 && hitDepth < depth) {
// float c = sphereDistSqr - sphere.w*sphere.w;
// float discriminant = b2 - d * c;
// float hitDepth = (-b - sqrt(discriminant)) * e;
vec3 hitPos = worldDir * hitDepth;
vec3 normal = normalize(hitPos - sphere.xyz);
vec3 normal = normalize(hitPos - position);
float normalDot = dot(normal, normalize(worldDir));
return feathering + normalDot * normalDot;
} else {
return feathering;
// blend into the effect based on the distance between the fragcoord and point on the sphere
// this avoinds having hard edges
strength += mix(0., normalDot * normalDot * density, clamp(depth - hitDepth, 0., feather + 1.));
}
return clamp(strength, 0., 1.);
}
vec3 applyFilters(in vec3 worldDir, in float depth, in vec3 diffuse) {
float filterStrength(vec3 worldDir, float depth, vec4 sphere, vec4 data) {
float feather = data.x;
float strength = 0.;
// transition effect
float transitionRadius = sphere.w + feather;
strength += 1. - smoothstep(transitionRadius, transitionRadius + data.y, length(sphere.xyz));
// surface effect
strength += surfaceFilterStrength(worldDir * depth, sphere, feather);
// bubble effect
strength += bubbleFilterStrength(worldDir, depth, sphere, feather, data.z);
return strength;
}
vec3 applyFilters(vec3 worldDir, float depth, vec3 diffuse) {
vec3 worldPos = worldDir * depth;
vec3 accum = diffuse;
vec3 diffuseHSV = rgb2hsv(accum);
vec3 accum = vec3(diffuse);
for (int i = 0; i < uCount; i++) {
SphereFilter s = uSpheres[i];
//float strength = overlayFilterAmount(worldPos, s.sphere, s.data.x);
float strength = sphereFilterAmount(worldDir, depth, s.sphere, s.data);
//accum = vec3(strength, strength, strength);
vec3 toFilter = mix(diffuse, diffuseHSV, s.data.w);
float strength = filterStrength(worldDir, depth, s.sphere, s.data);
vec3 filtered = filterColor(s.colorOp, diffuse);
filtered = mix(filtered, hsv2rgbWrapped(filtered), s.data.w);
accum = mix(accum, filtered, clamp(strength * s.data.z, 0., 1.));
accum = mix(accum, filtered, clamp(strength * s.data.w, 0., 1.));
}
return accum;

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB