app :: App :: frame_core_shadow_prep
This method updates shadow_context.depth_texture
.
# Update the depth texture from the light point of view
#
# This method updates `shadow_context.depth_texture`.
protected fun frame_core_shadow_prep(display: GamnitDisplay)
do
if not supports_shadows then return
var light = app.light
if not light isa LightCastingShadows then return
# Make sure there's no errors pending
assert glGetError == gl_NO_ERROR
# Bind the framebuffer and make sure it is OK
glBindFramebuffer(gl_FRAMEBUFFER, shadow_context.light_view_framebuffer)
assert glGetError == gl_NO_ERROR
assert glCheckFramebufferStatus(gl_FRAMEBUFFER) == gl_FRAMEBUFFER_COMPLETE
# Draw to fill the depth texture and only the depth
glViewport(0, 0, shadow_resolution, shadow_resolution)
glColorMask(false, false, false, false)
glClear gl_COLOR_BUFFER_BIT | gl_DEPTH_BUFFER_BIT
assert glGetError == gl_NO_ERROR
# Update light position
var camera = light.camera
camera.position.x = app.world_camera.position.x
camera.position.y = app.world_camera.position.y
camera.position.z = app.world_camera.position.z
# Draw all actors
for actor in actors do
for leaf in actor.model.leaves do
leaf.material.draw_depth(actor, leaf, camera)
end
end
# Take down, bring back default values
bind_screen_framebuffer shadow_context.screen_framebuffer
glColorMask(true, true, true, true)
end
lib/gamnit/depth/shadow.nit:77,2--117,4