测试代码更新

This commit is contained in:
daiqingshuang
2024-02-20 14:10:05 +08:00
parent c5c400229f
commit 7df6aa3e95
3 changed files with 36 additions and 32 deletions

View File

@@ -26,7 +26,7 @@ public:
static float f = 0.0f;
static int counter = 0;
// ImGui::DockSpaceOverViewport();
ImGui::DockSpaceOverViewport();
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
@@ -35,17 +35,16 @@ public:
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
// Buttons return true when clicked (most widgets return true when edited/activated)
if (ImGui::Button("按钮"))
// Buttons return true when clicked (most widgets return true when edited/activated)
counter++;
ImGui::SameLine();
ImGui::Text("counter = %d", counter);
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
if (!texture_)
texture_ = load_texture(R"(Z:\NanakoDisk\可爱二次元\IMG_2745(20230507-020428).JPG)");
texture_->draw();
render_target_->draw();
// const bool width_changed = ImGui::SliderInt("test_width", &width, 1, 1024);
// const bool height_changed = ImGui::SliderInt("test_height", &height, 1, 1024);
@@ -74,35 +73,42 @@ public:
// drawer_ = create_pixel_shader_drawer();
// drawer_->init(128, 128, pixel_shader_);
return;
texture_ = create_texture(nullptr, width, height, vk::Format::eR8G8B8A8Unorm);
// texture_ = load_texture(R"(Z:\NanakoDisk\可爱二次元\35966078_p0_waifu2x_art_noise2_scale.png)");
// return;
audio_samples_.create_storage(sizeof(float) * 1024);
render_target_ = create_render_target(width, height, vk::Format::eR8G8B8A8Unorm);
audio_samples_ = std::make_shared<buffer_vk>();
param_ = std::make_shared<buffer_vk>();
audio_samples_->create_storage(sizeof(float) * 1024);
float samples[1024] = {};
for (int i = 0; i < 1024; i++) {
samples[i] = sinf(i * 0.1f);
}
audio_samples_.update(samples, sizeof(samples));
audio_samples_->update(samples, sizeof(float) * 1024);
param_.create_storage(sizeof(test_param));
param_->create_storage(sizeof(test_param));
test_param param = {};
param.WaveColor = ImVec4(1.0f, 0.0f, 0.0f, 1.0f);
param.BgColor = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
param.LineUV = 0.5f;
param_.update(param);
param_->update(param);
compute_pipeline pipeline;
pipeline.set_shader(WAVEFORMCS_COMP, sizeof(WAVEFORMCS_COMP));
pipeline.add_storage_buffer(0, audio_samples_);
pipeline.add_storage_buffer(1, param_);
pipeline.add_uniform_image(2, texture_);
pipeline.add_storage_image(2, render_target_);
pipeline.create();
pipeline.dispatch(width, height, 1);
}
void shutdown() override {
render_target_ = nullptr;
texture_ = nullptr;
audio_samples_ = nullptr;
param_ = nullptr;
// compute_shader_ = nullptr;
// pixel_shader_ = nullptr;
@@ -112,16 +118,14 @@ public:
private:
bool show_another_window_ = true;
std::shared_ptr<texture> texture_ = nullptr;
std::shared_ptr<pixel_shader_drawer> drawer_ = nullptr;
int width = 512;
int height = 512;
std::shared_ptr<render_target> render_target_ = nullptr;
buffer_vk audio_samples_;
buffer_vk param_;
buffer_vk result_;
std::shared_ptr<render_target> render_target_ = nullptr;
std::shared_ptr<texture> texture_ = nullptr;
std::shared_ptr<buffer_vk> audio_samples_ = nullptr;
std::shared_ptr<buffer_vk> param_ = nullptr;
};
int main(int argc, char* argv[]) {

View File

@@ -2,11 +2,6 @@
layout (local_size_x = 1,local_size_y = 1,local_size_z = 1) in;
vec4 lerp(vec4 a, vec4 b, float x)
{
return a + x * (b - a);
}
layout (std430, binding = 0) buffer Samples
{
float AudioSamples[];
@@ -17,7 +12,12 @@ layout (std430, binding = 1) buffer Params
vec4 BgColor;
float LineUV;
};
layout (rgba8, binding = 2) writeonly uniform image2D Result;
layout (binding = 2) writeonly uniform image2D Result;
vec4 lerp(vec4 a, vec4 b, float x)
{
return a + x * (b - a);
}
void main()
{
@@ -25,13 +25,13 @@ void main()
ivec2 pos = ivec2(gl_GlobalInvocationID.xy);
int X = pos.x;
int Y = pos.y;
int Y = pos.y;
float height = size.y;
float Top = AudioSamples[X * 2] + 1; // -1;
float Bottom = AudioSamples[X * 2 + 1] + 1; // 1;
float Bottom = AudioSamples[X * 2 + 1] + 1; // 1;
Top = min(Top, 1);
Bottom = max(Bottom, 0);
Bottom = max(Bottom, 0);
Top *= height;
Top *= 0.5;
Bottom *= height;
@@ -39,9 +39,9 @@ void main()
// (id.y >= Top && id.y <= Bottom)
float b1 = min(step(Top, Y), step(Y , Bottom));
// (Y == height / 2)
float b2 = step(Y, height * LineUV) * step(height * LineUV, Y);
float b3 = max(b1, b2);
float b1 = min(step(Top, Y), step(Y , Bottom));
// (Y == height / 2)
float b2 = step(Y, height * LineUV) * step(height * LineUV, Y);
float b3 = max(b1, b2);
imageStore(Result, pos, lerp(BgColor, WaveColor, b3));
}