Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colored flood fill lighting #428

Open
wants to merge 76 commits into
base: 1.20
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
59405b7
Working light propagation and data storage
spiralhalo Jun 2, 2023
e890130
Cleanup cruft
spiralhalo Jun 2, 2023
0fdac19
Move encoding out into one place
spiralhalo Jun 2, 2023
47e53d5
Perform light replacement in heap
spiralhalo Jun 2, 2023
9582811
Make BVec cache thread-local because it just makes sense
spiralhalo Jun 2, 2023
fa9d2ea
Make propagation tasks child of RenderRegion task
spiralhalo Jun 2, 2023
ee28df8
Small improvements
spiralhalo Jun 2, 2023
0fac619
Prevent propagating in the opposite direction
spiralhalo Jun 3, 2023
2499b0d
Upload light data in fixed location in the render loop
spiralhalo Jun 3, 2023
6703cb7
Mask removals based on 0 bits
spiralhalo Jun 4, 2023
73096f7
Do per-face occlusion
spiralhalo Jun 4, 2023
3853ba6
Restore decimated light source
spiralhalo Jun 4, 2023
f2e3503
Try expand static area with dummy allocator
spiralhalo Jun 4, 2023
6a9dc23
Propagate to neighboring chunks, do updates in render thread
spiralhalo Jun 4, 2023
f38b99b
Loop through every regions within extent for update
spiralhalo Jun 5, 2023
b597751
Propagate chunk edge lights for new regions
spiralhalo Jun 5, 2023
7875071
Use ResourceCache for light registry
spiralhalo Jun 6, 2023
4c16822
Set alpha (flags) to registered during restoration
spiralhalo Jun 7, 2023
b4a26cd
Process decrease before increase frame-wide, and also twice
spiralhalo Jun 7, 2023
0e976c9
Actually call decrease three times to cover corner neighbors
spiralhalo Jun 7, 2023
d3a974f
Merge branch '1.20' into light-prism-mini-refactor
spiralhalo Jun 8, 2023
b06e315
Fix light placing and make consistent
spiralhalo Jun 8, 2023
f1370ba
Block light API draft, improve item light fallback
spiralhalo Jun 9, 2023
8106230
Fix fluid occlusion value, refactor
spiralhalo Jun 9, 2023
b130eaa
Make light registry thread safe
spiralhalo Jun 9, 2023
cc30e9d
Whoops
spiralhalo Jun 9, 2023
996468b
Account for state change
spiralhalo Jun 9, 2023
2ae11a1
Keep doing decrease until it's done
spiralhalo Jun 10, 2023
3051e47
Set light level fallback dynamically
spiralhalo Jun 10, 2023
1cc7e37
Add license
spiralhalo Jun 28, 2023
9166f31
Try letting pipeline define light data image
spiralhalo Jun 28, 2023
b346b27
Properly reload regions on pipeline selection
spiralhalo Jun 29, 2023
d66c739
Comment, style, cleanup
spiralhalo Jun 29, 2023
6ea5ea0
Rename "light volume" to "colored lights"
spiralhalo Jun 29, 2023
d7dd044
Add shader API for light volume constants
spiralhalo Jun 29, 2023
4aea58e
Fixed big stupid
spiralhalo Jun 29, 2023
51afa24
Add shader API, consolidate LightOp
spiralhalo Jul 1, 2023
0b02b8c
Light occlusion data complete retrieval, cleanup
spiralhalo Jul 3, 2023
a033f2d
Improve / fix complex light sampling around the edges
spiralhalo Jul 11, 2023
34978e0
Lazy region buffer allocation; test sparse allocator
spiralhalo Jul 12, 2023
9bc0044
Implement working sparse allocation
spiralhalo Jul 12, 2023
9507420
Fix pointer storage remapping and clear more often
spiralhalo Jul 12, 2023
5388f2f
Debug screen light allocation counter
spiralhalo Jul 12, 2023
6058c58
Use uniforms for pointer meta
spiralhalo Jul 22, 2023
56c0835
Deprecate light update extent; use Set-based queue
spiralhalo Jul 22, 2023
cdc0341
Merge pull request #1 from spiralhalo/light-prism-sparse
spiralhalo Jul 22, 2023
967f264
Implement built-in sampler; Demo in abstract pipeline
spiralhalo Jul 22, 2023
bbfea2f
Block Light API defaults/examples
spiralhalo Jul 23, 2023
b5a52f7
Fix erroneous macro usage
spiralhalo Jul 29, 2023
beadb2b
Merge remote-tracking branch 'vram-guild/1.20' into light-prism
spiralhalo Dec 27, 2023
b5cdbf3
Fix emitter re-propagation (I thought I fixed this?)
spiralhalo Dec 27, 2023
eced5f6
Enable/disable colored lights via config and pipeline option
spiralhalo Dec 27, 2023
aa9b355
Prevent light data texture size exceeding hardware limit
spiralhalo Dec 27, 2023
3d2fdef
Try small optimize and add comments about redundancy, fix concurrency…
spiralhalo Dec 28, 2023
9543aaa
Add colored lights update profiler
spiralhalo Dec 28, 2023
364099d
Merge branch '1.20' into light-prism
spiralhalo Dec 28, 2023
927fa38
Employ urgency system based on vanilla
spiralhalo Dec 28, 2023
e7a29aa
Add default light color resources
spiralhalo Dec 28, 2023
453c8b3
Critical: Fix false pointer clearance
spiralhalo Dec 28, 2023
462c059
Try reduce pointer space overlap with more extent padding
spiralhalo Dec 29, 2023
606765f
Robust reload on pipeline state change
spiralhalo Dec 29, 2023
413764d
Mark light region urgency differently, better result
spiralhalo Dec 29, 2023
f2f338c
Fix 1-tick emitter replacement (fire to nether portal)
spiralhalo Dec 31, 2023
eb009dd
Disable colored light filtering "integrity check" by default
spiralhalo Jan 4, 2024
fa8363d
Differentiate shader recompile and full reload in config screen
spiralhalo Jan 4, 2024
96ae964
(cont. from prev commit) Don't reload timekeeper twice
spiralhalo Jan 5, 2024
73ff9a1
Prevent drawing light texture out of bounds
spiralhalo Jan 5, 2024
56c8a63
Merge branch '1.20' into light-prism
spiralhalo Jan 5, 2024
1c120b7
NEW: Implement virtual light system
spiralhalo Jan 6, 2024
bf97937
Implement item-based virtual lighting for entity held light and item …
spiralhalo Jan 7, 2024
cde4831
Fewer mixin approach, turn off local player's virtual light for now
spiralhalo Jan 7, 2024
f5f78da
Entity JSON light loader, refactor CachedBlockLight
spiralhalo Jan 7, 2024
bf67085
Let pipeline disallow virtual lights, more robust reload
spiralhalo Jan 7, 2024
f59115c
Merge branch '1.20' into light-prism
spiralhalo Jan 8, 2024
4afb98b
Clamp item light intensity when converting to block light
spiralhalo Jan 8, 2024
4cae0d2
Merge branch '1.20' into light-prism
spiralhalo Jan 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fabric/src/main/java/io/vram/canvas/CanvasFabricMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.fabricmc.loader.api.FabricLoader;

