Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
55 changes: 55 additions & 0 deletions fission/src/systems/preferences/PreferenceTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,61 @@ export function defaultGraphicsPreferences(): GraphicsPreferences {
}
}

export function mediumGraphicsPreferences(): GraphicsPreferences {
return {
lightIntensity: 5,
fancyShadows: false,
maxFar: 30,
cascades: 4,
shadowMapSize: 4096,
antiAliasing: false,
}
}

export function highGraphicsPreferences(): GraphicsPreferences {
return {
lightIntensity: 5,
fancyShadows: true,
maxFar: 30,
cascades: 4,
shadowMapSize: 4096,
antiAliasing: true,
}
}

export function veryHighGraphicsPreferences(): GraphicsPreferences {
return {
lightIntensity: 6,
fancyShadows: true,
maxFar: 50,
cascades: 4,
shadowMapSize: 4096,
antiAliasing: true,
}
}

export function lowGraphicsPreferences(): GraphicsPreferences {
return {
lightIntensity: 3,
fancyShadows: false,
maxFar: 20,
cascades: 2,
shadowMapSize: 2048,
antiAliasing: false,
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be wrong but I'm pretty sure light intensity doesn't change performance, it's just like a brightness setting. And (assuming the UI is done correctly) the shadow-related properties are ignored when fancy shadows are off, making low graphics just like medium graphics performance-wise but darker. Maybe remove low and shift the other ones so medium is low, high is medium (default), etc?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also another note, there are differences in maxFar, cascades, shadowMapSize - all of which actually do not make a difference when fancyShadows is set to false. So, there is pretty much no quality difference between the two

}

export function ultraGraphicsPreferences(): GraphicsPreferences {
return {
lightIntensity: 7,
fancyShadows: true,
maxFar: 100,
cascades: 6,
shadowMapSize: 8192,
antiAliasing: true,
}
}

export type IntakePreferences = {
deltaTransformation: number[]
zoneDiameter: number
Expand Down
5 changes: 5 additions & 0 deletions fission/src/systems/preferences/PreferencesSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ class PreferencesSystem {
this.savePreferences()
}

public static setGraphicsPreferences(g: GraphicsPreferences) {
this._preferences[GRAPHICS_PREFERENCE_KEY] = g
this.savePreferences()
}

/** Loads all preferences from local storage. */
public static loadPreferences() {
const loadedPrefs = window.localStorage.getItem(this._localStorageKey)
Expand Down
7 changes: 6 additions & 1 deletion fission/src/ui/components/StatefulSlider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Slider, Stack, Tooltip, Typography } from "@mui/material"
import Label from "./Label"
import { useState } from "react"
import { useEffect, useState } from "react"

const StatefulSlider: React.FC<
Omit<Parameters<typeof Slider>[0], "value" | "onChange"> & {
Expand All @@ -12,6 +12,11 @@ const StatefulSlider: React.FC<
}
> = props => {
const [value, setValue] = useState(props.defaultValue)

useEffect(() => {
setValue(props.defaultValue)
}, [props.defaultValue])
Comment thread
RoushilS marked this conversation as resolved.

return (
<Tooltip title={props.tooltip ?? ""}>
<Stack
Expand Down
112 changes: 92 additions & 20 deletions fission/src/ui/modals/configuring/SettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ import { useThemeContext } from "@/ui/helpers/ThemeProviderHelpers"
import { useUIContext } from "@/ui/helpers/UIProviderHelpers"
import { randomColor } from "@/util/Random"
import CommandRegistry from "@/ui/components/CommandRegistry"
import {
mediumGraphicsPreferences,
lowGraphicsPreferences,
highGraphicsPreferences,
veryHighGraphicsPreferences,
ultraGraphicsPreferences,
type GraphicsPreferences,
} from "@/systems/preferences/PreferenceTypes"
import { Select, MenuItem } from "@mui/material"

// Register command: Open Settings (module-scope side effect)
CommandRegistry.get().registerCommand({
Expand Down Expand Up @@ -209,6 +218,7 @@ const GeneralTab: React.FC<GeneralTabProps> = ({ writePreference }) => (

const GraphicsTab: React.FC<GraphicsTabProps> = ({ onActionsChange }) => {
const [reload, setReload] = useState<boolean>(false)
const [selectedPreset, setSelectedPreset] = useState<string>("medium")
const [lightIntensity, setLightIntensity] = useState<number>(
PreferencesSystem.getGraphicsPreferences().lightIntensity
)
Expand All @@ -218,6 +228,43 @@ const GraphicsTab: React.FC<GraphicsTabProps> = ({ onActionsChange }) => {
const [shadowMapSize, setShadowMapSize] = useState<number>(PreferencesSystem.getGraphicsPreferences().shadowMapSize)
const [antiAliasing, setAntiAliasing] = useState<boolean>(PreferencesSystem.getGraphicsPreferences().antiAliasing)

const applyGraphicsPreferencesLocally = (prefs: ReturnType<typeof PreferencesSystem.getGraphicsPreferences>) => {
setLightIntensity(prefs.lightIntensity)
setFancyShadows(prefs.fancyShadows)
setMaxFar(prefs.maxFar)
setCascades(prefs.cascades)
setShadowMapSize(prefs.shadowMapSize)
setAntiAliasing(prefs.antiAliasing)
World.sceneRenderer.changeLighting(prefs.fancyShadows)
}

useEffect(() => {
const current = PreferencesSystem.getGraphicsPreferences()

const presetMatches = (preset: GraphicsPreferences) => {
return (
current.lightIntensity === preset.lightIntensity &&
current.fancyShadows === preset.fancyShadows &&
current.maxFar === preset.maxFar &&
current.cascades === preset.cascades &&
current.shadowMapSize === preset.shadowMapSize &&
current.antiAliasing === preset.antiAliasing
)
}

if (presetMatches(lowGraphicsPreferences())) {
setSelectedPreset("low")
} else if (presetMatches(mediumGraphicsPreferences())) {
setSelectedPreset("medium")
} else if (presetMatches(highGraphicsPreferences())) {
setSelectedPreset("high")
} else if (presetMatches(veryHighGraphicsPreferences())) {
setSelectedPreset("veryHigh")
} else if (presetMatches(ultraGraphicsPreferences())) {
setSelectedPreset("ultra")
}
Comment thread
RoushilS marked this conversation as resolved.
Outdated
}, [])

// Create actions object and notify parent
useEffect(() => {
const actions: GraphicsTabActions = {
Expand Down Expand Up @@ -250,6 +297,28 @@ const GraphicsTab: React.FC<GraphicsTabProps> = ({ onActionsChange }) => {
setAntiAliasing(g.antiAliasing)
setReload(false)
World.sceneRenderer.changeLighting(g.fancyShadows)
const presetMatches = (preset: GraphicsPreferences) => {
return (
g.lightIntensity === preset.lightIntensity &&
g.fancyShadows === preset.fancyShadows &&
g.maxFar === preset.maxFar &&
g.cascades === preset.cascades &&
g.shadowMapSize === preset.shadowMapSize &&
g.antiAliasing === preset.antiAliasing
)
}

if (presetMatches(lowGraphicsPreferences())) {
setSelectedPreset("low")
} else if (presetMatches(mediumGraphicsPreferences())) {
setSelectedPreset("medium")
} else if (presetMatches(highGraphicsPreferences())) {
setSelectedPreset("high")
} else if (presetMatches(veryHighGraphicsPreferences())) {
setSelectedPreset("veryHigh")
} else if (presetMatches(ultraGraphicsPreferences())) {
setSelectedPreset("ultra")
}
},
requiresReload: reload,
}
Expand All @@ -258,6 +327,29 @@ const GraphicsTab: React.FC<GraphicsTabProps> = ({ onActionsChange }) => {

return (
<Stack gap={2}>
<Label size="md">Graphics Presets</Label>
<Select
value={selectedPreset}
onChange={e => {
const preset = e.target.value
setSelectedPreset(preset)
if (preset === "low") applyGraphicsPreferencesLocally(lowGraphicsPreferences())
else if (preset === "medium") applyGraphicsPreferencesLocally(mediumGraphicsPreferences())
else if (preset === "high") applyGraphicsPreferencesLocally(highGraphicsPreferences())
else if (preset === "veryHigh") applyGraphicsPreferencesLocally(veryHighGraphicsPreferences())
else if (preset === "ultra") applyGraphicsPreferencesLocally(ultraGraphicsPreferences())
}}
sx={{ width: "100%" }}
>
<MenuItem value="low">Low Graphics</MenuItem>
<MenuItem value="medium">Medium Graphics (Default)</MenuItem>
<MenuItem value="high">High Graphics</MenuItem>
<MenuItem value="veryHigh">Very High Graphics</MenuItem>
<MenuItem value="ultra">Ultra Graphics</MenuItem>
</Select>

<Label size="md">Customize Graphics</Label>

<StatefulSlider
label="Light Intensity"
min={MIN_LIGHT_INTENSITY}
Expand Down Expand Up @@ -334,26 +426,6 @@ const GraphicsTab: React.FC<GraphicsTabProps> = ({ onActionsChange }) => {
}}
step={1024}
/>
<Box alignSelf="center">
<Button
onClick={() => {
setShadowMapSize(4096)
setMaxFar(30)
setLightIntensity(5)
setCascades(4)
World.sceneRenderer.changeCSMSettings({
shadowMapSize: 4096,
maxFar: 30,
lightIntensity: 5,
fancyShadows,
cascades: 4,
antiAliasing,
})
}}
>
Reset Default
</Button>
</Box>
</>
)}
<Checkbox
Expand Down
Loading