Skip to content

Commit

Permalink
Merge branch 'master' into OptixBSDF
Browse files Browse the repository at this point in the history
  • Loading branch information
teachmain committed Oct 12, 2023
2 parents c1e15f7 + 393f30e commit ab207be
Show file tree
Hide file tree
Showing 289 changed files with 18,422 additions and 2,341 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ option(ZENO_INSTALL_TARGET "Enable installation targets" OFF)
option(ZENO_WITH_CUDA "Build ZENO with CUDA support" OFF)
option(ZENO_MARCH_NATIVE "Build ZENO with -march=native" OFF)
option(ZENO_USE_FAST_MATH "Build ZENO with -ffast-math" OFF)
option(ZENO_OPTIX_PROC "Optix with a new proc" OFF)

if (NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
# Otherwise we can't link .so libs with .a libs
Expand Down
2 changes: 1 addition & 1 deletion projects/CuLagrange/fem/FleshDynamicStepping.cu
Original file line number Diff line number Diff line change
Expand Up @@ -2315,7 +2315,7 @@ struct FleshDynamicStepping : INode {
auto inds = gh_buffer.pack(dim_c<4>,"inds",ei).reinterpret_bits(int_c);
for(int i = 0;i != 4;++i)
if(inds[i] < 0 || inds[i] >= vsize)
printf("negative sttemp inds : %d %d %d\n",inds[0],inds[1],inds[2],inds[3]);
printf("negative sttemp inds : %d %d %d, %d\n",inds[0],inds[1],inds[2],inds[3]);
auto H = gh_buffer.pack(dim_c<12,12>,"H",ei);
update_hessian(spmat,inds,H,true);
});
Expand Down
28 changes: 16 additions & 12 deletions projects/CuLagrange/fem/collision_energy/evaluate_collision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,7 @@ void calc_continous_self_PT_collision_impulse(Pol& pol,
else
triCCDBvh.build(pol,bvs);

auto execTag = wrapv<space>{};
pol(zs::range(verts.size()),[
invMass = proxy<space>({},invMass),
xtag = xtag,
Expand All @@ -1309,7 +1310,7 @@ void calc_continous_self_PT_collision_impulse(Pol& pol,
impulse_buffer = proxy<space>(impulse_buffer),
impulse_count = proxy<space>(impulse_count),
eps = eps,
exec_tag = wrapv<space>{},
execTag,
bvh = proxy<space>(triCCDBvh)] ZS_LAMBDA(int vi) mutable {
auto p = verts.pack(dim_c<3>,xtag,vi);
auto v = verts.pack(dim_c<3>,vtag,vi);
Expand Down Expand Up @@ -1392,9 +1393,9 @@ void calc_continous_self_PT_collision_impulse(Pol& pol,

for(int i = 0;i != 4;++i) {
auto beta = (bary[i] * invMass("minv",inds[i])) / cm;
atomic_add(exec_tag,&impulse_count[inds[i]],1);
atomic_add(execTag,&impulse_count[inds[i]],1);
for(int d = 0;d != 3;++d)
atomic_add(exec_tag,&impulse_buffer[inds[i]][d],impulse[d] * beta);
atomic_add(execTag,&impulse_buffer[inds[i]][d],impulse[d] * beta);
}
};
bvh.iter_neighbors(bv,do_close_proximity_detection);
Expand Down Expand Up @@ -1435,6 +1436,7 @@ void calc_continous_self_EE_collision_impulse(Pol& pol,
else
edgeCCDBvh.build(pol,edgeBvs);

auto execTag = wrapv<space>{};
pol(zs::range(edges.size()),[
xtag = xtag,
vtag = vtag,
Expand All @@ -1445,7 +1447,7 @@ void calc_continous_self_EE_collision_impulse(Pol& pol,
impulse_count = proxy<space>(impulse_count),
// thickness = thickness,
eps = eps,
exec_tag = wrapv<space>{},
execTag,
edgeBvs = proxy<space>(edgeBvs),
bvh = proxy<space>(edgeCCDBvh)] ZS_LAMBDA(int ei) mutable {
auto ea = edges.pack(dim_c<2>,"inds",ei,int_c);
Expand Down Expand Up @@ -1541,9 +1543,9 @@ void calc_continous_self_EE_collision_impulse(Pol& pol,
if(!compute_continous_EE_collision_impulse(ps,vs,minvs,imps))
return;
for(int i = 0;i != 4;++i) {
atomic_add(exec_tag,&impulse_count[inds[i]],1);
atomic_add(execTag,&impulse_count[inds[i]],1);
for(int d = 0;d != 3;++d)
atomic_add(exec_tag,&impulse_buffer[inds[i]][d],imps[i][d]);
atomic_add(execTag,&impulse_buffer[inds[i]][d],imps[i][d]);
}
#endif
};
Expand Down Expand Up @@ -1572,15 +1574,17 @@ void apply_impulse(Pol& pol,
zs::Vector<int> impulse_count{verts.get_allocator(),verts.size()};
pol(zs::range(impulse_count),[] ZS_LAMBDA(auto& c) mutable {c = 0;});

auto execTag = wrapv<space>{};
pol(zs::range(imminent_collision_buffer.size()),[
verts = proxy<space>({},verts),
vtag = zs::SmallString(vtag),
imminent_collision_buffer = proxy<space>({},imminent_collision_buffer),
exec_tag = wrapv<space>{},
execTag,
eps = eps,
restitution_rate = imminent_restitution_rate,
impulse_count = proxy<space>(impulse_count),
impulse_buffer = proxy<space>(impulse_buffer)] ZS_LAMBDA(auto ci) mutable {
impulse_buffer = proxy<space>(impulse_buffer)
] ZS_LAMBDA(auto ci) mutable {
auto inds = imminent_collision_buffer.pack(dim_c<4>,"inds",ci,int_c);
auto bary = imminent_collision_buffer.pack(dim_c<4>,"bary",ci);
auto impulse = imminent_collision_buffer.pack(dim_c<3>,"impulse",ci);
Expand All @@ -1594,9 +1598,9 @@ void apply_impulse(Pol& pol,

for(int i = 0;i != 4;++i) {
auto beta = verts("minv",inds[i]) * bary[i] / cminv;
atomic_add(exec_tag,&impulse_count[inds[i]],1);
atomic_add(execTag,&impulse_count[inds[i]],1);
for(int d = 0;d != 3;++d)
atomic_add(exec_tag,&impulse_buffer[inds[i]][d],impulse[d] * beta);
atomic_add(execTag,&impulse_buffer[inds[i]][d],impulse[d] * beta);
}

});
Expand All @@ -1607,14 +1611,14 @@ void apply_impulse(Pol& pol,
impulse_count = proxy<space>(impulse_count),
relaxation_rate = imminent_relaxation_rate,
eps = eps,
exec_tag = wrapv<space>{}] ZS_LAMBDA(int vi) mutable {
execTag] ZS_LAMBDA(int vi) mutable {
if(impulse_buffer[vi].norm() < eps || impulse_count[vi] == 0)
return;
auto impulse = relaxation_rate * impulse_buffer[vi] / (T)impulse_count[vi];
// auto dp = impulse * verts("minv",vi);

for(int i = 0;i != 3;++i)
atomic_add(exec_tag,&verts(vtag,i,vi),impulse[i]);
atomic_add(execTag,&verts(vtag,i,vi),impulse[i]);
});
}

Expand Down
2 changes: 1 addition & 1 deletion projects/CuLagrange/geometry/Topology.cu
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ struct VisualTetrahedraHalfFacet : zeno::INode {
auto opposite_hf_idx = zs::reinterpret_bits<int>(halfFacet("opposite_hf",hf_idx));
if(opposite_hf_idx >= 0) {
if(opposite_hf_idx >= halfFacet.size()) {
printf("opposite_hf_idx = %d exceeding size of halfFacet : %d\n",opposite_hf_idx,halfFacet.size());
printf("opposite_hf_idx = %d exceeding size of halfFacet : %d\n", (int)opposite_hf_idx, (int)halfFacet.size());
return;
}
auto nti = zs::reinterpret_bits<int>(halfFacet("to_tet",opposite_hf_idx));
Expand Down
6 changes: 3 additions & 3 deletions projects/CuLagrange/geometry/kernel/geo_math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ namespace zeno { namespace LSL_GEO {
return (costheta / sintheta);
}

template<typename DREAL,typename VecT, zs::enable_if_all<VecT::dim == 1, (VecT::extent <= 3), (VecT::extent > 1)> = 0,typename REAL = VecT::value_type>
template<typename DREAL,typename VecT, zs::enable_if_all<VecT::dim == 1, (VecT::extent <= 3), (VecT::extent > 1)> = 0,typename REAL = typename VecT::value_type>
constexpr auto cotTheta(const zs::VecInterface<VecT>& e0,const zs::VecInterface<VecT>& e1){
auto de0 = e0.cast<DREAL>();
auto de1 = e1.cast<DREAL>();
auto de0 = e0.template cast<DREAL>();
auto de1 = e1.template cast<DREAL>();
auto costheta = de0.dot(de1);
auto sintheta = de0.cross(de1).norm();
return (REAL)(costheta / sintheta);
Expand Down
5 changes: 3 additions & 2 deletions projects/CuLagrange/geometry/kernel/intersection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1969,7 +1969,8 @@ int do_global_self_intersection_analysis_on_surface_mesh_info(Pol& pol,
r = LSL_GEO::tri_ray_intersect(v1[j],e1s[j],v0[0],v0[1],v0[2]);
if(r < (T)(1.0)) {
e1_indices[nm_e1_its] = j;
e1_its[nm_e1_its] = v1[i] + e1s[j] * r;
/// @note both these should be 'j'
e1_its[nm_e1_its] = v1[j] + e1s[j] * r;
++nm_e1_its;
}
}
Expand Down Expand Up @@ -3462,7 +3463,7 @@ int do_global_intersection_analysis_with_connected_manifolds(Pol& pol,
auto hi = key[0];
auto no = halfedges_tab.query(hi);
if(no >= closestTriID.size()) {
printf("closestTriID overflow : %d %d\n",no,closestTriID.size());
printf("closestTriID overflow : %d %d\n",(int)no, (int)closestTriID.size());
return;
}
auto cti = closestTriID[no];
Expand Down
2 changes: 1 addition & 1 deletion projects/CuLagrange/geometry/kernel/topology.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ namespace zeno {
constexpr auto CODIM = VecTi::extent;
constexpr auto NM_EDGES = (CODIM - 1) * (CODIM) / 2;

zs::vec<Ti,2> out_edges[NM_EDGES] = {};
zs::vec<zs::vec<Ti,2>, NM_EDGES> out_edges{};
int nm_out_edges = 0;
for(int i = 0;i != CODIM;++i)
for(int j = i + 1;j != CODIM;++j)
Expand Down
14 changes: 6 additions & 8 deletions projects/CuLagrange/mpm/Generation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ struct PoissonDiskSample : INode {
}
};
ZENDEFNODE(PoissonDiskSample, {
{"VDBGrid", {"float", "dx", "0.1"}, {"float", "ppc", "8"}},
{"VDBGrid", {"float", "dx", "0.1"}, {"float", "ppc", "8"}, {"string", "path", ""}},
{"prim"},
{{"string", "path", ""}},
{},
{"MPM"},
});

Expand All @@ -94,17 +94,15 @@ struct ZSPoissonDiskSample : INode {
using LsT = RM_CVREF_T(ls);
if constexpr (is_same_v<LsT, typename ZenoLevelSet::basic_ls_t>) {
auto &field = ls._ls;
match(
[&sampled = sampled, dx = dx,
ppc = ppc](auto &lsPtr) -> std::enable_if_t<is_spls_v<typename RM_CVREF_T(lsPtr)::element_type>> {
match([&sampled = sampled, dx = dx, ppc = ppc](auto &lsPtr) {
if constexpr (is_spls_v<typename RM_CVREF_T(lsPtr)::element_type>) {
const auto &ls = *lsPtr;
const auto &spls = ls.memspace() != memsrc_e::host ? ls.clone({memsrc_e::host, -1}) : ls;
sampled = zs::sample_from_levelset(zs::proxy<zs::execspace_e::openmp>(spls), dx, ppc);
},
[](auto &lsPtr) -> std::enable_if_t<!is_spls_v<typename RM_CVREF_T(lsPtr)::element_type>> {
} else
throw std::runtime_error(
fmt::format("levelset type [{}] not supported in sampling.", zs::get_var_type_str(lsPtr)));
})(field);
})(field);
} else if constexpr (is_same_v<LsT, typename ZenoLevelSet::const_sdf_vel_ls_t>) {
match([&sampled = sampled, dx = dx, ppc = ppc](auto lsv) {
sampled = zs::sample_from_levelset(SdfVelFieldView{lsv}, dx, ppc);
Expand Down
34 changes: 17 additions & 17 deletions projects/CuLagrange/pbd/constraint_function_kernel/constraint.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace zeno { namespace CONSTRAINT {
return true;
}

template<typename VECTOR3d,typename SCALER = VECTOR3d::value_type>
template<typename VECTOR3d,typename SCALER = typename VECTOR3d::value_type>
constexpr bool init_DihedralBendingConstraint(
const VECTOR3d& p0,
const VECTOR3d& p1,
Expand Down Expand Up @@ -229,7 +229,7 @@ namespace zeno { namespace CONSTRAINT {
return true;
}

template<typename VECTOR3d,typename SCALER = VECTOR3d::value_type>
template<typename VECTOR3d,typename SCALER = typename VECTOR3d::value_type>
constexpr bool solve_DihedralConstraint(
const VECTOR3d& p0, const SCALER& invMass0,
const VECTOR3d& p1, const SCALER& invMass1,
Expand Down Expand Up @@ -310,24 +310,24 @@ namespace zeno { namespace CONSTRAINT {
const VECTOR3d x[4] = { p2, p3, p0, p1 };
// Q = MATRIX4d::uniform(0);

// const auto e0 = x[1].cast<double>() - x[0].cast<double>();
// const auto e1 = x[2].cast<double>() - x[0].cast<double>();
// const auto e2 = x[3].cast<double>() - x[0].cast<double>();
// const auto e3 = x[2].cast<double>() - x[1].cast<double>();
// const auto e4 = x[3].cast<double>() - x[1].cast<double>();
// const auto e0 = x[1].template cast<double>() - x[0].template cast<double>();
// const auto e1 = x[2].template cast<double>() - x[0].template cast<double>();
// const auto e2 = x[3].template cast<double>() - x[0].template cast<double>();
// const auto e3 = x[2].template cast<double>() - x[1].template cast<double>();
// const auto e4 = x[3].template cast<double>() - x[1].template cast<double>();

const auto e0 = x[1].cast<double>() - x[0].cast<double>();
const auto e1 = x[2].cast<double>() - x[0].cast<double>();
const auto e2 = x[3].cast<double>() - x[0].cast<double>();
const auto e3 = x[2].cast<double>() - x[1].cast<double>();
const auto e4 = x[3].cast<double>() - x[1].cast<double>();
const auto e0 = x[1].template cast<double>() - x[0].template cast<double>();
const auto e1 = x[2].template cast<double>() - x[0].template cast<double>();
const auto e2 = x[3].template cast<double>() - x[0].template cast<double>();
const auto e3 = x[2].template cast<double>() - x[1].template cast<double>();
const auto e4 = x[3].template cast<double>() - x[1].template cast<double>();


// auto e0 = e0_.cast<double>();
// auto e1 = e1_.cast<double>();
// auto e2 = e2_.cast<double>();
// auto e3 = e3_.cast<double>();
// auto e4 = e4_.cast<double>();
// auto e0 = e0_.template cast<double>();
// auto e1 = e1_.template cast<double>();
// auto e2 = e2_.template cast<double>();
// auto e3 = e3_.template cast<double>();
// auto e4 = e4_.template cast<double>();

// printf("init isometric bending energy : %f %f %f %f\n",
// (float)p0.norm(),
Expand Down
2 changes: 2 additions & 0 deletions projects/FBX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ endif()
zeno_add_asset_dir(${DEM_DIR})
configure_file(zeno_FBX_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/confinc/zeno_FBX_config.h @ONLY)
target_include_directories(zeno PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/confinc)

execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/dem-bones-bin/models ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/models)
18 changes: 17 additions & 1 deletion projects/FBX/MayaCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,15 @@ struct LightNode : INode {

auto exposure = get_input2<float>("exposure");
auto intensity = get_input2<float>("intensity");
intensity *= pow(2.0, exposure);

auto scaler = powf(2.0f, exposure);

if (std::isnan(scaler) || std::isinf(scaler) || scaler < 0.0f) {
scaler = 1.0f;
printf("Light exposure = %f is invalid, fallback to 0.0 \n", exposure);
}

intensity *= scaler;

auto prim = std::make_shared<zeno::PrimitiveObject>();
auto &verts = prim->verts;
Expand Down Expand Up @@ -301,6 +309,14 @@ struct LightNode : INode {

auto &clr = prim->verts.add_attr<zeno::vec3f>("clr");
auto c = color * intensity;

for (size_t i=0; i<c.size(); ++i) {
if (std::isnan(c[i]) || std::isinf(c[i]) || c[i] < 0.0f) {
c[i] = 1.0f;
printf("Light color component %llu is invalid, fallback to 1.0 \n", i);
}
}

for(int i=0; i<verts.size(); i++){
clr[i] = c;
}
Expand Down
23 changes: 21 additions & 2 deletions projects/SampleModel/LoadSampleModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,32 @@
#include <filesystem>
#include <sstream>
#include <cctype>
#ifdef __linux__
#include <unistd.h>
#include <stdio.h>
#endif

namespace zeno {
namespace {

std::string modelsDir() {
#ifdef __linux__
char path[1024];
getcwd(path, sizeof(path));
auto cur_path = std::string(path);
return cur_path + "/models";
#else
auto cur_path = std::string(_pgmptr);
cur_path = cur_path.substr(0, cur_path.find_last_of("\\"));
return cur_path + "\\models";
#endif
}

struct LoadSampleModel : INode {
virtual void apply() override {
auto name = get_input2<std::string>("name");
auto dir = getAssetDir(MODELS_DIR, name + ".obj");
//auto dir = getAssetDir(MODELS_DIR, name + ".obj");
auto dir = getAssetDir(modelsDir(), name + ".obj"); //temp fix for zeno-727 release
log_info("found sample model path [{}]", dir);
set_output("prim", getThisGraph()->callTempNode("ReadObjPrim", {
{"triangulate:", objectFromLiterial(get_input2<bool>("triangulate"))},
Expand Down Expand Up @@ -62,7 +80,8 @@ struct LoadStringPrim : INode {
std::ostringstream ss;
ss << "ascii/" << std::setw(3) << std::setfill('0') << c << ".obj";
//printf("asdasd %s\n", ss.str().c_str());
auto path = getAssetDir(MODELS_DIR, ss.str());
//auto path = getAssetDir(MODELS_DIR, ss.str());
auto path = getAssetDir(modelsDir(), ss.str()); //temp fix for zeno-727 release
if (!std::filesystem::exists(path)) {
zeno::log_warn("LoadStringPrim got ASCII char not printable: {}", c);
continue;
Expand Down
2 changes: 1 addition & 1 deletion projects/ZenoFX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ target_include_directories(zeno PRIVATE .)

target_link_libraries(zeno PRIVATE $<BUILD_INTERFACE:ZFX>)
target_sources(zeno PRIVATE
nw.cpp pw.cpp pnw.cpp ppw.cpp p2w.cpp pmw.cpp tw.cpp ne.cpp se.cpp FDGather.cpp dbg_printf.h
nw.cpp pw.cpp pnw.cpp ppw.cpp p2w.cpp pmw.cpp tw.cpp ne.cpp se.cpp FDGather.cpp refutils.cpp dbg_printf.h
)

#if (ZENO_WITH_zenvdb)
Expand Down
11 changes: 11 additions & 0 deletions projects/ZenoFX/ne.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "dbg_printf.h"

namespace zeno {
std::string preApplyRefs(const std::string& code, Graph* pGraph);

namespace {
static zfx::Compiler compiler;
static zfx::x64::Assembler assembler;
Expand Down Expand Up @@ -115,6 +117,15 @@ struct NumericEval : zeno::INode {
opts.define_param(key, dim);
}

if (1)
{
// BEGIN 引用预解析:将其他节点参数引用到此处,可能涉及提前对该参数的计算
// 方法是: 搜索code里所有ref(...),然后对于每一个ref(...),解析ref内部的引用,
// 然后将计算结果替换对应ref(...),相当于预处理操作。
code = preApplyRefs(code, getThisGraph());
// END 引用预解析
}

//开始编译
if (code.find("@result") == std::string::npos)
code = "@result = ( " + code + " )";
Expand Down
Loading

0 comments on commit ab207be

Please sign in to comment.