Skip to content

Commit

Permalink
merge: optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
chase-moskal committed May 11, 2024
2 parents 161bdac + 3983115 commit abea4fd
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 25 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"dependencies": {
"@benev/slate": "^0.1.2",
"@benev/toolbox": "^0.6.0-8",
"@benev/toolbox": "^0.6.0-9",
"@dimforge/rapier3d": "^0.13.1",
"@dimforge/rapier3d-compat": "^0.13.1",
"es-module-shims": "^1.10.0",
Expand All @@ -49,7 +49,7 @@
"importly": "^0.2.3",
"mkdirp": "^3.0.1",
"npm-run-all": "^4.1.5",
"rimraf": "^5.0.5",
"rimraf": "^5.0.6",
"rollup": "^4.17.2",
"terser": "^5.31.0",
"typescript": "^5.4.5"
Expand Down
32 changes: 27 additions & 5 deletions s/models/levels/levels/viking_village.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

import {clone, debounce, reactor} from "@benev/slate"
import {clone, debounce, nap, reactor} from "@benev/slate"
import {Material} from "@babylonjs/core/Materials/material.js"
import {AbstractMesh} from "@babylonjs/core/Meshes/abstractMesh.js"
import {DirectionalLight} from "@babylonjs/core/Lights/directionalLight.js"

import {Ui} from "../../ui/ui.js"
Expand All @@ -12,9 +14,7 @@ export default levelScript(async(realm, stuff) => {
const {quality} = realm.gameplan

const sunlight = stuff.level.lights[0] as DirectionalLight

const shadows = setup_shadows(realm, stuff, sunlight)

let particleFog: ReturnType<typeof setup_fog> | null = null

const applyFogSettings = debounce(100, (data: Ui["particleFog"]) => {
Expand Down Expand Up @@ -46,15 +46,37 @@ export default levelScript(async(realm, stuff) => {
)

if (quality === "potato") bestorage.json = `
{"resolution":50,"effects":{"image":{"contrast":1.85,"exposure":1},"tonemapping":{"operator":"Photographic"},"vignette":{"color":[0,0,0],"weight":3.68,"stretch":1,"multiply":true},"scene":{"clearColor":[0.1,0.1,0.1],"ambientColor":[0,0,0],"shadowsEnabled":false,"environmentIntensity":0.38,"forceWireframe":false,"forceShowBoundingBoxes":false,"disableGammaTransform":false}},"shadows":{"basics":{"filter":0,"filteringQuality":2,"sunDistance":100,"grass_receives_shadows":true,"grass_casts_shadows":false},"light":{"intensity":7.6,"autoUpdateExtends":false,"autoCalcShadowZBounds":false,"shadowOrthoScale":0.1,"shadowFrustumSize":0,"shadowMinZ":10,"shadowMaxZ":500},"generator":{"enableSoftTransparentShadow":false,"useKernelBlur":false,"forceBackFacesOnly":false,"mapSize":1024,"blurScale":2,"blurKernel":1,"blurBoxOffset":1,"contactHardeningLightSizeUVRatio":0.1,"bias":0.00005,"darkness":0,"depthScale":50,"frustumEdgeFalloff":0},"cascaded":{"enabled":false,"debug":false,"stabilizeCascades":false,"autoCalcDepthBounds":true,"freezeShadowCastersBoundingInfo":true,"numCascades":4,"lambda":0.5,"cascadeBlendPercentage":0.05,"penumbraDarkness":1,"shadowMinZ":0.1,"shadowMaxZ":500}},"particleFog":{"enabled":true,"color1":[0.7058823529411765,0.8156862745098039,0.9921568627450981],"color2":[0.4549019607843137,0.596078431372549,0.7058823529411765],"alpha":0.128,"count":500,"spinrate":0.39}}
{"resolution":50,"effects":{"image":{"contrast":1.85,"exposure":1},"tonemapping":{"operator":"Photographic"},"vignette":{"color":[0,0,0],"weight":3.68,"stretch":1,"multiply":true},"scene":{"clearColor":[0.1,0.1,0.1],"ambientColor":[0,0,0],"shadowsEnabled":false,"environmentIntensity":0.38,"forceWireframe":false,"forceShowBoundingBoxes":false,"useOrderIndependentTransparency":false}},"shadows":{"basics":{"filter":0,"filteringQuality":2,"sunDistance":100,"grass_receives_shadows":true,"grass_casts_shadows":false},"light":{"intensity":7.6,"autoUpdateExtends":false,"autoCalcShadowZBounds":false,"shadowOrthoScale":0.1,"shadowFrustumSize":0,"shadowMinZ":10,"shadowMaxZ":500},"generator":{"enableSoftTransparentShadow":false,"useKernelBlur":false,"forceBackFacesOnly":false,"mapSize":1024,"blurScale":2,"blurKernel":1,"blurBoxOffset":1,"contactHardeningLightSizeUVRatio":0.1,"bias":0.00005,"darkness":0,"depthScale":50,"frustumEdgeFalloff":0},"cascaded":{"enabled":false,"debug":false,"stabilizeCascades":false,"autoCalcDepthBounds":true,"freezeShadowCastersBoundingInfo":true,"numCascades":4,"lambda":0.5,"cascadeBlendPercentage":0.05,"penumbraDarkness":1,"shadowMinZ":0.1,"shadowMaxZ":500}},"particleFog":{"enabled":true,"color1":[0.7058823529411765,0.8156862745098039,0.9921568627450981],"color2":[0.4549019607843137,0.596078431372549,0.7058823529411765],"alpha":0.128,"count":500,"spinrate":0.39}}
`

else if (quality === "mid") bestorage.json = `
{"resolution":100,"effects":{"image":{"contrast":1.82,"exposure":1},"tonemapping":{"operator":"Photographic"},"vignette":{"color":[0,0,0],"weight":3.11,"stretch":1,"multiply":true},"antialiasing":{"samples":8,"fxaa":true},"bloom":{"weight":0.48,"scale":0.57,"kernel":392,"threshold":0.178},"scene":{"clearColor":[0.1,0.1,0.1],"ambientColor":[0,0,0],"shadowsEnabled":true,"environmentIntensity":0.39,"forceWireframe":false,"forceShowBoundingBoxes":false,"disableGammaTransform":false}},"shadows":{"basics":{"filter":7,"filteringQuality":0,"sunDistance":100,"grass_receives_shadows":true,"grass_casts_shadows":false},"light":{"intensity":6.4,"autoUpdateExtends":false,"autoCalcShadowZBounds":false,"shadowOrthoScale":0.122,"shadowFrustumSize":0,"shadowMinZ":20,"shadowMaxZ":1000},"generator":{"enableSoftTransparentShadow":false,"useKernelBlur":false,"forceBackFacesOnly":false,"mapSize":2048,"blurScale":0,"blurKernel":0,"blurBoxOffset":0,"contactHardeningLightSizeUVRatio":0.38,"bias":0.00018,"darkness":0,"depthScale":0,"frustumEdgeFalloff":0},"cascaded":{"enabled":true,"debug":false,"stabilizeCascades":false,"autoCalcDepthBounds":false,"freezeShadowCastersBoundingInfo":true,"numCascades":4,"lambda":0.94,"cascadeBlendPercentage":0,"penumbraDarkness":0,"shadowMinZ":0,"shadowMaxZ":185}},"particleFog":{"enabled":true,"color1":[0.7058823529411765,0.8156862745098039,0.9921568627450981],"color2":[0.4549019607843137,0.596078431372549,0.7058823529411765],"alpha":0.031,"count":5000,"spinrate":1.28}}
{"resolution":100,"effects":{"image":{"contrast":1.82,"exposure":1},"tonemapping":{"operator":"Photographic"},"vignette":{"color":[0,0,0],"weight":3.11,"stretch":1,"multiply":true},"antialiasing":{"samples":8,"fxaa":true},"bloom":{"weight":0.48,"scale":0.57,"kernel":392,"threshold":0.178},"scene":{"clearColor":[0.1,0.1,0.1],"ambientColor":[0,0,0],"shadowsEnabled":true,"environmentIntensity":0.39,"forceWireframe":false,"forceShowBoundingBoxes":false,"useOrderIndependentTransparency":false}},"shadows":{"basics":{"filter":7,"filteringQuality":1,"sunDistance":100,"grass_receives_shadows":true,"grass_casts_shadows":false},"light":{"intensity":6.4,"autoUpdateExtends":false,"autoCalcShadowZBounds":false,"shadowOrthoScale":0.122,"shadowFrustumSize":0,"shadowMinZ":0,"shadowMaxZ":200},"generator":{"enableSoftTransparentShadow":false,"useKernelBlur":false,"forceBackFacesOnly":true,"mapSize":2048,"blurScale":0,"blurKernel":0,"blurBoxOffset":0,"contactHardeningLightSizeUVRatio":0.11,"bias":0.000729,"darkness":0,"depthScale":0,"frustumEdgeFalloff":0},"cascaded":{"enabled":false,"debug":false,"stabilizeCascades":false,"autoCalcDepthBounds":false,"freezeShadowCastersBoundingInfo":true,"numCascades":4,"lambda":0.94,"cascadeBlendPercentage":0,"penumbraDarkness":0,"shadowMinZ":0,"shadowMaxZ":185}},"particleFog":{"enabled":true,"color1":[0.7058823529411765,0.8156862745098039,0.9921568627450981],"color2":[0.4549019607843137,0.596078431372549,0.7058823529411765],"alpha":0.031,"count":5000,"spinrate":1.28}}
`

else bestorage.json = `
{"resolution":100,"effects":{"image":{"contrast":1.82,"exposure":1},"tonemapping":{"operator":"Photographic"},"vignette":{"color":[0,0,0],"weight":3.69,"stretch":1,"multiply":true},"antialiasing":{"samples":8,"fxaa":true},"bloom":{"weight":0.1,"scale":0.57,"kernel":216,"threshold":0.797},"scene":{"clearColor":[0.1,0.1,0.1],"ambientColor":[0,0,0],"shadowsEnabled":true,"environmentIntensity":0.39,"forceWireframe":false,"forceShowBoundingBoxes":false,"disableGammaTransform":false}},"shadows":{"basics":{"filter":7,"filteringQuality":0,"sunDistance":100,"grass_receives_shadows":true,"grass_casts_shadows":true},"light":{"intensity":7.6,"autoUpdateExtends":false,"autoCalcShadowZBounds":false,"shadowOrthoScale":0.116,"shadowFrustumSize":0,"shadowMinZ":0,"shadowMaxZ":210},"generator":{"enableSoftTransparentShadow":false,"useKernelBlur":false,"forceBackFacesOnly":true,"mapSize":4096,"blurScale":1.71,"blurKernel":1.69,"blurBoxOffset":0.94,"contactHardeningLightSizeUVRatio":1.17,"bias":0.000116,"darkness":0,"depthScale":47.1,"frustumEdgeFalloff":0},"cascaded":{"enabled":true,"debug":false,"stabilizeCascades":true,"autoCalcDepthBounds":false,"freezeShadowCastersBoundingInfo":false,"numCascades":4,"lambda":0.91,"cascadeBlendPercentage":0,"penumbraDarkness":0,"shadowMinZ":0,"shadowMaxZ":85}},"particleFog":{"enabled":true,"color1":[0.7058823529411765,0.8156862745098039,0.9921568627450981],"color2":[0.4549019607843137,0.596078431372549,0.7058823529411765],"alpha":0.031,"count":5000,"spinrate":1.28}}
`

// reduce startup lag, and freeze meshes and materials
{
const materials = new Map<Material, AbstractMesh>()

for (const mesh of stuff.level.meshes) {
mesh.freezeWorldMatrix()
if (mesh.material)
materials.set(mesh.material, mesh)
}

await Promise.all(
[...materials].map(
async([material, mesh]) => {
await material.forceCompilationAsync(mesh)
material.freeze()
}
)
)
}

return {dispose: () => {
shadows.dispose()
stop1()
Expand Down
10 changes: 2 additions & 8 deletions s/models/realm/realm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import {clone, reactor} from "@benev/slate"
import {ScenePerformancePriority} from "@babylonjs/core/scene.js"
import {Bestorage, Stage, assignSelectively, debug_colors, defaultEffectsData} from "@benev/toolbox"

import {Ui} from "../ui/ui.js"
Expand All @@ -11,6 +10,7 @@ import {HuGameplan} from "../../gameplan.js"
import {CommitHash} from "../../tools/commit_hash.js"
import {ShadowManager} from "./parts/shadow-manager.js"
import {LoadingDock} from "../planning/loading_dock.js"
import {optimize_scene} from "../../tools/optimize_scene.js"
import {standard_glb_post_process} from "../glb/standard_glb_post_process.js"

export type RealmParams = {
Expand Down Expand Up @@ -70,8 +70,8 @@ export async function makeRealm(params: RealmParams) {
})

const {scene} = stage
scene.performancePriority = ScenePerformancePriority.BackwardCompatible

optimize_scene(scene)
const loadingDock = new LoadingDock(scene, commit)
const tact = new HuTact()
const colors = debug_colors(scene)
Expand All @@ -81,12 +81,6 @@ export async function makeRealm(params: RealmParams) {
// before it's copied to the scene.
loadingDock.glb_post_process = standard_glb_post_process({gameplan, loadingDock})

// // hack specular fix on node material shaders
// loadingDock.shader_post_process = async shader => {
// if (shader.pbr)
// shader.pbr.specularIntensity = 0.2
// }

const characterContainer = await loadingDock.loadGlb(
gameplan.characters.pimsley.glb
)
Expand Down
6 changes: 4 additions & 2 deletions s/tools/optimize_scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
import {Scene, ScenePerformancePriority} from "@babylonjs/core/scene.js"

export function optimize_scene(scene: Scene) {
scene.performancePriority = ScenePerformancePriority.Intermediate
scene.performancePriority = ScenePerformancePriority.BackwardCompatible

scene.autoClear = false
scene.skipFrustumClipping = true
scene.skipPointerMovePicking = true
scene.skipPointerDownPicking = true
scene.skipPointerUpPicking = true

// scene.skipFrustumClipping = false
// scene.autoClearDepthAndStencil = false
}

0 comments on commit abea4fd

Please sign in to comment.