diff --git a/src/films/display.cpp b/src/films/display.cpp index f879ef62..8aab3d95 100644 --- a/src/films/display.cpp +++ b/src/films/display.cpp @@ -231,7 +231,7 @@ class DisplayInstance final : public Film::Instance { } void _display() const noexcept { - auto scale = luisa::exp2(_exposure); + auto scale = 1.0f; auto is_ldr = _window->framebuffer().storage() != PixelStorage::FLOAT4; auto size = _framebuffer.size(); *_stream << _blit(_tone_mapping, is_ldr, scale).dispatch(size); diff --git a/src/integrators/megappm_diff.cpp b/src/integrators/megappm_diff.cpp index f1be0e39..3a8dcadd 100644 --- a/src/integrators/megappm_diff.cpp +++ b/src/integrators/megappm_diff.cpp @@ -1368,6 +1368,7 @@ class MegakernelPhotonMappingDiffInstance : public DifferentiableIntegrator::Ins grad_beta += grad(beta_diff); grad_dis = grad(rel_dis_diff); }; + auto grad_b = get_bary_grad(grad_p, it->instance_id(), it->triangle_id()); count_neighbors += 1u; grad_bary += grad_b; diff --git a/src/python/lrapi.cpp b/src/python/lrapi.cpp index c936a969..a08cb6c1 100644 --- a/src/python/lrapi.cpp +++ b/src/python/lrapi.cpp @@ -160,6 +160,308 @@ class ParamStruct{ buffer_ptr(buffer_ptr), value(value){} }; +class ViewPointMap { +public: + Buffer _grid_head; + Buffer _beta3; + Buffer _wo; + Buffer _position; + Buffer _grad_pos; + Buffer _pixel_id; + Buffer _surface_tags; + Buffer _nxt; + uint _size;//current viewpoint count + const Spectrum::Instance *_spectrum; + uint _dimension; + Buffer _grid_min;//atomic float3 + Buffer _grid_max;//atomic float3 + Buffer _grid_len;//the length of a single grid (float1) + Buffer _tot; + Buffer tot_test; + float radius; +public: + ViewPointMap(uint viewpointcount, const Spectrum::Instance *spectrum, float radius) { + auto &&device = spectrum->pipeline().device(); + + _grid_head = device.create_buffer(viewpointcount); + _beta3 = device.create_buffer(viewpointcount); + _wo = device.create_buffer(viewpointcount); + _position = device.create_buffer(viewpointcount); + _pixel_id = device.create_buffer(viewpointcount); + _surface_tags = device.create_buffer(viewpointcount); + _grad_pos = device.create_buffer(viewpointcount); + _nxt = device.create_buffer(viewpointcount); + _tot = device.create_buffer(1u); + _grid_len = device.create_buffer(1u); + _grid_min = device.create_buffer(3u); + _grid_max = device.create_buffer(3u); + tot_test = device.create_buffer(1u); + + _spectrum = spectrum; + _dimension = 3; + _size = viewpointcount; + this->radius = radius; + } + auto tot_viewpoint() const noexcept { + return _tot->read(0u); + } + auto grid_len() const noexcept { + return _grid_len->read(0u); + } + auto size() const noexcept { + return _size; + } + auto position(Expr index) const noexcept { + return _position->read(index); + } + auto wo(Expr index) const noexcept { + return _wo->read(index); + } + auto beta(Expr index) const noexcept { + return _beta3->read(index); + } + auto nxt(Expr index) const noexcept { + return _nxt->read(index); + } + auto grid_head(Expr index) const noexcept { + return _grid_head->read(index); + } + auto pixel_id(Expr index) const noexcept { + return _pixel_id->read(index); + } + auto surface_tag(Expr index) const noexcept { + return _surface_tags->read(index); + } + auto grad_pos(Expr index) const noexcept { + return _grad_pos->read(index); + } + UInt push(Expr position, Expr beta, Expr wi, Expr pixel_id, Expr surface_tag) { + auto index = _tot->atomic(0u).fetch_add(1u); + _wo->write(index, wi); + _position->write(index, position); + _pixel_id->write(index, pixel_id); + _surface_tags->write(index, surface_tag); + _beta3->write(index, beta); + for (auto i = 0u; i < 3u; ++i) + _grid_min->atomic(i).fetch_min(position[i]); + for (auto i = 0u; i < 3u; ++i) + _grid_max->atomic(i).fetch_max(position[i]); + _nxt->write(index, 0u); + return index; + } + void set_grad_pos(Expr index, Expr grad) { + _grad_pos->write(index, grad); + } + //from uint3 grid id to hash index of the grid + auto grid_to_index(Expr p) const noexcept { + auto hash = ((p.x * 73856093) ^ (p.y * 19349663) ^ + (p.z * 83492791)) % + (_size); + return (hash + _size) % _size; + } + //from float3 position to uint3 grid id + auto point_to_grid(Expr p) const noexcept { + Float3 grid_min = {_grid_min->read(0), + _grid_min->read(1), + _grid_min->read(2)}; + return make_int3((p - grid_min) / grid_len()) + make_int3(2, 2, 2); + } + auto point_to_index(Expr p) const noexcept { + return grid_to_index(point_to_grid(p)); + } + + void link(Expr index) { + auto p = _position->read(index); + auto grid_index = point_to_index(p); + auto head = _grid_head->atomic(grid_index).exchange(index); + _nxt->write(index, head); + } + + void reset(Expr index) { + _grid_head->write(index, ~0u); + _tot->write(0, 0u); + _nxt->write(index, ~0u); + for (auto i = 0u; i < 3u; ++i) { + _grid_min->write(i, std::numeric_limits::max()); + _grid_max->write(i, -std::numeric_limits::max()); + } + } + void write_grid_len(Expr len) { + _grid_len->write(0u, len); + } + auto split(Expr grid_count) const noexcept { + auto _grid_size = _spectrum->pipeline().geometry()->world_max() - _spectrum->pipeline().geometry()->world_min(); + return min(min(_grid_size.x / grid_count, _grid_size.y / grid_count), _grid_size.z / grid_count); + } +}; +class PixelIndirect { +public: + Buffer _radius; + Buffer _cur_n; + Buffer _n_photon; + Buffer _phi; + Buffer _tau; + Buffer _weight; + const Spectrum::Instance *_spectrum; + bool _shared_radius; + uint _viewpoint_per_iter; + float _clamp; + +public: + PixelIndirect(uint viewpoint_per_iter, const Spectrum::Instance *spectrum) { + _spectrum = spectrum; + _clamp = 1024.0; + auto device = spectrum->pipeline().device(); + auto dimension = 3u;//always save rgb + _shared_radius = true; + if (_shared_radius) { + _radius = device.create_buffer(1); + _cur_n = device.create_buffer(1); + _n_photon = device.create_buffer(1); + } else { + _radius = device.create_buffer(viewpoint_per_iter); + _cur_n = device.create_buffer(viewpoint_per_iter); + _n_photon = device.create_buffer(viewpoint_per_iter); + } + _phi = device.create_buffer(viewpoint_per_iter * dimension); + _tau = device.create_buffer(viewpoint_per_iter * dimension); + _weight = device.create_buffer(viewpoint_per_iter); + _viewpoint_per_iter = viewpoint_per_iter; + } + void write_radius(Expr pixel_id, Expr value) noexcept { + if (!_shared_radius) { + _radius->write(pixel_id, value); + } else { + _radius->write(0u, value); + } + } + void write_cur_n(Expr pixel_id, Expr value) noexcept { + if (!_shared_radius) { + _cur_n->write(pixel_id, value); + } else { + _cur_n->write(0u, value); + } + } + + void write_n_photon(Expr pixel_id, Expr value) noexcept { + if (!_shared_radius) { + _n_photon->write(pixel_id, value); + } else { + _n_photon->write(0u, value); + } + } + + void reset_phi(Expr pixel_id) noexcept { + auto dimension = 3u; + for (auto i = 0u; i < dimension; ++i) + _phi->write(pixel_id * dimension + i, 0.f); + } + + void reset_tau(Expr pixel_id) noexcept { + auto dimension = 3u; + for (auto i = 0u; i < dimension; ++i) + _tau->write(pixel_id * dimension + i, 0.f); + } + + auto radius(Expr pixel_id) const noexcept { + if (!_shared_radius) { + return _radius->read(pixel_id); + } else { + return _radius->read(0u); + } + } + + //tau=(tau+clamp(phi))*value, see pixel_info_update for useage + void update_tau(Expr pixel_id, Expr value) noexcept { + auto dimension = 3u; + auto thershold = _clamp; + for (auto i = 0u; i < dimension; ++i) { + auto old_tau = _tau->read(pixel_id * dimension + i); + auto phi = _phi->read(pixel_id * dimension + i); + phi = max(-thershold, min(phi, thershold));//-thershold for wavelength sampling + _tau->write(pixel_id * dimension + i, (old_tau + phi) * value); + } + } + + auto n_photon(Expr pixel_id) const noexcept { + if (!_shared_radius) { + return _n_photon->read(pixel_id); + } else { + return _n_photon->read(0u); + } + } + + auto cur_n(Expr pixel_id) const noexcept { + if (!_shared_radius) { + return _cur_n->read(pixel_id); + } else { + return _cur_n->read(0u); + } + } + + + auto phi(Expr pixel_id) const noexcept { + auto dimension = 3u; + Float3 ret; + for (auto i = 0u; i < dimension; ++i) + ret[i] = _phi->read(pixel_id * dimension + i); + return ret; + } + + auto tau(Expr pixel_id) const noexcept { + auto dimension = 3u; + Float3 ret; + for (auto i = 0u; i < dimension; ++i) + ret[i] = _tau->read(pixel_id * dimension + i); + return ret; + } + + void add_cur_n(Expr pixel_id, Expr value) noexcept { + if (!_shared_radius) { + _cur_n->atomic(pixel_id).fetch_add(value); + } else { + _cur_n->atomic(0u).fetch_add(value); + } + } + + void add_phi(Expr pixel_id, Expr phi) noexcept { + auto dimension = 3u; + for (auto i = 0u; i < dimension; ++i) + _phi->atomic(pixel_id * dimension + i).fetch_add(phi[i]); + } + + void pixel_info_update(Expr pixel_id) { + $if(cur_n(pixel_id) > 0) { + Float gamma = 2.0f / 3.0f; + UInt n_new = n_photon(pixel_id) + cur_n(pixel_id); + Float r_new = radius(pixel_id) * sqrt(n_new * gamma / (n_photon(pixel_id) * gamma + cur_n(pixel_id))); + //indirect->write_tau(pixel_id, (indirect->tau(pixel_id) + indirect->phi(pixel_id)) * (r_new * r_new) / (indirect->radius(pixel_id) * indirect->radius(pixel_id))); + update_tau(pixel_id, r_new * r_new / (radius(pixel_id) * radius(pixel_id))); + if (!_shared_radius) { + write_n_photon(pixel_id, n_new); + write_cur_n(pixel_id, 0u); + write_radius(pixel_id, r_new); + } + reset_phi(pixel_id); + }; + } + + void shared_update() { + auto pixel_id = 0u; + $if(cur_n(pixel_id) > 0) { + Float gamma = 2.0f / 3.0f; + UInt n_new = n_photon(pixel_id) + cur_n(pixel_id); + Float r_new = radius(pixel_id) * sqrt(n_new * gamma / (n_photon(pixel_id) * gamma + cur_n(pixel_id))); + write_n_photon(pixel_id, n_new); + write_cur_n(pixel_id, 0u); + write_radius(pixel_id, r_new); + }; + } +}; + +unique_ptr indirect; +unique_ptr viewpoint_map; + PYBIND11_MODULE(_lrapi, m) { m.doc() = "LuisaRender API";// optional module docstring // log @@ -173,6 +475,257 @@ PYBIND11_MODULE(_lrapi, m) { log_level_info(); LUISA_INFO("LuisaRender API init"); }); + m.def("init_viewpointmap", [](uint viewpoints, float radius) { + LUISA_INFO("LuisaRender init_viewpointmap"); + viewpoint_map = make_unique(viewpoints, scene_python._pipeline->spectrum(), radius); + indirect = make_unique(viewpoints, scene_python._pipeline->spectrum()); + + Kernel1D viewpointreset_kernel = [&]() noexcept { + auto index = static_cast(dispatch_x()); + viewpoint_map->reset(index); + }; + + Kernel1D indirect_initialize_kernel = [&]() noexcept { + auto index = static_cast(dispatch_x()); + indirect->write_radius(index, radius); + viewpoint_map->write_grid_len(radius); + indirect->write_cur_n(index, 0u); + indirect->write_n_photon(index, 0u); + indirect->reset_phi(index); + indirect->reset_tau(index); + }; + auto viewpointreset = scene_python._pipeline->device().compile(viewpointreset_kernel); + auto indirect_initialize = scene_python._pipeline->device().compile(indirect_initialize_kernel); + *scene_python._stream << viewpointreset().dispatch(viewpoints); + *scene_python._stream << indirect_initialize().dispatch(viewpoints); + *scene_python._stream << synchronize(); + + }); + m.def("add_viewpoint", [](uint64_t pos_ptr, uint64_t wi_ptr, uint64_t beta_ptr, uint size, bool debug) { + + auto pos_buffer = scene_python._pipeline->device().import_external_buffer(reinterpret_cast(pos_ptr),size*3); + auto wi_buffer = scene_python._pipeline->device().import_external_buffer(reinterpret_cast(wi_ptr),size*3); + auto beta_buffer = scene_python._pipeline->device().import_external_buffer(reinterpret_cast(beta_ptr),size*3); + + Kernel1D viewpointreset_kernel = [&]() noexcept { + auto index = static_cast(dispatch_x()); + viewpoint_map->reset(index); + }; + Kernel1D add_viewpoint_kernel = [&](Bool debug) noexcept { + auto index = static_cast(dispatch_x()); + auto pos = make_float3(pos_buffer->read(index*3+0),pos_buffer->read(index*3+1),pos_buffer->read(index*3+2)); + auto wi = make_float3(wi_buffer->read(index*3+0),wi_buffer->read(index*3+1),wi_buffer->read(index*3+2)); + auto beta = make_float3(beta_buffer->read(index*3+0),beta_buffer->read(index*3+1),beta_buffer->read(index*3+2)); + $if(pos[0]>-500.f) + { + $if(debug) + { + device_log("index {} pos: {}, wi: {}, beta: {}",index, pos, wi, beta); + }; + viewpoint_map->push(pos, beta, wi, index, 0u); + }; + //device_log("index {} pos: {}, wi: {}, beta: {}",index, pos, wi, beta); + }; + + Kernel1D build_grid_kernel = [&]() noexcept { + auto index = static_cast(dispatch_x()); + $if(viewpoint_map->nxt(index) == 0u) { + viewpoint_map->link(index); + }; + }; + + auto viewpointreset = scene_python._pipeline->device().compile(viewpointreset_kernel); + *scene_python._stream << viewpointreset().dispatch(viewpoint_map->size()) << synchronize(); + + auto add_viewpoint = scene_python._device->compile(add_viewpoint_kernel); + auto build_grid = scene_python._device->compile(build_grid_kernel); + + *scene_python._stream << add_viewpoint(debug).dispatch(size) << synchronize(); + LUISA_INFO("LuisaRender add_viewpoint"); + + *scene_python._stream << build_grid().dispatch(size) << synchronize(); + LUISA_INFO("LuisaRender build_grid"); + }); + + m.def("indirect_update", []() { + LUISA_INFO("LuisaRender indirect_update"); + Kernel1D indirect_update_kernel = [&]() noexcept { + set_block_size(16u, 16u, 1u); + auto pixel_id = dispatch_x(); + indirect->pixel_info_update(pixel_id); + }; + + Kernel1D shared_update_kernel = [&]() noexcept { + indirect->shared_update(); + viewpoint_map->write_grid_len(indirect->radius(0u)); + }; + + auto indirect_update = scene_python._device->compile(indirect_update_kernel); + auto shared_update = scene_python._device->compile(shared_update_kernel); + + *scene_python._stream << indirect_update().dispatch(viewpoint_map->size()); + *scene_python._stream << shared_update().dispatch(1u) << synchronize(); + }); + + m.def("get_indirect", [](uint64_t buffer_ptr, uint size, uint tot_photon, bool debug) { + LUISA_INFO("LuisaRender get_indirect"); + auto ind_buffer = scene_python._pipeline->device().import_external_buffer(reinterpret_cast(buffer_ptr),size*3); + Kernel1D indirect_draw_kernel = [&](Bool debug) noexcept { + auto index = dispatch_x(); + auto r = indirect->radius(index); + auto tau = indirect->tau(index); + auto L = tau / (tot_photon * pi * r * r); + $if(debug) + { + device_log("index {} tau: {}, L: {}, r: {}",index, tau, L, r); + }; + ind_buffer->write(index*3+0, L[0]); + ind_buffer->write(index*3+1, L[1]); + ind_buffer->write(index*3+2, L[2]); + //camera->film()->accumulate(pixel_id, L, 0.5f * spp); + }; + auto indirect_draw = scene_python._device->compile(indirect_draw_kernel); + *scene_python._stream << indirect_draw(debug).dispatch(size) << synchronize(); + //return reinterpret_cast(ind_buffer.native_handle()); + }); + + m.def("update_grad", [](uint64_t grad_buffer_ptr, uint size, bool debug) { + LUISA_INFO("LuisaRender update_grad"); + auto grad_buffer = scene_python._pipeline->device().import_external_buffer(reinterpret_cast(grad_buffer_ptr),size*3); + Kernel1D update_grad_kernel = [&](Bool debug) noexcept { + auto index = dispatch_x(); + auto grad = make_float3(grad_buffer->read(index*3+0),grad_buffer->read(index*3+1),grad_buffer->read(index*3+2)); + $if(debug){ + device_log("index {} grad: {}",index, grad); + }; + viewpoint_map->set_grad_pos(index, grad); + }; + auto update_grad = scene_python._device->compile(update_grad_kernel); + *scene_python._stream << update_grad(debug).dispatch(size) << synchronize(); + }); + + m.def("accum_ind", [](uint64_t pos_ptr,uint64_t wi_ptr, uint64_t beta_ptr, uint size, bool debug) { + + LUISA_INFO("LuisaRender accum ind"); + auto pos_buffer = scene_python._pipeline->device().import_external_buffer(reinterpret_cast(pos_ptr),size*3); + auto wi_buffer = scene_python._pipeline->device().import_external_buffer(reinterpret_cast(wi_ptr),size*3); + auto beta_buffer = scene_python._pipeline->device().import_external_buffer(reinterpret_cast(beta_ptr),size*3); + + Kernel1D query_kernel = [&](Bool debug) noexcept{ + auto index = dispatch_x(); + + auto pos = make_float3(pos_buffer->read(index*3+0),pos_buffer->read(index*3+1),pos_buffer->read(index*3+2)); + auto wi_local = make_float3(wi_buffer->read(index*3+0),wi_buffer->read(index*3+1),wi_buffer->read(index*3+2)); + auto beta = make_float3(beta_buffer->read(index*3+0),beta_buffer->read(index*3+1),beta_buffer->read(index*3+2)); + + auto grid = viewpoint_map->point_to_grid(pos); + $if(debug){ + device_log("index {} pos: {}, wi: {}, beta: {} grid {}",index, pos, wi_local, beta, grid); + }; + auto radius = viewpoint_map->radius; + Float3 ind{0.0f, 0.0f, 0.0f}; + $for(x, grid.x - 1, grid.x + 2) { + $for(y, grid.y - 1, grid.y + 2) { + $for(z, grid.z - 1, grid.z + 2) { + Int3 check_grid{x, y, z}; + auto viewpoint_index = viewpoint_map->grid_head(viewpoint_map->grid_to_index(check_grid)); + $if(debug){ + device_log("index {} viewpoint_index: ",index, viewpoint_index); + }; + $while(viewpoint_index != ~0u) { + auto position = viewpoint_map->position(viewpoint_index); + auto pixel_id = viewpoint_map->pixel_id(viewpoint_index); + auto dis = distance(position, pos); + $if(dis <= radius) { + auto viewpointwo = viewpoint_map->wo(viewpoint_index); + auto viewpointbeta = viewpoint_map->beta(viewpoint_index); + auto rel_dis = dis / radius; + auto weight = 3.5f*(1.0f- 6 * pow(rel_dis, 5.) + 15 * pow(rel_dis, 4.) - 10 * pow(rel_dis, 3.)); + auto Phi = viewpointbeta*beta*weight/max(0.01f,abs_cos_theta(wi_local)); + indirect->add_phi(pixel_id, Phi); + indirect->add_cur_n(pixel_id, 1u); + $if(debug){ + device_log("index {} pos: {}, wi: {}, beta: {}, weight: {}, Phi: {}, pixel_id {}",index, pos, wi_local, beta, weight, Phi, pixel_id); + }; + }; + viewpoint_index = viewpoint_map->nxt(viewpoint_index); + }; + }; + }; + }; + // pos_buffer->write(index*3+0, ind[0]/(3.1415926f*radius*radius)); + // pos_buffer->write(index*3+1, ind[1]/(3.1415926f*radius*radius)); + // pos_buffer->write(index*3+2, ind[2]/(3.1415926f*radius*radius)); + }; + auto query_ind = scene_python._device->compile(query_kernel); + *scene_python._stream << query_ind(debug).dispatch(size) << synchronize(); + // return reinterpret_cast(pos_buffer.native_handle()); + }); + + m.def("compute_ind_grad", [](uint64_t pos_ptr,uint64_t wi_ptr, uint64_t beta_ptr, uint size, uint tot_photon) { + + LUISA_INFO("LuisaRender compute_ind_grad"); + auto pos_buffer = scene_python._pipeline->device().import_external_buffer(reinterpret_cast(pos_ptr),size*3); + auto wi_buffer = scene_python._pipeline->device().import_external_buffer(reinterpret_cast(wi_ptr),size*3); + auto beta_buffer = scene_python._pipeline->device().import_external_buffer(reinterpret_cast(beta_ptr),size*3); + + Kernel1D compute_kernel = [&]() noexcept{ + auto index = dispatch_x(); + + auto pos = make_float3(pos_buffer->read(index*3+0),pos_buffer->read(index*3+1),pos_buffer->read(index*3+2)); + auto wi_local = make_float3(wi_buffer->read(index*3+0),wi_buffer->read(index*3+1),wi_buffer->read(index*3+2)); + auto beta = make_float3(beta_buffer->read(index*3+0),beta_buffer->read(index*3+1),beta_buffer->read(index*3+2)); + + auto grid = viewpoint_map->point_to_grid(pos); + Float3 grad_pos{0.0f, 0.0f, 0.0f}; + Float3 grad_beta{0.0f, 0.0f, 0.0f}; + Float grad_dis{0.0f}; + $for(x, grid.x - 1, grid.x + 2) { + $for(y, grid.y - 1, grid.y + 2) { + $for(z, grid.z - 1, grid.z + 2) { + Int3 check_grid{x, y, z}; + auto viewpoint_index = viewpoint_map->grid_head(viewpoint_map->grid_to_index(check_grid)); + $while(viewpoint_index != ~0u) { + auto position = viewpoint_map->position(viewpoint_index); + auto pixel_id = viewpoint_map->pixel_id(viewpoint_index); + auto radius = indirect->radius(pixel_id); + auto dis = distance(position, pos); + $if(dis <= radius) { + auto viewpointwo = viewpoint_map->wo(viewpoint_index); + auto viewpointbeta = viewpoint_map->beta(viewpoint_index); + auto grad_view = viewpoint_map->grad_pos(pixel_id); + auto Phi = viewpointbeta/max(0.01f,abs_cos_theta(wi_local)); + $autodiff { + requires_grad(pos, beta); + auto rel_dis = distance(position, pos) / radius; + requires_grad(rel_dis); + auto rel3 = rel_dis*rel_dis*rel_dis; + auto weight = 3.5f*(1- 6*rel3*rel_dis*rel_dis + 15*rel3*rel_dis - 10*rel3); + auto Phi_beta_weight = Phi * beta * weight; + auto contrib = Phi_beta_weight / (tot_photon * pi * radius * radius); + auto dldPhi = (contrib[0u]*grad_view[0] + contrib[1u]*grad_view[1] + contrib[2u]*grad_view[2]); + backward(dldPhi); + grad_pos += grad(pos); + grad_beta += grad(beta); + grad_dis = grad(rel_dis); + }; + }; + viewpoint_index = viewpoint_map->nxt(viewpoint_index); + }; + }; + }; + }; + pos_buffer->write(index*3+0, grad_pos[0]); + pos_buffer->write(index*3+0, grad_pos[1]); + pos_buffer->write(index*3+0, grad_pos[2]); + beta_buffer->write(index*3+0, grad_beta[0]); + beta_buffer->write(index*3+0, grad_beta[1]); + beta_buffer->write(index*3+0, grad_beta[2]); + }; + auto compute_grad = scene_python._device->compile(compute_kernel); + *scene_python._stream << compute_grad().dispatch(size) << synchronize(); + }); + m.def("load_scene", [](std::vector &argvs){ int argc = argvs.size(); LUISA_INFO("Argc: {}", argc); @@ -354,6 +907,6 @@ PYBIND11_MODULE(_lrapi, m) { // .def("render", &Pipeline::render); // .def("update_texture", &Pipeline::update_texture); // .def("update_mesh", &Pipeline::update_mesh); - + } diff --git a/src/tests/outputs/backwarde_render_0.exr b/src/tests/outputs/backwarde_render_0.exr deleted file mode 100644 index 8166ac7a..00000000 Binary files a/src/tests/outputs/backwarde_render_0.exr and /dev/null differ diff --git a/src/tests/outputs/render0.exr b/src/tests/outputs/render0.exr deleted file mode 100644 index 980638cf..00000000 Binary files a/src/tests/outputs/render0.exr and /dev/null differ diff --git a/src/tests/test_ad_torch.py b/src/tests/test_ad_torch.py index d51c4ffc..0799e7bd 100644 --- a/src/tests/test_ad_torch.py +++ b/src/tests/test_ad_torch.py @@ -68,7 +68,7 @@ def compute_vertex_normals(vertex_pos, face_ids): vertex_height.requires_grad_() -vertex_pos[...,1] = ((vertex_pos[...,1]-1)*0.05)+1 +#vertex_pos[...,1] = ((vertex_pos[...,1]-1)*0.05)+1 gt_param = vertex_pos[...,1].clone() vertex_normal = compute_vertex_normals(vertex_pos, face_ids_torch) vertex[...,0:3] = vertex_pos @@ -86,7 +86,7 @@ def compute_vertex_normals(vertex_pos, face_ids): target_img = cu_device_ptr_to_torch_tensor(luisarender.render()[0], (512, 512, 4)).clone() imageio.imwrite("gt_0.05.exr",target_img.detach().cpu().numpy()[...,:3]) imageio.imwrite("gt.png",target_img.detach().cpu().numpy()[...,:3]) - +exit() #print(torch.max(target_img), torch.min(target_img), torch.sum(target_img))