luv

Workshop wiki

frontier-light.lisp

luvcraft/frontier-light.lisp

system luvcraft/core · 29 definitions · on GitHub

Production voxel light stated and lowered as frontier programs.

in-package#:luvcraft
frontiers:define-frontier-programvoxel-light-addition:family:monotone-max-fixpoint:frontier-layout:brightest-first-buckets:neighborhood:voxel-face-relations

The local law of voxel light. LEVEL is the relaxed best-known field, bound to the sky or block lane at realization; opacity is the entered cell's attenuation. A relation transfers the source level minus the propagation loss, admits a strict improvement, and schedules it at its own brightness. Those three are the monotone family's meaning; only the transfer needs stating.

:fields
level:relaxedt
opacity
:constants
direct-direction
:predicates
direct
direction=direct-direction
:transfer

Field bindings close the program over the light region's storage: each role names the lanes it borrows from a materialization (a light region entry) and how one offset is read or written through them.

defunlight-level-field-binding
field-name
let
lane-reader
ecasefield-name
frontiers:make-frontier-field-binding'level:declaration:lanes`
levels
,lane-readermaterialization
:type
simple-array
unsigned-byte8
:read'
areflevelsoffset
:write'
setf
areflevelsoffset
value
defunlight-opacity-field-binding
frontiers:make-frontier-field-binding'opacity:declaration:lanes'
losses:type
simple-array
unsigned-byte8
indices
light-region-entry-indicesmaterialization
:type
simple-array
unsigned-byte16
:read'
areflosses
arefindicesoffset
defvar*compiled-light-realizations*
make-hash-table:test#'eq
"Realizations of VOXEL-LIGHT-ADDITION per relaxed field name."
defuncompiled-light-realization
field-name

Return the current realization of the light program over field-name.

The compiled solver. Seeds and drains both go through the realization: a sky boundary is a virtual source at full brightness whose loss follows the same law, and an emitter is a value joined into the block field.

defunseed-compiled-sky-boundaries
realizationregionfrontierexecution&keykeyentry

Relate open sky into every open face of region's entries, or of entry.

flet
seed
keyentry
dolist
when

Open sky is a virtual source at full brightness beyond the face; the relation into the entry runs the other way. The program's own transfer law decides the level and admission. #581ZQP

let
map-entry-face-sitesentrydirection
lambda
offsetlocal
valueslocal
frontiers:relate-frontier-realization-siterealizationregionfrontierexecutionentryoffsetinward:direct-direction+voxel-negative-y+:level+maximum-light-level+
ifentry
seedkeyentry
maphash#'seed
light-region-entriesregion
defunseed-compiled-emitters
realizationregionfrontierexecution
maphash
lambda
keyentry
declare
ignorekey
let
indices
light-region-entry-indicesentry
do-chunk-domain-sites
offsetlocaldomain
valueslocal
let
level
arefemission
arefindicesoffset
when
plusplevel
frontiers:admit-frontier-realization-siterealizationregionfrontierexecutionentryoffsetlevel:direct-directionnil
light-region-entriesregion
defunsolve-compiled-light-region
region

Solve region from scratch with the compiled voxel-light realization. #PJY6E1

let*
sky-execution
block-execution
frontiers:make-realization-executionblockregionblock-frontier
with-cpu-trace-zone
:lighting/compiled/seed-sky
seed-compiled-sky-boundariesskyregionsky-frontiersky-execution
with-cpu-trace-zone
:lighting/compiled/propagate-sky
with-cpu-trace-zone
:lighting/compiled/drain-sites:tracy-value
frontiers:frontier-execution-visitssky-execution
frontiers:drain-frontier-realizationskyregionsky-frontiersky-execution:direct-direction+voxel-negative-y+
with-cpu-trace-zone
:lighting/compiled/seed-block
seed-compiled-emittersblockregionblock-frontierblock-execution
with-cpu-trace-zone
:lighting/compiled/propagate-block
with-cpu-trace-zone
:lighting/compiled/drain-sites:tracy-value
frontiers:frontier-execution-visitsblock-execution
frontiers:drain-frontier-realizationblockregionblock-frontierblock-execution:direct-directionnil
valuesregion
+
frontiers:frontier-execution-visitssky-execution
frontiers:frontier-execution-visitsblock-execution
listsky-executionblock-execution
defmethodsolve-light-region-using
solver
eql:compiled
regionlight-region
&key&allow-other-keys
declare
ignoresolver

Invalidation. Removing a source, an occluder's disappearance being an addition, or a departed neighbour can leave levels that no surviving source justifies. The removal program clears every level the removed site fed--strictly dimmer, or equal for direct sky continuing down--and re-admits the cleared site at the level it had; a lit neighbour it did not feed is handed to the addition frontier as a surviving source. The cleared set is the execution's retained admissions. #K3WRD3 #DURBKN

