Skip to content

Commit

Permalink
fix bump2normal channels
Browse files Browse the repository at this point in the history
  • Loading branch information
OldNew777 committed Apr 24, 2024
1 parent 849b25b commit b08ceba
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/textures/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
20 changes: 12 additions & 8 deletions src/textures/bump2normal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -116,12 +124,6 @@ luisa::unique_ptr<Texture::Instance> 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<Image<float>>(PixelStorage::FLOAT1, resolution_scaled, 1u);
auto gaussian_blurred = pipeline.create<Image<float>>(PixelStorage::FLOAT1, resolution_scaled, 1u);
auto dx = pipeline.create<Image<float>>(PixelStorage::FLOAT1, res_dx, 1u);
Expand All @@ -134,9 +136,11 @@ luisa::unique_ptr<Texture::Instance> 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();
Expand Down
4 changes: 0 additions & 4 deletions src/textures/concat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit b08ceba

Please sign in to comment.