Skip to content

Commit

Permalink
Handheld light configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
grondag committed Nov 18, 2020
1 parent 1f21a5d commit d01331d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/main/java/grondag/canvas/Configurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class Configurator {
public static float bloomIntensity = DEFAULTS.bloomIntensity;
public static float bloomScale = DEFAULTS.bloomScale;
public static boolean wavyGrass = DEFAULTS.wavyGrass;
public static int handheldLightRadius = DEFAULTS.handheldLightRadius;
public static boolean lightmapNoise = DEFAULTS.lightmapNoise;
public static DiffuseMode diffuseShadingMode = DEFAULTS.diffuseShadingMode;
public static boolean lightSmoothing = DEFAULTS.lightSmoothing;
Expand Down Expand Up @@ -135,6 +136,7 @@ private static void loadConfig() {
bloomIntensity = config.bloomIntensity;
bloomScale = config.bloomScale;
wavyGrass = config.wavyGrass;
handheldLightRadius = config.handheldLightRadius;

shaderDebug = config.shaderDebug;
maxLightmapDelayFrames = config.maxLightmapDelayFrames;
Expand Down Expand Up @@ -183,6 +185,7 @@ private static void saveConfig() {
config.bloomIntensity = bloomIntensity;
config.bloomScale = bloomScale;
config.wavyGrass = wavyGrass;
config.handheldLightRadius = handheldLightRadius;

config.shaderDebug = shaderDebug;
config.maxLightmapDelayFrames = maxLightmapDelayFrames;
Expand Down Expand Up @@ -321,6 +324,18 @@ public static Screen display(Screen screen) {
})
.build());

features.addEntry(ENTRY_BUILDER
.startIntSlider(new TranslatableText("config.canvas.value.handheld_light_radius"), handheldLightRadius, 0, 15)
.setDefaultValue(DEFAULTS.handheldLightRadius)
.setMax(15)
.setMin(0)
.setTooltip(parse("config.canvas.help.handheld_light_radius"))
.setSaveConsumer(b -> {
reload |= handheldLightRadius != b;
handheldLightRadius = b;
})
.build());

// LIGHTING
final ConfigCategory lighting = builder.getOrCreateCategory(new TranslatableText("config.canvas.category.lighting"));

Expand Down Expand Up @@ -661,6 +676,8 @@ static class ConfigData {
public float bloomScale = 0.25f;
@Comment("Animated foliage")
public boolean wavyGrass = true;
@Comment("Hand held light max radius. 0-15, Zero disables")
public int handheldLightRadius = 12;
@Comment("Enable rendering of internal buffers for debug purposes. Off by default to prevent accidental activation.")
public boolean enableBufferDebug = false;
@Comment("Output load/reload trace data to log. Will have performance impact.")
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/grondag/canvas/shader/GlShader.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ private String getSource() {
result = StringUtils.replace(result, "#define TARGET_EMISSIVE -1", "#define TARGET_EMISSIVE 1");
}

result = StringUtils.replace(result, "#define HANDHELD_LIGHT_RADIUS 0", "#define HANDHELD_LIGHT_RADIUS " + Configurator.handheldLightRadius);

if (Configurator.hdLightmaps()) {
result = StringUtils.replace(result, "#define VANILLA_LIGHTING", "//#define VANILLA_LIGHTING");

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/canvas/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"config.canvas.help.bloom_scale": "Size of bloom effect around light sources.",
"config.canvas.value.wavy_grass": "Animated Foliage",
"config.canvas.help.wavy_grass": "Activates shaders for waving grass, leaves, etc.",
"config.canvas.value.handheld_light_radius": "Handheld Light Radius",
"config.canvas.help.handheld_light_radius": "Max reach for hand-held lights. Zero disables.",
"config.canvas.category.lighting": "Lighting",
"config.canvas.value.light_smoothing": "Light Smoothing",
"config.canvas.help.light_smoothing": "Makes light sources less cross-shaped.;Chunk loading a little slower.;Overall light levels remain similar.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@

#define TARGET_BASECOLOR 0
#define TARGET_EMISSIVE -1

#define HANDHELD_LIGHT_RADIUS 0
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ vec4 light(frx_FragmentData fragData) {
result = texture2D(frxs_lightmap, fragData.light);
#endif

#if HANDHELD_LIGHT_RADIUS != 0
vec4 held = frx_heldLight();

if (held.w > 0.0 && !frx_isGui()) {
float d = clamp(gl_FogFragCoord / (held.w * 12.0), 0.0, 1.0);
float d = clamp(gl_FogFragCoord / (held.w * HANDHELD_LIGHT_RADIUS), 0.0, 1.0);
d = 1.0 - d * d;

vec4 maxBlock = texture2D(frxs_lightmap, vec2(0.96875, 0.03125));
Expand All @@ -76,6 +77,7 @@ vec4 light(frx_FragmentData fragData) {

result = min(result + held, 1.0);
}
#endif

return result;
}
Expand Down

0 comments on commit d01331d

Please sign in to comment.