From b08ceba6993cbe4a6e8a7097d284e9e86c3a292c Mon Sep 17 00:00:00 2001 From: chenxin Date: Wed, 24 Apr 2024 23:30:26 +0800 Subject: [PATCH] fix bump2normal channels --- src/compute | 2 +- src/textures/CMakeLists.txt | 2 +- src/textures/bump2normal.cpp | 20 ++++++++++++-------- src/textures/concat.cpp | 4 ---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/compute b/src/compute index a9390277..017f8500 160000 --- a/src/compute +++ b/src/compute @@ -1 +1 @@ -Subproject commit a939027785e0437362d81e29a7990ec5a11bc784 +Subproject commit 017f85001cf63ce22074301e6eb64d459fe5f3b8 diff --git a/src/textures/CMakeLists.txt b/src/textures/CMakeLists.txt index 75afbc26..0081ab66 100644 --- a/src/textures/CMakeLists.txt +++ b/src/textures/CMakeLists.txt @@ -17,4 +17,4 @@ luisa_render_add_plugin(nishitasky CATEGORY texture SOURCES nishita_sky.cpp) target_link_libraries(luisa-render-texture-nishitasky PRIVATE luisa-render-texture-sky-precompute) # bump to normal -luisa_render_add_plugin(bump2normal CATEGORY texture SOURCES bump2normal.cpp) +luisa_render_add_plugin(bumptonormal CATEGORY texture SOURCES bump2normal.cpp) diff --git a/src/textures/bump2normal.cpp b/src/textures/bump2normal.cpp index 9f50b8a6..9cdac617 100644 --- a/src/textures/bump2normal.cpp +++ b/src/textures/bump2normal.cpp @@ -73,6 +73,14 @@ class Bump2NormalTexture final : public Texture { _scale = desc->property_float_or_default("scale", 1.f); _bump_texture = scene->load_texture(desc->property_node("bump")); + if (_bump_texture->channels() != 1u) { + LUISA_WARNING_WITH_LOCATION("Bump image {} should only have 1 channel. {} found.", + desc->identifier(), + _bump_texture->channels()); + } + LUISA_ASSERT(all(_bump_texture->resolution() >= 3u), + "Bump image {} resolution conflicts with the algorithm.", + desc->identifier()); _gaussian5x5 = scene->load_filter(builtin_gaussian_filter_desc(5)); _gaussian3x3 = scene->load_filter(builtin_gaussian_filter_desc(3)); @@ -116,12 +124,6 @@ luisa::unique_ptr Bump2NormalTexture::build( auto res_dy = make_uint2(resolution_scaled.x, resolution_scaled.y - 1u); auto strength = std::min(resolution.x, resolution.y) * _scale; - LUISA_ASSERT(bump_texture->node()->channels() == 1u, - "Bump image should only have 1 channel. {} found.", - bump_texture->node()->channels()); - LUISA_ASSERT(all(resolution >= 3u), - "Bump image resolution conflicts with the algorithm."); - auto bump_scaled = pipeline.create>(PixelStorage::FLOAT1, resolution_scaled, 1u); auto gaussian_blurred = pipeline.create>(PixelStorage::FLOAT1, resolution_scaled, 1u); auto dx = pipeline.create>(PixelStorage::FLOAT1, res_dx, 1u); @@ -134,9 +136,11 @@ luisa::unique_ptr Bump2NormalTexture::build( auto uv = make_float2( dispatch_id.x / Float(resolution.x), dispatch_id.y / Float(resolution.y)); - auto value = bump_texture->evaluate(Interaction(uv), 0.f); + auto value = bump_texture->evaluate(Interaction(uv), 0.f).x; auto value_mapped = pow(value, 2.2f); - target->write(dispatch_id, value_mapped); + auto value_float4 = def(make_float4(0.f)); + value_float4.x = value_mapped; + target->write(dispatch_id, value_float4); }; auto scale_shader = pipeline.device().compile<2>(scale_kernel); command_buffer << scale_shader(*bump_scaled).dispatch(resolution_scaled) << commit(); diff --git a/src/textures/concat.cpp b/src/textures/concat.cpp index 47db5f4b..5aeb8d24 100644 --- a/src/textures/concat.cpp +++ b/src/textures/concat.cpp @@ -50,10 +50,6 @@ class ConcatTexture final : public Texture { _is_black = _is_black && texture->is_black(); _evaluate_static = _evaluate_static && texture->evaluate_static().has_value(); } - LUISA_INFO_WITH_LOCATION("ConcatTexture created with {} channels.", _channels); - LUISA_INFO_WITH_LOCATION("is_constant: {}", _is_constant); - LUISA_INFO_WITH_LOCATION("is_black: {}", _is_black); - LUISA_INFO_WITH_LOCATION("evaluate_static: {}", _evaluate_static); } [[nodiscard]] const auto &sub_textures() const noexcept { return _sub_textures; } [[nodiscard]] auto last_channel_size() const noexcept { return _last_channel_size; }