96 lines
2.4 KiB
Text
96 lines
2.4 KiB
Text
-- Stage 6b test: shadows. A floor, a cube, a duck and a walking fox under a directional sun
|
|
-- (first screenshot), then the same scene lit by a spot light overhead (second screenshot).
|
|
local font = fontLoad("Singe/FreeSansBold.ttf", 28)
|
|
local frames = 0
|
|
|
|
fontSelect(font)
|
|
discPlay()
|
|
sceneEnable(true)
|
|
sceneSetBackground(30, 30, 50, 255)
|
|
sceneSetAmbient(50, 50, 60)
|
|
|
|
local grey = materialNew()
|
|
materialSetColor(grey, 200, 200, 200)
|
|
materialSetRoughness(grey, 0.9)
|
|
|
|
local red = materialNew()
|
|
materialSetColor(red, 220, 50, 50)
|
|
|
|
local floor = nodeNew()
|
|
nodeSetMesh(floor, meshPlane(10, 10), grey)
|
|
nodeSetPosition(floor, 0, -1, 0)
|
|
|
|
local wall = nodeNew()
|
|
nodeSetMesh(wall, meshBox(10, 4, 0.2), grey)
|
|
nodeSetPosition(wall, 0, 1, -3)
|
|
|
|
local cube = nodeNew()
|
|
nodeSetMesh(cube, meshBox(1, 1, 1), red)
|
|
nodeSetPosition(cube, -2, -0.5, 0)
|
|
nodeSetRotation(cube, 0, 30, 0)
|
|
|
|
local duck = modelInstance(modelLoad("testScripts/Models/Duck.glb"))
|
|
nodeSetPosition(duck, 0.5, -1, 0.5)
|
|
nodeSetRotation(duck, 0, -40, 0)
|
|
|
|
local fox = modelInstance(modelLoad("testScripts/Models/Fox.glb"))
|
|
nodeSetPosition(fox, 2.5, -1, 0)
|
|
nodeSetScale(fox, 0.015)
|
|
nodeSetRotation(fox, 0, -110, 0)
|
|
animationPlay(fox, "Walk", true)
|
|
|
|
local sun = lightNew(LIGHT_DIRECTIONAL)
|
|
nodeSetPosition(sun, 3, 6, 4)
|
|
nodeLookAt(sun, 0, 0, 0)
|
|
lightSetIntensity(sun, 1.4)
|
|
lightSetShadow(sun, true)
|
|
|
|
local lamp = lightNew(LIGHT_SPOT)
|
|
nodeSetPosition(lamp, 0, 5, 1.5)
|
|
nodeLookAt(lamp, 0, -1, 0)
|
|
lightSetIntensity(lamp, 40)
|
|
lightSetCone(lamp, 30, 42)
|
|
nodeSetVisible(lamp, false)
|
|
|
|
local bulb = lightNew(LIGHT_POINT)
|
|
nodeSetPosition(bulb, 0.8, 0.4, 1.2)
|
|
lightSetColor(bulb, 255, 220, 180)
|
|
lightSetIntensity(bulb, 12)
|
|
lightSetRange(bulb, 12)
|
|
nodeSetVisible(bulb, false)
|
|
|
|
local camera = nodeNew()
|
|
nodeSetPosition(camera, 0, 2.5, 7)
|
|
nodeLookAt(camera, 0, -0.3, 0)
|
|
cameraSet(camera)
|
|
|
|
function onOverlayUpdate()
|
|
frames = frames + 1
|
|
overlayClear()
|
|
fontPrint(20, 20, "Shadows, frame " .. frames)
|
|
if frames == 40 then
|
|
singeScreenshot()
|
|
end
|
|
if frames == 45 then
|
|
-- Sun and spot casting at once.
|
|
nodeSetVisible(lamp, true)
|
|
lightSetShadow(lamp, true)
|
|
end
|
|
if frames == 80 then
|
|
singeScreenshot()
|
|
end
|
|
if frames == 85 then
|
|
-- A bulb inside the scene: cube-map shadows in every direction.
|
|
nodeSetVisible(sun, false)
|
|
nodeSetVisible(lamp, false)
|
|
nodeSetVisible(bulb, true)
|
|
lightSetShadow(bulb, true)
|
|
sceneSetAmbient(25, 25, 30)
|
|
end
|
|
if frames == 120 then
|
|
singeScreenshot()
|
|
end
|
|
if frames == 130 then
|
|
singeQuit()
|
|
end
|
|
end
|