frontiers:define-frontier-programvoxel-light-removal:family:invalidation:frontier-layout:brightest-first-buckets:neighborhood:voxel-face-relations:fields
level:invalidatedt
:constants
direct-direction
:predicates
direct
direction=direct-direction
:admission
or
<
leveltarget
levelsource
anddirect
=
leveltarget
levelsource
:retain-admissionst
defvar*compiled-light-removal-realizations*
make-hash-table:test#'eq
defstruct
compiled-light-reconciliation
:constructor%make-compiled-light-reconciliation

The frontiers and executions of one compiled incremental relight.

regionnil
removalnil:typelist
additionnil:typelist
removal-executionsnil:typelist
addition-executionsnil:typelist
defunmake-compiled-light-reconciliation
region
let*
block-removal
sky-addition
block-addition
addition-frontiers
%make-compiled-light-reconciliation:regionregion:removal
listsky-removalblock-removal
:addition
listsky-additionblock-addition
:removal-executions
mapcar
lambda
realizationfrontier
frontiers:make-realization-executionrealizationregionfrontier
listsky-removalblock-removal
removal-frontiers
:addition-executions
mapcar
lambda
realizationfrontier
frontiers:make-realization-executionrealizationregionfrontier
listsky-additionblock-addition
addition-frontiers
defuninvalidate-compiled-light-site
reconciliationentryoffset

Clear both fields at ENTRY/OFFSET and admit them for removal.

loopforrealizationin
compiled-light-reconciliation-removalreconciliation
forexecutionin
compiled-light-reconciliation-removal-executionsreconciliation
forlaneinforindexfrom0do
frontiers:admit-frontier-realization-siterealization
compiled-light-reconciliation-regionreconciliation
frontiers:frontier-execution-frontierexecution
executionentryoffset
areflaneoffset
:direct-direction
defuninvalidate-compiled-light-face
reconciliationentrydirection

Clear and admit for removal every lit site on entry's direction face.

loopforrealizationin
compiled-light-reconciliation-removalreconciliation
forexecutionin
compiled-light-reconciliation-removal-executionsreconciliation
forlaneinforindexfrom0do
map-entry-face-sitesentrydirection
lambda
offsetlocal
valueslocal
when
plusp
areflaneoffset
frontiers:admit-frontier-realization-siterealization
compiled-light-reconciliation-regionreconciliation
frontiers:frontier-execution-frontierexecution
executionentryoffset
areflaneoffset
:direct-direction
defundrain-compiled-light-removals
reconciliation

Run both removal programs; survivors land in the addition frontiers.

loopforrealizationin
compiled-light-reconciliation-removalreconciliation
forexecutionin
compiled-light-reconciliation-removal-executionsreconciliation
foradditionin
compiled-light-reconciliation-addition-executionsreconciliation
forindexfrom0do
frontiers:drain-frontier-realizationrealization
compiled-light-reconciliation-regionreconciliation
frontiers:frontier-execution-frontierexecution
execution
frontiers:frontier-execution-frontieraddition
:direct-direction
defunmap-cleared-light-sites
functionexecution

Call function with ENTRY and OFFSET for every site execution cleared.

let*
sites
frontiers:frontier-execution-admitted-sitesexecution
entries
frontiers:frontier-site-buffer-materialization-lanesites
offsets
frontiers:frontier-site-buffer-offset-lanesites
dotimes
index
frontiers:frontier-site-buffer-lengthsites
funcallfunction
arefentriesindex
arefoffsetsindex
defunreseed-compiled-emitter
reconciliationentryoffset

Join ENTRY/OFFSET's own emission back into the block field.

let
level
aref
aref
light-region-entry-indicesentry
offset
when
plusplevel
let
execution
second
compiled-light-reconciliation-addition-executionsreconciliation
frontiers:admit-frontier-realization-site
second
compiled-light-reconciliation-additionreconciliation
compiled-light-reconciliation-regionreconciliation
frontiers:frontier-execution-frontierexecution
executionentryoffsetlevel:direct-directionnil
defunchunk-domain-contains-components-p
domainxyz
let
shape
voxel-space-chunk-shape
chunk-domain-spacedomain
and
<=0x
<x
chunk-shape-widthshape
<=0y
<y
chunk-shape-heightshape
<=0z
<z
chunk-shape-depthshape
defunreseed-compiled-open-sky
reconciliationentryoffset

Relate open sky back into ENTRY/OFFSET if it sits on an open face.