import grondag.canvas.CanvasMod;
import grondag.canvas.light.color.LightRegistry;
import grondag.canvas.pipeline.config.PipelineLoader;
import grondag.canvas.texture.MaterialIndexProvider;

Expand Down Expand Up @@ -66,6 +67,7 @@ public ResourceLocation getFabricId() {
public void onResourceManagerReload(ResourceManager manager) {
PipelineLoader.reload(manager);
MaterialIndexProvider.reload();
LightRegistry.reload(manager);
}
});
}
Expand Down
1 change: 1 addition & 0 deletions fabric/src/main/resources/mixins.canvas.client.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"MixinBufferUploader",
"MixinChunkRenderDispatcher",
"MixinClientChunkCache",
"MixinClientLevel",
"MixinCompiledChunk",
"MixinCyclingOption",
"MixinDebugScreenOverlay",
Expand Down
1 change: 0 additions & 1 deletion src/main/java/grondag/canvas/CanvasMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
//FEAT: pbr textures
//PERF: disable animated textures when not in view
//PERF: improve light smoothing performance
//FEAT: colored lights
//FEAT: weather uniforms
//FEAT: biome texture in shader

Expand Down
85 changes: 67 additions & 18 deletions src/main/java/grondag/canvas/apiimpl/CanvasState.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

package grondag.canvas.apiimpl;

import java.util.Objects;

import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.language.I18n;

