Update cubemap probes automatically.
This commit is contained in:
parent
924fa2413a
commit
40276c443b
5 changed files with 53 additions and 11 deletions
|
@ -192,7 +192,24 @@ proc draw_all*(self: RenderManager) =
|
||||||
continue
|
continue
|
||||||
scene.update_all_matrices()
|
scene.update_all_matrices()
|
||||||
scene.update_lights()
|
scene.update_lights()
|
||||||
# TODO: render probes required by cameras of enabled screens
|
# TODO: move this
|
||||||
|
var update_probe_ubo = false
|
||||||
|
for probe in scene.cubemap_probes:
|
||||||
|
let upd = case probe.update_strategy:
|
||||||
|
of UpdateNever: false
|
||||||
|
of UpdateOnFirstUse:
|
||||||
|
# TODO: detect when relevant objects are fully loaded
|
||||||
|
# and also when anything that affects it is visible and
|
||||||
|
# nearby
|
||||||
|
not probe.used
|
||||||
|
of UpdateAlways: true
|
||||||
|
if upd:
|
||||||
|
probe.render_cubemap(true)
|
||||||
|
probe.used = true
|
||||||
|
update_probe_ubo = true
|
||||||
|
if update_probe_ubo:
|
||||||
|
scene.cubemap_UBO.update()
|
||||||
|
|
||||||
# TODO: render shadows required by cameras of enabled screens
|
# TODO: render shadows required by cameras of enabled screens
|
||||||
for screen in self.engine.screens:
|
for screen in self.engine.screens:
|
||||||
if not screen.enabled:
|
if not screen.enabled:
|
||||||
|
|
|
@ -584,13 +584,18 @@ method loadScene*(self: BlendLoader, name: string="", scene: Scene=nil, callback
|
||||||
if scn["id"]["name"].cstr == idname.cstring:
|
if scn["id"]["name"].cstr == idname.cstring:
|
||||||
let node = scn
|
let node = scn
|
||||||
var scene = scene
|
var scene = scene
|
||||||
|
let was_first_scene = self.engine.scenes.len == 0
|
||||||
if scene == nil:
|
if scene == nil:
|
||||||
scene = self.engine.new_scene(name=name)
|
scene = self.engine.new_scene(name=name)
|
||||||
self.loadSceneImpl(node, scene)
|
self.loadSceneImpl(node, scene)
|
||||||
callback(scene)
|
callback(scene)
|
||||||
|
# TODO: when loading is async, move this stuff after loading has
|
||||||
|
# finished
|
||||||
|
if was_first_scene and not scene.enabled:
|
||||||
|
echo "Warning: Your scene is not enabled, use 'scene.enable_render()' or 'scene.enable_all()'"
|
||||||
|
scene.render_all_cubemaps(true)
|
||||||
return
|
return
|
||||||
assert false, &"Scene {name} not found"
|
assert false, &"Scene {name} not found"
|
||||||
|
|
||||||
proc debug_dump*(self: BlendLoader) =
|
proc debug_dump*(self: BlendLoader) =
|
||||||
self.blend_file.debug_dump
|
self.blend_file.debug_dump
|
||||||
|
|
|
@ -96,6 +96,7 @@ proc newCubemapProbe*(engine: MyouEngine, name: string="camera", scene: Scene =
|
||||||
parallax_distance
|
parallax_distance
|
||||||
else:
|
else:
|
||||||
influence_distance
|
influence_distance
|
||||||
|
self.update_strategy = UpdateOnFirstUse
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -351,6 +351,17 @@ proc destroy*(self: Scene) =
|
||||||
self.engine.scenes.del(self.name)
|
self.engine.scenes.del(self.name)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
proc enable_render*(self: Scene) =
|
||||||
|
self.enabled = true
|
||||||
|
|
||||||
|
proc enable_physics*(self: Scene) =
|
||||||
|
if self.world != nil:
|
||||||
|
self.world.enabled = true
|
||||||
|
|
||||||
|
proc enable_all*(self: Scene) =
|
||||||
|
self.enable_render()
|
||||||
|
self.enable_physics()
|
||||||
|
|
||||||
proc new_gameobject*(self: Scene, name: string): GameObject =
|
proc new_gameobject*(self: Scene, name: string): GameObject =
|
||||||
return self.engine.new_gameobject(name=name, scene=self)
|
return self.engine.new_gameobject(name=name, scene=self)
|
||||||
|
|
||||||
|
@ -528,10 +539,6 @@ proc get_lighting_code*(self: Scene): string =
|
||||||
code.add staticOrDebugRead "shadows/simple_shadow.glsl"
|
code.add staticOrDebugRead "shadows/simple_shadow.glsl"
|
||||||
return code.join "\n"
|
return code.join "\n"
|
||||||
|
|
||||||
|
|
||||||
# template as_float_array(x: untyped): untyped =
|
|
||||||
# cast[array[sizeof(typeof(x)) div 4, float]](x)
|
|
||||||
|
|
||||||
proc update_lights*(self: Scene) =
|
proc update_lights*(self: Scene) =
|
||||||
if self.lighting_UBOs.len == 0:
|
if self.lighting_UBOs.len == 0:
|
||||||
return
|
return
|
||||||
|
|
|
@ -694,6 +694,11 @@ type
|
||||||
|
|
||||||
# cubemap_probe.nim
|
# cubemap_probe.nim
|
||||||
|
|
||||||
|
ProbeUpdateStrategy* = enum
|
||||||
|
UpdateNever
|
||||||
|
UpdateOnFirstUse
|
||||||
|
UpdateAlways
|
||||||
|
|
||||||
ProbeInfluenceType* = enum
|
ProbeInfluenceType* = enum
|
||||||
SphereInfluence
|
SphereInfluence
|
||||||
BoxInfluence
|
BoxInfluence
|
||||||
|
@ -715,6 +720,8 @@ type
|
||||||
intensity*: float32
|
intensity*: float32
|
||||||
clipping_start*: float32
|
clipping_start*: float32
|
||||||
clipping_end*: float32
|
clipping_end*: float32
|
||||||
|
update_strategy*: ProbeUpdateStrategy
|
||||||
|
used*: bool
|
||||||
|
|
||||||
# NOTE: layout must match struct CubemapInfo in scene.nim
|
# NOTE: layout must match struct CubemapInfo in scene.nim
|
||||||
CubemapProbeUniform* = object
|
CubemapProbeUniform* = object
|
||||||
|
@ -761,6 +768,8 @@ type
|
||||||
parent_object*: GameObject
|
parent_object*: GameObject
|
||||||
|
|
||||||
World* = ref object of RootObj
|
World* = ref object of RootObj
|
||||||
|
enabled*: bool
|
||||||
|
|
||||||
DebugDraw* = ref object of RootObj
|
DebugDraw* = ref object of RootObj
|
||||||
Body* = ref object
|
Body* = ref object
|
||||||
|
|
||||||
|
@ -824,12 +833,15 @@ type BlendLoader* = ref object of Loader
|
||||||
cached_materials*: Table[(FNode, string, bool),
|
cached_materials*: Table[(FNode, string, bool),
|
||||||
(string, seq[Varying], OrderedTable[string, string], OrderedTable[string, TexturePixels])] ## private
|
(string, seq[Varying], OrderedTable[string, string], OrderedTable[string, TexturePixels])] ## private
|
||||||
resource*: LoadableResource
|
resource*: LoadableResource
|
||||||
|
|
||||||
template enqueue*(self: RenderManager, fun: proc()) =
|
template enqueue*(renderer: RenderManager, fun: proc()) =
|
||||||
if self.initialized:
|
## Run a proc after the renderer has been initialized.
|
||||||
|
##
|
||||||
|
## If it was already initialized, it runs it immediately.
|
||||||
|
if renderer.initialized:
|
||||||
fun()
|
fun()
|
||||||
else:
|
else:
|
||||||
self.queue.add fun
|
renderer.queue.add fun
|
||||||
|
|
||||||
when not defined(release):
|
when not defined(release):
|
||||||
from sugar import dump
|
from sugar import dump
|
||||||
|
|
Loading…
Reference in a new issue