SkyLight
Package: Libraries.Game.Graphics · Inherits from: Libraries.Language.Object
SkyLight is the light a Skybox gives a scene: the soft light from every direction of the sky, and the sky seen in shiny surfaces. It is worked out once, on the computer's processor, from the sky's six pictures, when the sky is set or changes: - the diffuse light: nine numbers per color (spherical harmonics), which give the light falling on a surface facing any direction; - reflections: four small cubes of the sky, 64, 32, 16 and 8 pixels a side, each a blurrier half of the last. Rough surfaces see the blurrier ones. The Vulkan 3D painter makes one for its layer's skybox on its own, and gives it to the layer's EnvironmentVulkan, so most programs never use this class. EnvironmentVulkan:SetSkyLightStrength sets how strong it is.
Example Code
use Libraries.Game.Game
use Libraries.Game.Graphics.Skybox
use Libraries.Game.Graphics.SkyLight
class Main is Game
action Main
StartGame()
end
action CreateGame
Skybox skybox
skybox:Load("Skybox/right.jpg", "Skybox/left.jpg", "Skybox/top.jpg", "Skybox/bottom.jpg", "Skybox/front.jpg", "Skybox/back.jpg")
SetSkybox(skybox)
SkyLight light
if light:Load(skybox)
output "The sky light is ready."
end
end
end
Actions
Dispose()
This action frees the reflection cubes. The light can be loaded again.
GetIrradiance()
This action returns the diffuse light: 27 numbers, nine coefficients of red, green and blue in turn. They are scaled so a sky of one even color gives that color back.
Returns
Libraries.Containers.Number32BitArray: The 27 numbers.
GetLinearIrradiance()
This action returns the diffuse light for linear lighting: as GetIrradiance, but worked out from the sky pictures' colors turned from how pictures store them (sRGB) into amounts of light.
Returns
Libraries.Containers.Number32BitArray: The 27 numbers.
GetReflectionCube(integer index)
This action returns one reflection cube: 0 is the sharpest (64 pixels a side), 3 the blurriest (8 pixels).
Parameters
indexinteger: Which cube, from 0 to 3.
Returns
Libraries.Game.Graphics.Texture: The cube.
GetReflectionCubeCount()
This action returns how many reflection cubes there are, 4.
Returns
integer: The number of reflection cubes.
GetSkybox()
This action returns the skybox the light was made from. Its rotation turns the light too.
Returns
Libraries.Game.Graphics.Skybox: The skybox, or undefined before Load.
IsLoaded()
This action returns true once Load has made the light.
Returns
boolean: True if the light is ready.
IsMadeFrom(Libraries.Game.Graphics.Skybox skybox)
This action returns true if this light was made from the skybox as it is now: the same skybox, with the same six files.
Parameters
skyboxLibraries.Game.Graphics.Skybox: A skybox.
Returns
boolean: True if the light was made from it and it hasn't changed since.
Load(Libraries.Game.Graphics.Skybox skybox)
This action works out the sky light from a skybox's six pictures: it reads them again from their files, makes the four reflection cubes and the diffuse light. It takes a moment for large pictures, so it is done once, when the sky changes. The cubes are asked for from the texture manager and are ready when it next loads textures.
Parameters
skyboxLibraries.Game.Graphics.Skybox: The skybox, loaded from six files.
Returns
boolean: True if the light was made, or false if a picture couldn't be read.