Added dithering magnitude as a config option

This commit is contained in:
Lucas Dower 2023-03-27 18:08:38 +01:00
parent 89229e4a2a
commit d7614fc597
No known key found for this signature in database
GPG Key ID: B3EE6B8499593605
7 changed files with 25 additions and 8 deletions

View File

@ -223,6 +223,7 @@ export class AppContext {
textureAtlas: components.textureAtlas.getValue(),
blockPalette: components.blockPalette.getValue().getBlocks(),
dithering: components.dithering.getValue(),
ditheringMagnitude: components.ditheringMagnitude.getValue(),
colourSpace: ColourSpace.RGB,
fallable: components.fallable.getValue() as FallableBehaviour,
resolution: Math.pow(2, components.colourAccuracy.getValue()),

View File

@ -83,11 +83,11 @@ export class BlockMesh {
break;
}
case 'random': {
Ditherer.ditherRandom(ditheredColour);
Ditherer.ditherRandom(ditheredColour, blockMeshParams.ditheringMagnitude);
break;
}
case 'ordered': {
Ditherer.ditherOrdered(ditheredColour, voxel.position);
Ditherer.ditherOrdered(ditheredColour, voxel.position, blockMeshParams.ditheringMagnitude);
break;
}
}

View File

@ -30,7 +30,6 @@ export class AppConfig {
public readonly CAMERA_SENSITIVITY_ROTATION = 0.005;
public readonly CAMERA_SENSITIVITY_ZOOM = 0.005;
public readonly CONSTRAINT_MAXIMUM_HEIGHT = 380;
public readonly DITHER_MAGNITUDE = 32;
public readonly SMOOTHNESS_MAX = 3.0;
public readonly CAMERA_SMOOTHING = 1.0;
public readonly VIEWPORT_BACKGROUND_COLOUR: RGBA = {

View File

@ -4,22 +4,22 @@ import { ASSERT } from './util/error_util';
import { Vector3 } from './vector';
export class Ditherer {
public static ditherRandom(colour: RGBA_255) {
const offset = (Math.random() - 0.5) * AppConfig.Get.DITHER_MAGNITUDE;
public static ditherRandom(colour: RGBA_255, magnitude: number) {
const offset = (Math.random() - 0.5) * magnitude;
colour.r += offset;
colour.g += offset;
colour.b += offset;
}
public static ditherOrdered(colour: RGBA_255, position: Vector3) {
public static ditherOrdered(colour: RGBA_255, position: Vector3, magnitude: number) {
const map = this._getThresholdValue(
Math.abs(position.x % 4),
Math.abs(position.y % 4),
Math.abs(position.z % 4),
);
const offset = map * AppConfig.Get.DITHER_MAGNITUDE;
const offset = map * magnitude;
colour.r += offset;
colour.g += offset;

View File

@ -175,7 +175,21 @@ export class UI {
displayText: 'Off',
payload: 'off',
}])
.setLabel('Dithering'),
.setLabel('Dithering')
.addEnabledChangedListener((isEnabled) => {
this._ui.assign.components.ditheringMagnitude.setEnabled(isEnabled && this._ui.assign.components.dithering.getValue() !== 'off', false);
})
.addValueChangedListener((newValue: TDithering) => {
this._ui.assign.components.ditheringMagnitude.setEnabled(newValue !== 'off', false);
}),
'ditheringMagnitude': new SliderComponent()
.setMin(1)
.setMax(64)
.setDefaultValue(32)
.setDecimals(0)
.setStep(1)
.setLabel('Dithering magnitude')
.setShouldObeyGroupEnables(false),
'fallable': new ComboboxComponent<FallableBehaviour>()
.addItems([{
displayText: 'Replace falling with solid',
@ -238,6 +252,7 @@ export class UI {
'textureAtlas',
'blockPalette',
'dithering',
'ditheringMagnitude',
'fallable',
'colourAccuracy',
'contextualAveraging',

View File

@ -109,6 +109,7 @@ export namespace AssignParams {
textureAtlas: TAtlasId,
blockPalette: string[],
dithering: TDithering,
ditheringMagnitude: number,
colourSpace: ColourSpace,
fallable: FallableBehaviour,
resolution: RGBAUtil.TColourAccuracy,

View File

@ -20,6 +20,7 @@ export const headlessConfig: THeadlessConfig = {
textureAtlas: 'vanilla', // Must be an atlas name that exists in /resources/atlases
blockPalette: PALETTE_ALL_RELEASE, // Must be a palette name that exists in /resources/palettes
dithering: 'ordered',
ditheringMagnitude: 32,
colourSpace: ColourSpace.RGB,
fallable: 'replace-falling',
resolution: 32,