diff options
| -rw-r--r-- | src/effects/scene1_effect.cc | 10 | ||||
| -rw-r--r-- | workspaces/main/shaders/scene1.wgsl | 16 |
2 files changed, 10 insertions, 16 deletions
diff --git a/src/effects/scene1_effect.cc b/src/effects/scene1_effect.cc index da2797c..71e25a4 100644 --- a/src/effects/scene1_effect.cc +++ b/src/effects/scene1_effect.cc @@ -7,11 +7,13 @@ #include "util/fatal_error.h" #include "util/mini_math.h" -static CameraParams make_scene1_camera() { +static CameraParams make_scene1_camera(float time) { const float TAU = 6.283185307f; - const vec3 ro(0.0f, 2.5f, 5.0f); + const float R = 6.0f; + const vec3 ro(R * sin(time * .43), 2.5f, R * cos(time * .43)); 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 @@ -31,7 +33,7 @@ Scene1::Scene1(const GpuContext& ctx, const std::vector<std::string>& inputs, create_dummy_scene_texture(); camera_params_.init(ctx_.device); - camera_params_.update(ctx_.queue, make_scene1_camera()); + camera_params_.update(ctx_.queue, make_scene1_camera(start_time)); pipeline_.set(create_post_process_pipeline( ctx_.device, WGPUTextureFormat_RGBA8Unorm, scene1_shader_wgsl)); @@ -40,6 +42,8 @@ Scene1::Scene1(const GpuContext& ctx, const std::vector<std::string>& inputs, void Scene1::render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params, NodeRegistry& nodes) { + + camera_params_.update(ctx_.queue, make_scene1_camera(params.time)); WGPUTextureView output_view = nodes.get_view(output_nodes_[0]); pp_update_bind_group(ctx_.device, pipeline_.get(), bind_group_.get_address(), diff --git a/workspaces/main/shaders/scene1.wgsl b/workspaces/main/shaders/scene1.wgsl index e98fae6..a47413b 100644 --- a/workspaces/main/shaders/scene1.wgsl +++ b/workspaces/main/shaders/scene1.wgsl @@ -26,8 +26,6 @@ fn rayPlane(ray: Ray, plane: vec4<f32>) -> f32 { return -(dot(ray.origin, plane.xyz) + plane.w) / dot(ray.direction, plane.xyz); } -var<private> g_rot0: mat2x2<f32>; - fn render0(ray: Ray) -> vec3<f32> { var col = vec3<f32>(0.0); let y = abs(ray.direction.y); @@ -54,11 +52,7 @@ const OBJ_CUBE: f32 = 1.0; const OBJ_SPHERE: f32 = 2.0; const OBJ_PLANE: f32 = 3.0; -fn df(p_in: vec3<f32>) -> f32 { - var p = p_in; - p.x = p_in.x * g_rot0[0][0] + p_in.z * g_rot0[0][1]; - p.z = p_in.x * g_rot0[1][0] + p_in.z * g_rot0[1][1]; - +fn df(p: vec3<f32>) -> f32 { // Cube var pc = p - vec3<f32>(-1.9, 0.0, 0.0); let dCube = sdBox(pc, vec3<f32>(1.6)); @@ -77,11 +71,7 @@ fn df(p_in: vec3<f32>) -> f32 { return d; } -fn dfWithID(p_in: vec3<f32>) -> RayMarchResult { - var p = p_in; - p.x = p_in.x * g_rot0[0][0] + p_in.z * g_rot0[0][1]; - p.z = p_in.x * g_rot0[1][0] + p_in.z * g_rot0[1][1]; - +fn dfWithID(p: vec3<f32>) -> RayMarchResult { // Cube var pc = p - vec3<f32>(-1.9, 0.0, 0.0); let dCube = sdBox(pc, vec3<f32>(1.6)); @@ -177,7 +167,7 @@ fn render1(ray: Ray) -> vec3<f32> { } fn effect(p: vec2<f32>) -> vec3<f32> { - g_rot0 = rot(-0.2 * uniforms.time); +// g_rot0 = rot(-0.2 * uniforms.time); let ray = getCameraRay(camera, p); return render1(ray); } |
