Skip to content

Commit

Permalink
Render 300 frames.
Browse files Browse the repository at this point in the history
- Box moving scene.
  • Loading branch information
kugimasa committed Aug 24, 2023
1 parent 57f3b6c commit 90356be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/include/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Renderer {

bool OnCompute();

bool OnRender(int frame);
bool OnRender(uint32_t frame);

void OnFrame();

Expand Down Expand Up @@ -42,7 +42,7 @@ class Renderer {
private:
static const uint32_t WIDTH = 640;
static const uint32_t HEIGHT = 480;
static const uint32_t MAX_FRAME = 1;
static const uint32_t MAX_FRAME = 300;
Camera camera_{};
Scene scene_{};
bool hasWindow_ = false;
Expand Down
9 changes: 6 additions & 3 deletions src/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,18 @@ bool Renderer::OnCompute() {
return success;
}

bool Renderer::OnRender(int frame) {
bool Renderer::OnRender(uint32_t frame) {
// chrono変数
std::chrono::system_clock::time_point start, end;
// 時間計測開始
start = std::chrono::system_clock::now();
/// Update camera
/// NOTE: 原点が(0, 0, 0)だと描画がうまくいかないことがある(FarのQuadなど)
Point3 origin = Vec3(0, 0, 0.01);
Point3 target = Vec3(0, 0, 15);
Point3 start_origin = Vec3(0, 0, 0.01);
Point3 start_target = Vec3(0, 0, 15);
float move_dist = lerp(0.0, 40.0, (float) frame / (float) MAX_FRAME);
Point3 origin = Vec3(0, 0, 0.01f - move_dist);
Point3 target = Vec3(0, 0, 15 + move_dist);
float aspect = (float) WIDTH / (float) HEIGHT;
float time = 0.0f;
camera_.Update(queue_, origin, target, aspect, time);
Expand Down
16 changes: 2 additions & 14 deletions src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,14 @@
*/
Scene::Scene(Device &device) {
/// Quadの追加
/// FIXME: 以下テスト用
auto pos = Point3(0, 0, -9);
auto scale = Vec3(6, 6, 6);
auto scale = Vec3(8, 5, 100);
auto cb = CornellBox(pos, scale);
auto u = 1.0f;
auto v = 2.0f;
auto center = Point3(2.0f, 0.0f, -9.0f);
pos = Point3(center.X(), center.Y() - v / 2.0f, center.Z() + u / 2.0f);
auto right = Vec3(0, 0, -u);
auto up = Vec3(0, v, 0);
quads_.emplace_back(pos, right, up, Color3(0.0, 0.2, 0.5));
pos = Vec3(-2, -2, -10);
right = Vec3(4, 0, 0);
up = Vec3(0, 4, 0);
quads_.emplace_back(pos, right, up, Color3(0.0, 0.2, .05));
/// CornellBoxの追加
cb.PushToQuads(quads_);

/// Sphereの追加
spheres_.emplace_back(Point3(0, 0, -9), 0.5, Color3(20, 20, 20), true);
spheres_.emplace_back(Point3(0, 0, -40), 0.5, Color3(20, 20, 20), true);
spheres_.emplace_back(Point3(-1.0, 0, -9), 0.3, Color3(0.0, 0.2, 0.5));
/// バッファのバインド
InitBindGroupLayout(device);
Expand Down

0 comments on commit 90356be

Please sign in to comment.