Skip to content

Commit

Permalink
merian-nodes: Shadertoy: Add more uniform variables
Browse files Browse the repository at this point in the history
  • Loading branch information
LDAP committed Sep 13, 2024
1 parent 54b21d6 commit ec05792
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
7 changes: 4 additions & 3 deletions include/merian-nodes/nodes/shadertoy/shadertoy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "merian-nodes/nodes/compute_node/compute_node.hpp"

#include "merian/utils/stopwatch.hpp"
#include "merian/vk/shader/shader_compiler.hpp"
#include "merian/vk/shader/shader_hotreloader.hpp"
#include "merian/vk/shader/shader_module.hpp"
Expand All @@ -22,11 +21,13 @@ class Shadertoy : public AbstractCompute {
glm::vec2 iResolution{};
float iTime{};
float iTimeDelta{};
float iFrame{};
int32_t iFrame{};
glm::vec4 iMouse{};
glm::vec4 iDate{};
};

public:
Shadertoy(const ContextHandle context);
Shadertoy(const ContextHandle& context);

std::vector<OutputConnectorHandle> describe_outputs(const NodeIOLayout& io_layout) override;

Expand Down
21 changes: 15 additions & 6 deletions src/merian-nodes/nodes/shadertoy/shadertoy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ layout(push_constant) uniform constants {
vec2 iResolution;
float iTime;
float iTimeDelta;
float iFrame;
int iFrame;
vec4 iMouse;
vec4 iDate;
};
)";
Expand Down Expand Up @@ -61,7 +63,7 @@ void mainImage(out vec4 fragColor, in vec2 fragCoord) {

class ShadertoyInjectCompiler : public ShaderCompiler {
public:
ShadertoyInjectCompiler(const ShaderCompilerHandle forwarding_compiler)
ShadertoyInjectCompiler(const ShaderCompilerHandle& forwarding_compiler)
: forwarding_compiler(forwarding_compiler) {}

~ShadertoyInjectCompiler() {}
Expand All @@ -78,7 +80,7 @@ class ShadertoyInjectCompiler : public ShaderCompiler {
const ShaderCompilerHandle forwarding_compiler;
};

Shadertoy::Shadertoy(const ContextHandle context)
Shadertoy::Shadertoy(const ContextHandle& context)
: AbstractCompute(context, sizeof(PushConstant)), shader_glsl(default_shader) {

ShaderCompilerHandle shaderc_compiler = nullptr;
Expand Down Expand Up @@ -133,7 +135,15 @@ const void* Shadertoy::get_push_constant([[maybe_unused]] GraphRun& run,
[[maybe_unused]] const NodeIO& io) {
constant.iTimeDelta = static_cast<float>(run.get_time_delta());
constant.iTime = static_cast<float>(run.get_elapsed());
constant.iFrame++;
constant.iFrame = static_cast<int32_t>(run.get_total_iteration());

const auto now = std::chrono::system_clock::now();
const auto now_d = std::chrono::floor<std::chrono::days>(now);
const std::chrono::year_month_day ymd(now_d);
constant.iDate.x = static_cast<float>(static_cast<int>(ymd.year()));
constant.iDate.y = static_cast<float>(static_cast<unsigned int>(ymd.month()));
constant.iDate.y = static_cast<float>(static_cast<unsigned int>(ymd.day()));
constant.iDate.w = std::chrono::duration_cast<std::chrono::duration<float>>(now - now_d).count();

return &constant;
}
Expand Down Expand Up @@ -222,9 +232,8 @@ AbstractCompute::NodeStatusFlags Shadertoy::properties(Properties& config) {

if (needs_reconnect) {
return NEEDS_RECONNECT;
} else {
return {};
}
return {};
}

} // namespace merian_nodes

0 comments on commit ec05792

Please sign in to comment.