let*
region
compiled-light-reconciliation-regionreconciliation
realization
first
compiled-light-reconciliation-additionreconciliation
execution
first
compiled-light-reconciliation-addition-executionsreconciliation
key
light-region-entry-keyentry
dolist
when
multiple-value-bind
xyz
multiple-value-bind
neighbor-xneighbor-yneighbor-z
values
+x
voxel-direction-dxdirection
+y
voxel-direction-dydirection
+z
voxel-direction-dzdirection
unless
chunk-domain-contains-components-pdomainneighbor-xneighbor-yneighbor-z
frontiers:relate-frontier-realization-siterealizationregion
frontiers:frontier-execution-frontierexecution
executionentryoffset:direct-direction+voxel-negative-y+:level+maximum-light-level+
defunseed-compiled-arrived-chunk
reconciliationkey

Seed a newly resident chunk and reschedule its neighbours' facing sites.

let*
region
compiled-light-reconciliation-regionreconciliation
world
light-region-worldregion
entry
multiple-value-bind
chunkpresent-p
andpresent-p
or
gethashkey
light-region-entriesregion
add-light-region-entryregionchunk:from-field-pt
whenentry
let
sky
first
compiled-light-reconciliation-additionreconciliation
sky-execution
first
compiled-light-reconciliation-addition-executionsreconciliation
seed-compiled-sky-boundariesskyregion
frontiers:frontier-execution-frontiersky-execution
sky-execution:keykey:entryentry
let
indices
light-region-entry-indicesentry
do-chunk-domain-sites
offsetlocaldomain
valueslocal
when
plusp
arefemission
arefindicesoffset
reseed-compiled-emitterreconciliationentryoffset
dolist
let*
neighbor-key
neighbor
multiple-value-bind
neighbor-chunkpresent-p
world-chunk-at-coordinateworldneighbor-key
andpresent-p
or
gethashneighbor-key
light-region-entriesregion
add-light-region-entryregionneighbor-chunk:from-field-pt
declare
dynamic-extentneighbor-key
whenneighbor
loopforrealizationin
compiled-light-reconciliation-additionreconciliation
forexecutionin
compiled-light-reconciliation-addition-executionsreconciliation
forlaneindo
map-entry-face-sitesneighbor
lambda
offsetlocal
valueslocal
frontiers:schedule-frontier-realization-siterealization
frontiers:frontier-execution-frontierexecution
executionneighboroffset
areflaneoffset
defundrain-compiled-light-additions
reconciliation
loopforrealizationin
compiled-light-reconciliation-additionreconciliation
forexecutionin
compiled-light-reconciliation-addition-executionsreconciliation
forindexfrom0do
frontiers:drain-frontier-realizationrealization
compiled-light-reconciliation-regionreconciliation
frontiers:frontier-execution-frontierexecution
execution:direct-direction
defmethodreconcile-light-region-using
solver
eql:compiled
stateregion
declare
ignoresolver
with-cpu-trace-zone
:lighting/compiled/reconcile
nth-value1
defunreconcile-compiled-lighting
stateregion

Settle state's dirty cells, departures, and arrivals over candidate region with the compiled removal and addition programs. Return the executions and the total visits. #K3WRD3

let
world
lighting-state-worldstate
with-cpu-trace-zone
:lighting/compiled/invalidate
maphash
lambda
declare
ignorepresent
multiple-value-bind
entryoffset
whenentry
invalidate-compiled-light-sitereconciliationentryoffset
lighting-state-dirty-cellsstate
maphash
lambda
declare
ignorepresent
dolist
let*
neighbor-key
entry
multiple-value-bind
chunkpresent-p
world-chunk-at-coordinateworldneighbor-key
andpresent-p
or
gethashneighbor-key
light-region-entriesregion
add-light-region-entryregionchunk:from-field-pt
declare
dynamic-extentneighbor-key
whenentry
lighting-state-departuresstate
with-cpu-trace-zone
:lighting/compiled/remove
with-cpu-trace-zone
:lighting/compiled/reseed
map-cleared-light-sites
lambda
entryoffset
reseed-compiled-emitterreconciliationentryoffset
second
compiled-light-reconciliation-removal-executionsreconciliation
map-cleared-light-sites
lambda
entryoffset
reseed-compiled-open-skyreconciliationentryoffset
first
compiled-light-reconciliation-removal-executionsreconciliation
maphash
lambda
declare
ignorepresent
lighting-state-arrivalsstate
with-cpu-trace-zone
:lighting/compiled/propagate
let
executions
append
compiled-light-reconciliation-removal-executionsreconciliation
compiled-light-reconciliation-addition-executionsreconciliation
valuesexecutions
reduce#'+executions:key#'frontiers:frontier-execution-visits