summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/effects/scene1_effect.cc20
-rw-r--r--src/effects/scene1_effect.h2
-rw-r--r--src/effects/shaders.cc2
-rw-r--r--workspaces/main/shaders/scene1.wgsl16
4 files changed, 26 insertions, 14 deletions
diff --git a/src/effects/scene1_effect.cc b/src/effects/scene1_effect.cc
index 7c109e7..da2797c 100644
--- a/src/effects/scene1_effect.cc
+++ b/src/effects/scene1_effect.cc
@@ -5,6 +5,21 @@
#include "gpu/gpu.h"
#include "gpu/post_process_helper.h"
#include "util/fatal_error.h"
+#include "util/mini_math.h"
+
+static CameraParams make_scene1_camera() {
+ const float TAU = 6.283185307f;
+ const vec3 ro(0.0f, 2.5f, 5.0f);
+ const vec3 la(0.0f, 0.0f, 0.0f);
+ const vec3 up(0.1f, 1.0f, 0.0f);
+ CameraParams cam;
+ cam.inv_view = mat4::look_at(ro, la, up).inverse();
+ cam.fov = TAU / 6.0f; // full vfov=60°; tan(fov/2)=tan(PI/6)=1/sqrt(3)=1/shader_fov
+ cam.near_plane = 0.1f;
+ cam.far_plane = 100.0f;
+ cam.aspect_ratio = 1.0f; // aspect handled in fs_main
+ return cam;
+}
Scene1::Scene1(const GpuContext& ctx, const std::vector<std::string>& inputs,
const std::vector<std::string>& outputs, float start_time,
@@ -15,6 +30,9 @@ Scene1::Scene1(const GpuContext& ctx, const std::vector<std::string>& inputs,
create_nearest_sampler();
create_dummy_scene_texture();
+ camera_params_.init(ctx_.device);
+ camera_params_.update(ctx_.queue, make_scene1_camera());
+
pipeline_.set(create_post_process_pipeline(
ctx_.device, WGPUTextureFormat_RGBA8Unorm, scene1_shader_wgsl));
}
@@ -26,7 +44,7 @@ void Scene1::render(WGPUCommandEncoder encoder,
pp_update_bind_group(ctx_.device, pipeline_.get(), bind_group_.get_address(),
dummy_texture_view_.get(), uniforms_buffer_.get(),
- {nullptr, 0});
+ camera_params_.get());
WGPURenderPassColorAttachment color_attachment = {};
gpu_init_color_attachment(color_attachment, output_view);
diff --git a/src/effects/scene1_effect.h b/src/effects/scene1_effect.h
index 781cbae..0d5d9d1 100644
--- a/src/effects/scene1_effect.h
+++ b/src/effects/scene1_effect.h
@@ -2,6 +2,7 @@
#pragma once
+#include "gpu/camera_params.h"
#include "gpu/effect.h"
#include "gpu/uniform_helper.h"
#include "gpu/wgpu_resource.h"
@@ -18,4 +19,5 @@ class Scene1 : public Effect {
private:
RenderPipeline pipeline_;
BindGroup bind_group_;
+ UniformBuffer<CameraParams> camera_params_;
};
diff --git a/src/effects/shaders.cc b/src/effects/shaders.cc
index 4329427..c62b6a8 100644
--- a/src/effects/shaders.cc
+++ b/src/effects/shaders.cc
@@ -29,7 +29,7 @@ void InitShaderComposer() {
AssetId::ASSET_SHADER_SEQUENCE_V2_UNIFORMS);
register_if_exists("postprocess_inline",
AssetId::ASSET_SHADER_POSTPROCESS_INLINE);
- // register_if_exists("camera_common", AssetId::ASSET_SHADER_CAMERA_COMMON);
+ register_if_exists("camera_common", AssetId::ASSET_SHADER_CAMERA_COMMON);
register_if_exists("math/sdf_shapes", AssetId::ASSET_SHADER_MATH_SDF_SHAPES);
register_if_exists("math/sdf_utils", AssetId::ASSET_SHADER_MATH_SDF_UTILS);
register_if_exists("math/common_utils",
diff --git a/workspaces/main/shaders/scene1.wgsl b/workspaces/main/shaders/scene1.wgsl
index 2f1174a..ff21318 100644
--- a/workspaces/main/shaders/scene1.wgsl
+++ b/workspaces/main/shaders/scene1.wgsl
@@ -2,12 +2,14 @@
// Source: Saturday cubism experiment by skal
#include "sequence_uniforms"
+#include "camera_common"
#include "math/color"
#include "math/utils"
#include "math/sdf_shapes"
#include "render/raymarching"
@group(0) @binding(2) var<uniform> uniforms: UniformsSequenceParams;
+@group(0) @binding(3) var<uniform> camera: CameraParams;
const PI: f32 = 3.141592654;
const TAU: f32 = 6.283185307;
@@ -178,18 +180,8 @@ fn render1(ro: vec3<f32>, rd: vec3<f32>) -> vec3<f32> {
fn effect(p: vec2<f32>) -> vec3<f32> {
g_rot0 = rot(-0.2 * uniforms.time);
-
- let fov = tan(TAU / 6.0);
- let ro = vec3<f32>(0.0, 2.5, 5.0);
- let la = vec3<f32>(0.0, 0.0, 0.0);
- let up = vec3<f32>(0.1, 1.0, 0.0);
-
- let ww = normalize(la - ro);
- let uu = normalize(cross(up, ww));
- let vv = cross(ww, uu);
- let rd = normalize(-p.x * uu + p.y * vv + fov * ww);
-
- return render1(ro, rd);
+ let ray = getCameraRay(camera, p);
+ return render1(ray.origin, ray.direction);
}
#include "render/fullscreen_vs"