Expand All @@ -30,9 +32,11 @@
import grondag.canvas.apiimpl.rendercontext.CanvasEntityBlockRenderContext;
import grondag.canvas.apiimpl.rendercontext.CanvasItemRenderContext;
import grondag.canvas.config.Configurator;
import grondag.canvas.light.color.LightDataManager;
import grondag.canvas.material.property.TextureMaterialState;
import grondag.canvas.perf.ChunkRebuildCounters;
import grondag.canvas.perf.Timekeeper;
import grondag.canvas.pipeline.Pipeline;
import grondag.canvas.pipeline.PipelineManager;
import grondag.canvas.pipeline.config.PipelineLoader;
import grondag.canvas.shader.GlMaterialProgramManager;
Expand All @@ -45,28 +49,73 @@
import grondag.canvas.terrain.util.ChunkColorCache;

public class CanvasState {
public static void recompileIfNeeded(boolean forceRecompile) {
while (CanvasMod.RECOMPILE.consumeClick()) {
forceRecompile = true;
public static void handleRecompileKeybind() {
final boolean recompilePressed = CanvasMod.RECOMPILE.consumeClick();

while (true) {
// consume all clicks
if (!CanvasMod.RECOMPILE.consumeClick()) {
break;
}
}

if (forceRecompile) {
CanvasMod.LOG.info(I18n.get("info.canvas.recompile"));
PipelineLoader.reload(Minecraft.getInstance().getResourceManager());
PipelineManager.reload();
PreReleaseShaderCompat.reload();
MaterialProgram.reload();
GlShaderManager.INSTANCE.reload();
GlProgramManager.INSTANCE.reload();
GlMaterialProgramManager.INSTANCE.reload();
// LightmapHdTexture.reload();
// LightmapHd.reload();
TextureMaterialState.reload();
ShaderDataManager.reload();
Timekeeper.configOrPipelineReload();
if (recompilePressed) {
recompile(false);
}
}

public static void recompile() {
recompile(false);
}

private static int loopCounter = 0;

private static boolean recompilePipeline() {
final var prev_coloredLightsConfig = Pipeline.config().coloredLights;
final boolean coloredLights_wasDisabled = !Pipeline.coloredLightsEnabled();
final boolean advancedCulling_wasDisabled = !Pipeline.advancedTerrainCulling();

PipelineLoader.reload(Minecraft.getInstance().getResourceManager());
PipelineManager.reload();

final boolean coloredLightsConfigChanged = !Objects.equals(Pipeline.config().coloredLights, prev_coloredLightsConfig);
final boolean coloredLights_requiresRebuild = Pipeline.coloredLightsEnabled() && (coloredLightsConfigChanged || coloredLights_wasDisabled);
final boolean culling_requiresRebuild = Pipeline.advancedTerrainCulling() && advancedCulling_wasDisabled;

return coloredLights_requiresRebuild || culling_requiresRebuild;
}

private static void recompile(boolean wasReloaded) {
CanvasMod.LOG.info(I18n.get("info.canvas.recompile"));

final boolean requireReload = recompilePipeline();

if (!wasReloaded && loopCounter < 2 && requireReload) {
CanvasMod.LOG.info(I18n.get("info.canvas.recompile_needs_reload"));
loopCounter++;
Minecraft.getInstance().levelRenderer.allChanged();
return;
}

LightDataManager.reload(wasReloaded);
PreReleaseShaderCompat.reload();
MaterialProgram.reload();
GlShaderManager.INSTANCE.reload();
GlProgramManager.INSTANCE.reload();
GlMaterialProgramManager.INSTANCE.reload();
// LightmapHdTexture.reload();
// LightmapHd.reload();
TextureMaterialState.reload();
ShaderDataManager.reload();
Timekeeper.configOrPipelineReload();

if (loopCounter > 1) {
CanvasMod.LOG.warn("Reloading recursively twice or more. This isn't supposed to happen.");
}

loopCounter = 0;
}

public static void reload() {
CanvasMod.LOG.info(I18n.get("info.canvas.reloading"));
PackedInputRegion.reload();
Expand All @@ -77,6 +126,6 @@ public static void reload() {
ChunkColorCache.invalidate();
AoFace.clampExteriorVertices(Configurator.clampExteriorVertices);

recompileIfNeeded(true);
recompile(true);
}
}
52 changes: 46 additions & 6 deletions src/main/java/grondag/canvas/config/CanvasConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static grondag.canvas.config.ConfigManager.DEFAULTS;
import static grondag.canvas.config.ConfigManager.Reload.DONT_RELOAD;
import static grondag.canvas.config.ConfigManager.Reload.RELOAD_EVERYTHING;
import static grondag.canvas.config.ConfigManager.Reload.RELOAD_PIPELINE;

import java.util.List;

Expand All @@ -47,6 +48,7 @@

public class CanvasConfigScreen extends BaseScreen {
private boolean reload;
private boolean recompile;
private boolean reloadTimekeeper;
private boolean requiresRestart;

Expand All @@ -59,6 +61,7 @@ public CanvasConfigScreen(Screen parent) {
super(parent, Component.translatable("config.canvas.title"));

reload = false;
recompile = false;
reloadTimekeeper = false;
requiresRestart = false;

Expand Down Expand Up @@ -95,7 +98,7 @@ protected void init() {
list.addItem(optionSession.booleanOption("config.canvas.value.wavy_grass",
() -> editing.wavyGrass,
b -> {
reload |= Configurator.wavyGrass != b;
recompile |= Configurator.wavyGrass != b;
editing.wavyGrass = b;
},
DEFAULTS.wavyGrass,
Expand All @@ -116,6 +119,24 @@ protected void init() {
DEFAULTS.semiFlatLighting,
"config.canvas.help.semi_flat_lighting").listItem());

list.addItem(optionSession.booleanOption("config.canvas.value.colored_lights",
() -> editing.coloredLights,
b -> {
reload |= Configurator.coloredLights != b;
editing.coloredLights = b;
},
DEFAULTS.coloredLights,
"config.canvas.help.colored_lights").listItem());

list.addItem(optionSession.booleanOption("config.canvas.value.entity_light_source",
() -> editing.entityLightSource,
b -> {
reload |= Configurator.entityLightSource != b;
editing.entityLightSource = b;
},
DEFAULTS.entityLightSource,
"config.canvas.help.entity_light_source").listItem());

// TWEAKS
final int indexTweaks = list.addCategory("config.canvas.category.tweaks");

Expand Down Expand Up @@ -332,7 +353,7 @@ protected void init() {
list.addItem(optionSession.booleanOption("config.canvas.value.preprocess_shader_source",
() -> editing.preprocessShaderSource,
b -> {
reload |= Configurator.preprocessShaderSource != b;
recompile |= Configurator.preprocessShaderSource != b;
editing.preprocessShaderSource = b;
},
DEFAULTS.preprocessShaderSource,
Expand Down Expand Up @@ -484,6 +505,15 @@ protected void init() {
DEFAULTS.traceTextureLoad,
"config.canvas.help.trace_texture_load").listItem());

list.addItem(optionSession.booleanOption("config.canvas.value.debug_shader_flag",
() -> editing.debugShaderFlag,
b -> {
recompile |= Configurator.debugShaderFlag != b;
editing.debugShaderFlag = b;
},
DEFAULTS.debugShaderFlag,
"config.canvas.help.debug_shader_flag").listItem());

if (sideW > 0) {
final ListWidget tabs = new ListWidget(1, list.getY(), sideW, list.getHeight(), true);
addRenderableWidget(tabs);
Expand Down Expand Up @@ -514,12 +544,22 @@ private void save() {

Configurator.readFromConfig(editing);

// for now Config reload does reload everything including Timekeeper
if (reloadTimekeeper && !reload) {
Timekeeper.configOrPipelineReload();
final ConfigManager.Reload configReload;

if (reload) {
configReload = RELOAD_EVERYTHING;
} else if (recompile) {
configReload = RELOAD_PIPELINE;
} else {
// the other cases already cover timekeeper reload at the moment.
if (reloadTimekeeper) {
Timekeeper.configOrPipelineReload();
}

configReload = DONT_RELOAD;
}

ConfigManager.saveUserInput(reload ? RELOAD_EVERYTHING : DONT_RELOAD);
ConfigManager.saveCanvasConfig(configReload);

if (requiresRestart) {
this.minecraft.setScreen(new ConfigRestartScreen(this.parent));
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/grondag/canvas/config/ConfigData.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class ConfigData {
//boolean moreLightmap = true;
@Comment("Models with flat lighting have smoother lighting (but no ambient occlusion).")
boolean semiFlatLighting = true;
@Comment("Enable colored block lights on pipelines that support it. Replaces vanilla lighting but only visually.")
boolean coloredLights = false;
@Comment("Enable entity as dynamic light sources. Requires colored lights and supporting pipeline.")
boolean entityLightSource = false;

// TWEAKS
@Comment("Adjusts quads on some vanilla models (like iron bars) to avoid z-fighting with neighbor blocks.")
Expand Down Expand Up @@ -151,6 +155,8 @@ class ConfigData {
boolean debugSpriteAtlas = false;
@Comment("Log significant events of texture/sprite atlas loading. For debugging use. Will spam the log.")
boolean traceTextureLoad = false;
@Comment("Enables debug flag in the shader. Only intended for internal Canvas development purposes.")
boolean debugShaderFlag = false;

// GSON doesn't do this automatically
public void clearNulls() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/grondag/canvas/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static void savePipelineOptions(OptionConfig[] options) {
CanvasMod.LOG.error("Error loading pipeline config. Using default values.");
}

CanvasState.recompileIfNeeded(true);
CanvasState.recompile();
}

private static void saveConfig() {
Expand Down Expand Up @@ -163,12 +163,12 @@ static void loadConfig() {
Configurator.readFromConfig(config, true);
}

static void saveUserInput(Reload reload) {
static void saveCanvasConfig(Reload reload) {
saveConfig();

switch (reload) {
case RELOAD_EVERYTHING -> Minecraft.getInstance().levelRenderer.allChanged();
case RELOAD_PIPELINE -> CanvasState.recompileIfNeeded(true);
case RELOAD_PIPELINE -> CanvasState.recompile();
case DONT_RELOAD -> { }
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/grondag/canvas/config/Configurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class Configurator {
//public static boolean moreLightmap = DEFAULTS.moreLightmap;
//public static int maxLightmapDelayFrames = DEFAULTS.maxLightmapDelayFrames;
public static boolean semiFlatLighting = DEFAULTS.semiFlatLighting;
public static boolean coloredLights = DEFAULTS.coloredLights;
public static boolean entityLightSource = DEFAULTS.entityLightSource;

public static boolean preventDepthFighting = DEFAULTS.preventDepthFighting;
public static boolean clampExteriorVertices = DEFAULTS.clampExteriorVertices;
Expand Down Expand Up @@ -95,6 +97,7 @@ public class Configurator {
public static boolean cullBackfacingTerrain = DEFAULTS.cullBackfacingTerrain;
public static boolean debugSpriteAtlas = DEFAULTS.debugSpriteAtlas;
public static boolean traceTextureLoad = DEFAULTS.traceTextureLoad;
public static boolean debugShaderFlag = DEFAULTS.debugShaderFlag;

// @LangKey("config.acuity_fancy_fluids")
// @Comment({"Enable fancy water and lava rendering.",
Expand Down Expand Up @@ -136,6 +139,8 @@ static void readFromConfig(ConfigData config, boolean isStartup) {
// lightmapNoise = config.lightmapNoise;
lightSmoothing = config.lightSmoothing;
semiFlatLighting = config.semiFlatLighting;
coloredLights = config.coloredLights;
entityLightSource = config.entityLightSource;

// disableVanillaChunkMatrix = config.disableVanillaChunkMatrix;
preventDepthFighting = config.preventDepthFighting;
Expand Down Expand Up @@ -185,6 +190,7 @@ static void readFromConfig(ConfigData config, boolean isStartup) {
cullBackfacingTerrain = config.cullBackfacingTerrain;
debugSpriteAtlas = config.debugSpriteAtlas;
traceTextureLoad = config.traceTextureLoad;
debugShaderFlag = config.debugShaderFlag;
}

static void writeToConfig(ConfigData config) {
Expand All @@ -202,6 +208,8 @@ static void writeToConfig(ConfigData config) {
config.lightSmoothing = lightSmoothing;
//config.moreLightmap = moreLightmap;
config.semiFlatLighting = semiFlatLighting;
config.coloredLights = coloredLights;
config.entityLightSource = entityLightSource;

config.preventDepthFighting = preventDepthFighting;
config.clampExteriorVertices = clampExteriorVertices;
Expand Down Expand Up @@ -250,5 +258,6 @@ static void writeToConfig(ConfigData config) {
config.cullBackfacingTerrain = cullBackfacingTerrain;
config.debugSpriteAtlas = debugSpriteAtlas;
config.traceTextureLoad = traceTextureLoad;
config.debugShaderFlag = debugShaderFlag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

package grondag.canvas.config;

import static grondag.canvas.config.ConfigManager.Reload.RELOAD_EVERYTHING;
import static grondag.canvas.config.ConfigManager.Reload.RELOAD_PIPELINE;

import java.util.List;
Expand Down Expand Up @@ -118,8 +117,7 @@ protected void init() {

private void savePipelineSelection(ResourceLocation newPipelineId) {
Configurator.pipelineId = newPipelineId.toString();
// When advanced terrain culling is *soft* disabled, better clear the region storage
ConfigManager.saveUserInput(Configurator.advancedTerrainCulling ? RELOAD_PIPELINE : RELOAD_EVERYTHING);
ConfigManager.saveCanvasConfig(RELOAD_PIPELINE);
}

private void save() {
Expand Down
Loading