Skybox
The sky: a gradient with a sun in it, drawn behind everything else. ## Why this is not a textured cube map The usual skybox is six images. That needs a colour cube map, which needs a native upload path this library does not have, and it needs the caller to find or make six matched images before they can see anything at all. This one is computed in the fragment shader from the view direction, so it needs no files, no native additions, and no assets in a release. An outdoor scene gets a horizon, a zenith and a sun by saying what colour they are. A photographic sky is a different feature and would want the cube map. ## How it draws Three things have to be true or a skybox goes wrong in a way that looks like something else broke: no translation The view matrix's translation is stripped, so the sky does not move when the camera walks. Leave it in and the sky slides past like painted scenery on a nearby wall. inside the cube Mesh->CubeInterior winds its triangles inward. Using Mesh->Cube instead leaves every face back-facing and the sky vanishes the moment culling is on. behind Drawn first with depth WRITES off, so everything after it covers it without the sky having to be far away. Draw takes the Camera rather than a matrix, because all three of those are easy to get wrong and none of them are interesting. sky := Skybox->New(); sky->SetHorizon(0.55, 0.62, 0.70); sky->SetZenith(0.12, 0.26, 0.55); sky->SetSun(0.3, 0.55, -0.75); ... window->BeginFrame(); sky->Draw(camera); # first, before the scene scene->Draw(view_projection);
Operations
Draw #
Draw the sky. Call FIRST, before the scene, and after BeginFrame has cleared. The depth buffer is left untouched, so everything drawn afterwards covers this regardless of distance. Restores depth writing and the cull mode on the way out, because a pass that quietly leaves state changed is the kind of bug that surfaces three draw calls later in unrelated geometry.
method : public : Draw(camera:Camera) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| camera | Camera | the eye. Its rotation is used and its position is not. |
GetError #
method : public : GetError() ~ StringReturn
| Type | Description |
|---|---|
| String | why this sky cannot draw, or an empty string |
IsOk #
method : public : IsOk() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true when the shader built and the geometry uploaded |
New # constructor
A sky drawn with geometry the caller owns.
New(mesh:Mesh)Parameters
| Name | Type | Description |
|---|---|---|
| mesh | Mesh | an INWARD-facing cube. Mesh->CubeInterior makes one; Mesh->Cube does not and will be invisible under back-face culling. |
SetHorizon #
The colour at eye level.
method : public : SetHorizon(r:Float, g:Float, b:Float) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| r | Float | red, 0..1 |
| g | Float | green, 0..1 |
| b | Float | blue, 0..1 |
SetSun #
Where the sun is, as a DIRECTION from the viewer -- not a position. It is normalised here, so any non-zero length will do. Point this the same way as the scene's directional Light and the shadows will agree with the sky. Nothing enforces that: they are two separate settings, and a sun in one corner with shadows from the other is a mistake this class cannot see.
method : public : SetSun(x:Float, y:Float, z:Float) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| x | Float | direction x |
| y | Float | direction y, positive is up |
| z | Float | direction z |
SetSunColor #
The sun's colour.
method : public : SetSunColor(r:Float, g:Float, b:Float) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| r | Float | red, 0..1 |
| g | Float | green, 0..1 |
| b | Float | blue, 0..1 |
SetSunSize #
How tight the sun's disc is. This is the cosine of its angular radius, so LARGER is smaller: 0.9999 is a pinpoint, 0.99 is a soft glow, and anything at or below 0.0 fills half the sky. Clamped below 1.0, because exactly 1.0 is a sun of zero size that flickers as it crosses a pixel centre.
method : public : SetSunSize(cosine:Float) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| cosine | Float | 0..1, nearer 1 for a smaller sun |