diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/effects/scene1_effect.cc | 20 | ||||
| -rw-r--r-- | src/effects/scene1_effect.h | 2 | ||||
| -rw-r--r-- | src/effects/shaders.cc | 2 |
3 files changed, 22 insertions, 2 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", |
