MXVK Vulkan Framework 0.24.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
example::SnowEffect3D Class Reference

Public Member Functions

void drawLayer (VkCommandBuffer cmd, uint32_t imageIndex, const glm::mat4 &view, const glm::mat4 &proj, bool frontLayer)
void init (mxvk::VK_Window *window, const std::string &assetRoot, const std::string &fragmentShaderPath)
void update (float deltaSeconds)

Static Public Attributes

static constexpr int MAX_SNOWFLAKES = 600
static constexpr float modelDepthClearance = 0.55f

Detailed Description

Definition at line 40 of file main.cpp.

Member Function Documentation

◆ drawLayer()

void example::SnowEffect3D::drawLayer ( VkCommandBuffer cmd,
uint32_t imageIndex,
const glm::mat4 & view,
const glm::mat4 & proj,
bool frontLayer )
inline

Definition at line 90 of file main.cpp.

90 {
91 if (snowSprite == nullptr) {
92 return;
93 }
94
95 snowSprite->updateCamera(imageIndex, view, proj);
96 for (const SnowFlake &flake : snowflakes) {
97 const bool isFront = flake.z >= 0.0f;
98 if (isFront != frontLayer) {
99 continue;
100 }
101
102 snowSprite->drawSprite(glm::vec3(flake.x, flake.y, flake.z),
103 glm::vec2(flake.size, flake.size),
104 glm::vec4(1.0f, 1.0f, 1.0f, 1.0f),
105 flake.rotation);
106 }
107
108 snowSprite->render(cmd, imageIndex);
109 snowSprite->clearQueue();
110 }

◆ init()

void example::SnowEffect3D::init ( mxvk::VK_Window * window,
const std::string & assetRoot,
const std::string & fragmentShaderPath )
inline

Definition at line 45 of file main.cpp.

45 {
46 if (snowSprite != nullptr) {
47 return;
48 }
49
50 snowSprite = window->createSprite3D(assetRoot + "/data/snowflake.png", "", fragmentShaderPath);
51 snowSprite->setDepthTestEnabled(true);
52 snowSprite->setDepthWriteEnabled(false);
53 snowSprite->setAlphaDiscardThreshold(0.1f);
54
55 snowflakes.reserve(MAX_SNOWFLAKES);
56 for (int i = 0; i < MAX_SNOWFLAKES; ++i) {
57 snowflakes.push_back(makeFlake());
58 }
59 }
static constexpr int MAX_SNOWFLAKES
Definition main.cpp:42
void setDepthTestEnabled(bool enabled)
Enable or disable depth testing for the 3D sprite pipeline.
VK_Sprite3D * createSprite3D(const std::string &pngPath, const std::string &vertexShaderPath="", const std::string &fragmentShaderPath="")
Create a world-space billboard sprite from a PNG file.
Definition mxvk.cpp:3578

◆ update()

void example::SnowEffect3D::update ( float deltaSeconds)
inline

Definition at line 61 of file main.cpp.

61 {
62 windTime += deltaSeconds * 1.2f;
63 const float windOffsetX = std::sin(windTime) * 0.12f;
64 const float windOffsetZ = std::cos(windTime * 0.7f) * 0.04f;
65 constexpr float twoPi = 6.28318530717958647692f;
66
67 for (auto &flake : snowflakes) {
68 flake.y -= flake.speed * deltaSeconds;
69 flake.x += windOffsetX * deltaSeconds;
70 flake.z += windOffsetZ * deltaSeconds;
71 if (std::abs(flake.z) < modelDepthClearance) {
72 flake.z = (flake.z >= 0.0f) ? modelDepthClearance : -modelDepthClearance;
73 }
74 flake.rotation += (flake.rotationSpeed + std::sin(windTime + flake.rotationAngle) *
75 flake.rotationSpeedIntensity * 0.5f) *
76 deltaSeconds;
77 if (flake.rotation > twoPi) {
78 flake.rotation -= twoPi;
79 } else if (flake.rotation < -twoPi) {
80 flake.rotation += twoPi;
81 }
82
83 if (flake.y < -3.8f) {
84 flake = makeFlake();
85 flake.y = 3.8f;
86 }
87 }
88 }
static constexpr float modelDepthClearance
Definition main.cpp:43

Member Data Documentation

◆ MAX_SNOWFLAKES

int example::SnowEffect3D::MAX_SNOWFLAKES = 600
staticconstexpr

Definition at line 42 of file main.cpp.

◆ modelDepthClearance

float example::SnowEffect3D::modelDepthClearance = 0.55f
staticconstexpr

Definition at line 43 of file main.cpp.


The documentation for this class was generated from the following file: