summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/36-sky/sky.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/examples/36-sky/sky.cpp')
-rw-r--r--3rdparty/bgfx/examples/36-sky/sky.cpp73
1 files changed, 37 insertions, 36 deletions
diff --git a/3rdparty/bgfx/examples/36-sky/sky.cpp b/3rdparty/bgfx/examples/36-sky/sky.cpp
index f529e0eb8a1..aad7bc27632 100644
--- a/3rdparty/bgfx/examples/36-sky/sky.cpp
+++ b/3rdparty/bgfx/examples/36-sky/sky.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2017 Stanislav Pidhorskyi. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
@@ -246,12 +246,9 @@ namespace
, m_eclipticObliquity(bx::toRad(23.4f) )
, m_delta(0.0f)
{
- m_northDirection[0] = 1.0;
- m_northDirection[1] = 0.0;
- m_northDirection[2] = 0.0;
- m_upvector[0] = 0.0f;
- m_upvector[1] = 1.0f;
- m_upvector[2] = 0.0f;
+ m_northDir = { 1.0f, 0.0f, 0.0f };
+ m_sunDir = { 0.0f, -1.0f, 0.0f };
+ m_upDir = { 0.0f, 1.0f, 0.0f };
}
void Update(float _time)
@@ -260,9 +257,9 @@ namespace
UpdateSunPosition(_time - 12.0f);
}
- float m_northDirection[3];
- float m_sunDirection[4];
- float m_upvector[3];
+ bx::Vec3 m_northDir;
+ bx::Vec3 m_sunDir;
+ bx::Vec3 m_upDir;
float m_latitude;
Month m_month;
@@ -277,27 +274,23 @@ namespace
void UpdateSunPosition(float _hour)
{
- float latitude = bx::toRad(m_latitude);
- float hh = _hour * bx::kPi / 12.0f;
- float azimuth = bx::atan2(
+ const float latitude = bx::toRad(m_latitude);
+ const float hh = _hour * bx::kPi / 12.0f;
+ const float azimuth = bx::atan2(
bx::sin(hh)
, bx::cos(hh) * bx::sin(latitude) - bx::tan(m_delta) * bx::cos(latitude)
);
- float altitude = bx::asin(
+ const float altitude = bx::asin(
bx::sin(latitude) * bx::sin(m_delta) + bx::cos(latitude) * bx::cos(m_delta) * bx::cos(hh)
);
- float rotation[4];
- bx::quatRotateAxis(rotation, m_upvector, -azimuth);
-
- float direction[3];
- bx::vec3MulQuat(direction, m_northDirection, rotation);
+ const bx::Quaternion rot0 = bx::rotateAxis(m_upDir, -azimuth);
+ const bx::Vec3 dir = bx::mul(m_northDir, rot0);
+ const bx::Vec3 uxd = bx::cross(m_upDir, dir);
- float v[3];
- bx::vec3Cross(v, m_upvector, direction);
- bx::quatRotateAxis(rotation, v, altitude);
- bx::vec3MulQuat(m_sunDirection, direction, rotation);
+ const bx::Quaternion rot1 = bx::rotateAxis(uxd, altitude);
+ m_sunDir = bx::mul(dir, rot1);
}
float m_eclipticObliquity;
@@ -311,16 +304,16 @@ namespace
static void init()
{
- ms_decl
+ ms_layout
.begin()
.add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float)
.end();
}
- static bgfx::VertexDecl ms_decl;
+ static bgfx::VertexLayout ms_layout;
};
- bgfx::VertexDecl ScreenPosVertex::ms_decl;
+ bgfx::VertexLayout ScreenPosVertex::ms_layout;
// Renders a screen-space grid of triangles.
// Because of performance reasons, and because sky color is smooth, sky color is computed in vertex shader.
@@ -372,7 +365,7 @@ namespace
}
}
- m_vbh = bgfx::createVertexBuffer(bgfx::copy(vertices, sizeof(ScreenPosVertex) * verticalCount * horizontalCount), ScreenPosVertex::ms_decl);
+ m_vbh = bgfx::createVertexBuffer(bgfx::copy(vertices, sizeof(ScreenPosVertex) * verticalCount * horizontalCount), ScreenPosVertex::ms_layout);
m_ibh = bgfx::createIndexBuffer(bgfx::copy(indices, sizeof(uint16_t) * k));
BX_FREE(allocator, indices);
@@ -407,8 +400,10 @@ namespace
class ExampleProceduralSky : public entry::AppI
{
public:
- ExampleProceduralSky(const char* _name, const char* _description): entry::AppI(_name, _description)
- {}
+ ExampleProceduralSky(const char* _name, const char* _description, const char* _url)
+ : entry::AppI(_name, _description, _url)
+ {
+ }
void init(int32_t _argc, const char* const* _argv, uint32_t _width, uint32_t _height) override
{
@@ -436,7 +431,7 @@ namespace
, 0x000000ff
, 1.0f
, 0
- );
+ );
m_sunLuminanceXYZ.SetMap(sunLuminanceXYZTable);
m_skyLuminanceXYZ.SetMap(skyLuminanceXYZTable);
@@ -452,7 +447,7 @@ namespace
m_time = 0.0f;
m_timeScale = 1.0f;
- s_texLightmap = bgfx::createUniform("s_texLightmap", bgfx::UniformType::Int1);
+ s_texLightmap = bgfx::createUniform("s_texLightmap", bgfx::UniformType::Sampler);
u_sunLuminance = bgfx::createUniform("u_sunLuminance", bgfx::UniformType::Vec4);
u_skyLuminanceXYZ = bgfx::createUniform("u_skyLuminanceXYZ", bgfx::UniformType::Vec4);
u_skyLuminance = bgfx::createUniform("u_skyLuminance", bgfx::UniformType::Vec4);
@@ -468,8 +463,7 @@ namespace
cameraCreate();
- const float initialPos[3] = { 5.0f, 3.0, 0.0f };
- cameraSetPosition(initialPos);
+ cameraSetPosition({ 5.0f, 3.0, 0.0f });
cameraSetVerticalAngle(bx::kPi / 8.0f);
cameraSetHorizontalAngle(-bx::kPi / 3.0f);
@@ -515,7 +509,8 @@ namespace
ImGui::SliderFloat("Turbidity", &m_turbidity, 1.9f, 10.0f);
ImGui::Checkbox("Prevent color banding", &m_sky.m_preventBanding);
- const char* items[] = {
+ const char* items[] =
+ {
"January",
"February",
"March",
@@ -529,6 +524,7 @@ namespace
"November",
"December"
};
+
ImGui::Combo("Month", (int*)&m_sun.m_month, items, 12);
ImGui::End();
@@ -596,7 +592,7 @@ namespace
bgfx::setUniform(u_skyLuminanceXYZ, &skyLuminanceXYZ.x);
bgfx::setUniform(u_skyLuminance, &skyLuminanceRGB.x);
- bgfx::setUniform(u_sunDirection, m_sun.m_sunDirection);
+ bgfx::setUniform(u_sunDirection, &m_sun.m_sunDir.x);
float exposition[4] = { 0.02f, 3.0f, 0.1f, m_time };
bgfx::setUniform(u_parameters, exposition);
@@ -665,4 +661,9 @@ namespace
} // namespace
-ENTRY_IMPLEMENT_MAIN(ExampleProceduralSky, "36-sky", "Perez dynamic sky model.");
+ENTRY_IMPLEMENT_MAIN(
+ ExampleProceduralSky
+ , "36-sky"
+ , "Perez dynamic sky model."
+ , "https://bkaradzic.github.io/bgfx/examples.html#sky"
+ );