blob: 89b3fa6e0d4604155f9694a9f67d611ad433d678 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
// This file is part of the 64k demo project.
// It defines RotatingCubeEffect for rendering a bump-mapped rotating cube.
// Uses auxiliary texture masking to render only inside a circular region.
#ifndef ROTATING_CUBE_EFFECT_H_
#define ROTATING_CUBE_EFFECT_H_
#include "gpu/effect.h"
#include "gpu/gpu.h"
#include "util/mini_math.h"
#include <string>
class RotatingCubeEffect : public Effect {
public:
RotatingCubeEffect(const GpuContext& ctx);
~RotatingCubeEffect() override;
void init(MainSequence* demo) override;
void render(WGPURenderPassEncoder pass, float time, float beat,
float intensity, float aspect_ratio) override;
private:
struct Uniforms {
mat4 view_proj;
mat4 inv_view_proj;
vec4 camera_pos_time;
vec4 params;
vec2 resolution;
vec2 padding;
};
struct ObjectData {
mat4 model;
mat4 inv_model;
vec4 color;
vec4 params;
};
MainSequence* demo_ = nullptr;
WGPURenderPipeline pipeline_ = nullptr;
WGPUBindGroup bind_group_0_ = nullptr;
WGPUBindGroup bind_group_1_ = nullptr;
GpuBuffer uniform_buffer_;
GpuBuffer object_buffer_;
WGPUTexture noise_texture_ = nullptr;
WGPUTextureView noise_view_ = nullptr;
WGPUSampler noise_sampler_ = nullptr;
WGPUSampler mask_sampler_ = nullptr;
float rotation_ = 0.0f;
// Store composed shader to keep it alive for WebGPU
std::string composed_shader_;
};
#endif /* ROTATING_CUBE_EFFECT_H_ */
|