Skip to content

Commit

Permalink
Merge branch 'master' into zeno2-fixbug
Browse files Browse the repository at this point in the history
  • Loading branch information
legobadman committed Jul 4, 2024
2 parents 0d4ca49 + 4a431bc commit 7b56d35
Show file tree
Hide file tree
Showing 61 changed files with 4,136 additions and 15,121 deletions.
94 changes: 94 additions & 0 deletions projects/CUDA/utils/Primitives.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <zeno/utils/vec.h>
#include <zeno/zeno.h>

#include "Noise.cuh"

namespace zeno {

/// utilities
Expand Down Expand Up @@ -74,6 +76,98 @@ float prim_reduce(typename ZenoParticles::particles_t &verts, float e, TransOp t
return ret.getVal();
}

struct ZSParticlePerlinNoise : INode {
virtual void apply() override {
auto zspars = get_input<ZenoParticles>("zspars");
auto attrTag = get_input2<std::string>("Attribute");
auto opType = get_input2<std::string>("OpType");
auto frequency = get_input2<vec3f>("Frequency");
auto offset = get_input2<vec3f>("Offset");
auto roughness = get_input2<float>("Roughness");
auto turbulence = get_input2<int>("Turbulence");
auto amplitude = get_input2<float>("Amplitude");
auto attenuation = get_input2<float>("Attenuation");
auto mean = get_input2<vec3f>("MeanNoise");

bool isAccumulate = opType == "accumulate" ? true : false;

zs::SmallString tag = attrTag;

auto &tv = zspars->getParticles();

if (!tv.hasProperty(tag))
throw std::runtime_error(fmt::format("Attribute [{}] doesn't exist!", tag));
const int nchns = tv.getPropertySize(tag);

auto pol = zs::cuda_exec();
constexpr auto space = zs::execspace_e::cuda;

pol(zs::range(tv.size()),
[tvv = zs::proxy<space>({}, tv), tag, nchns, isAccumulate,
frequency = zs::vec<float, 3>::from_array(frequency), offset = zs::vec<float, 3>::from_array(offset),
roughness, turbulence, amplitude, attenuation,
mean = zs::vec<float, 3>::from_array(mean)] __device__(int no) mutable {
auto wcoord = tvv.pack(zs::dim_c<3>, "x", no);
auto pp = frequency * wcoord - offset;

float scale = amplitude;

if (nchns == 3) {
// fractal Brownian motion
auto fbm = zs::vec<float, 3>::uniform(0);
for (int i = 0; i < turbulence; ++i, pp *= 2.f, scale *= roughness) {
zs::vec<float, 3> pln{ZSPerlinNoise1::perlin(pp[0], pp[1], pp[2]),
ZSPerlinNoise1::perlin(pp[1], pp[2], pp[0]),
ZSPerlinNoise1::perlin(pp[2], pp[0], pp[1])};
fbm += scale * pln;
}
auto noise = zs::vec<float, 3>{zs::pow(fbm[0], attenuation), zs::pow(fbm[1], attenuation),
zs::pow(fbm[2], attenuation)} +
mean;

if (isAccumulate)
tvv.tuple(zs::dim_c<3>, tag, no) =
tvv.pack(zs::dim_c<3>, tag, no) + noise;
else
tvv.tuple(zs::dim_c<3>, tag, no) = noise;

} else if (nchns == 1) {
float fbm = 0;
for (int i = 0; i < turbulence; ++i, pp *= 2.f, scale *= roughness) {
float pln = ZSPerlinNoise1::perlin(pp[0], pp[1], pp[2]);
fbm += scale * pln;
}
auto noise = zs::pow(fbm, attenuation) + mean[0];

if (isAccumulate)
tvv(tag, no) += noise;
else
tvv(tag, no) = noise;
}
});

set_output("zspars", zspars);
}
};

ZENDEFNODE(ZSParticlePerlinNoise, {/* inputs: */
{"zspars",
{"string", "Attribute", "v"},
{"enum replace accumulate", "OpType", "accumulate"},
{"vec3f", "Frequency", "1, 1, 1"},
{"vec3f", "Offset", "0, 0, 0"},
{"float", "Roughness", "0.5"},
{"int", "Turbulence", "4"},
{"float", "Amplitude", "1.0"},
{"float", "Attenuation", "1.0"},
{"vec3f", "MeanNoise", "0, 0, 0"}},
/* outputs: */
{"zspars"},
/* params: */
{},
/* category: */
{"Eulerian"}});

struct ZSPrimitiveReduction : zeno::INode {
struct pass_on {
template <typename T>
Expand Down
2 changes: 1 addition & 1 deletion projects/CUDA/zpc
Submodule zpc updated 36 files
+5 −1 CMakeLists.txt
+91 −2 include/zensim/CMakeLists.txt
+30 −0 include/zensim/Platform.hpp
+24 −32 include/zensim/ZpcFunctional.hpp
+2 −1 include/zensim/ZpcImplPattern.cpp
+1 −1 include/zensim/ZpcImplPattern.hpp
+1 −1 include/zensim/ZpcIterator.hpp
+12 −15 include/zensim/ZpcMathUtils.hpp
+2 −2 include/zensim/ZpcMeta.hpp
+8 −8 include/zensim/ZpcReflection.hpp
+15 −10 include/zensim/ZpcResource.hpp
+0 −3 include/zensim/ZpcTuple.hpp
+2 −0 include/zensim/cuda/memory/Allocator.cpp
+3 −1 include/zensim/cuda/memory/Allocator.h
+2 −2 include/zensim/execution/ConcurrencyPrimitive.cpp
+76 −11 include/zensim/math/Rotation.hpp
+15 −15 include/zensim/math/Vec.h
+23 −2 include/zensim/math/VecInterface.hpp
+14 −13 include/zensim/math/matrix/Transform.hpp
+1 −0 include/zensim/memory/Allocator.cpp
+2 −0 include/zensim/memory/Allocator.h
+19 −45 include/zensim/memory/MemoryResource.h
+10 −1 include/zensim/physics/constitutive_models/AnisotropicArap.hpp
+4 −4 include/zensim/physics/constitutive_models/NeoHookean.hpp
+8 −0 include/zensim/py_interop/Clang.cpp
+3 −0 include/zensim/resource/Resource.cpp
+3 −0 include/zensim/resource/Resource.h
+4 −1 include/zensim/types/SmallVector.hpp
+1 −1 include/zensim/vulkan/VkSwapchain.cpp
+1 −1 include/zensim/zpc_tpls
+1 −1 test/CMakeLists.txt
+2 −2 test/cuda/main.cu
+181 −40 test/help_parser.cpp
+2 −2 test/parallel_primitives.cpp
+2 −2 test/utils/parallel_primitives.hpp
+1 −1 zpc_assets
2 changes: 1 addition & 1 deletion projects/CuLagrange/pbd/ConstraintsBuilder.cu
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ virtual void apply() override {
rest_scale = rest_scale,
eles = proxy<space>({},eles),
verts = proxy<space>({},verts)] ZS_LAMBDA(auto ai,const auto& pair) mutable {
eles.tuple(dim_c<2>,"inds",ai) = pair.reinterpret_bits<float>();
eles.tuple(dim_c<2>,"inds",ai) = pair.template reinterpret_bits<float>();
auto v0 = verts.pack(dim_c<3>,"x",pair[0]);
auto v1 = verts.pack(dim_c<3>,"x",pair[1]);
eles("r",ai) = (v0 - v1).norm() * rest_scale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ constexpr bool solve_BendTwistConstraint(
}

// ----------------------------------------------------------------------------------------------
#if 0
template<typename VECTOR3d,typename SCALER>
constexpr bool solve_PerpendiculaBisectorConstraint(
const VECTOR3d &p0, SCALER invMass0,
Expand All @@ -1002,6 +1003,7 @@ constexpr bool solve_PerpendiculaBisectorConstraint(

return true;
}
#endif

// // ----------------------------------------------------------------------------------------------
// template<typename VECTOR3d,typename SCALER>
Expand Down
54 changes: 0 additions & 54 deletions projects/FBX/MayaCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <zeno/utils/log.h>

#include <zeno/zeno.h>
#include <zeno/utils/eulerangle.h>
#include <zeno/utils/logger.h>
#include <zeno/extra/GlobalState.h>
#include <zeno/types/NumericObject.h>
Expand All @@ -32,7 +31,6 @@
#include <glm/gtx/matrix_decompose.hpp>

#include <fstream>
#include <regex>

#define SET_CAMERA_DATA \
out_pos = (n->pos); \
Expand Down Expand Up @@ -88,58 +86,6 @@ ZENO_DEFNODE(CihouMayaCameraFov)({
{"FBX"},
});

struct CameraNode: zeno::INode{
virtual void apply() override {
auto camera = std::make_unique<zeno::CameraObject>();

camera->pos = get_input2<zeno::vec3f>("pos");
camera->up = get_input2<zeno::vec3f>("up");
camera->view = get_input2<zeno::vec3f>("view");
camera->fov = get_input2<float>("fov");
camera->aperture = get_input2<float>("aperture");
camera->focalPlaneDistance = get_input2<float>("focalPlaneDistance");
camera->userData().set2("frame", get_input2<float>("frame"));

auto other_props = get_input2<std::string>("other");
std::regex reg(",");
std::sregex_token_iterator p(other_props.begin(), other_props.end(), reg, -1);
std::sregex_token_iterator end;
std::vector<float> prop_vals;
while (p != end) {
prop_vals.push_back(std::stof(*p));
p++;
}
if (prop_vals.size() == 6) {
camera->isSet = true;
camera->center = {prop_vals[0], prop_vals[1], prop_vals[2]};
camera->theta = prop_vals[3];
camera->phi = prop_vals[4];
camera->radius = prop_vals[5];
}

set_output("camera", std::move(camera));
}
};

ZENO_DEFNODE(CameraNode)({
{
{"vec3f", "pos", "0,0,5"},
{"vec3f", "up", "0,1,0"},
{"vec3f", "view", "0,0,-1"},
{"float", "fov", "45"},
{"float", "aperture", "11"},
{"float", "focalPlaneDistance", "2.0"},
{"string", "other", ""},
{"int", "frame", "0"},
},
{
{"CameraObject", "camera"},
},
{
},
{"FBX"},
});

struct CameraEval: zeno::INode {

glm::quat to_quat(zeno::vec3f up, zeno::vec3f view){
Expand Down
File renamed without changes.
29 changes: 29 additions & 0 deletions ui/zenoedit/dock/docktabcontent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,18 @@ void DockContent_View::initToolbar(QHBoxLayout* pToolLayout)
pToolLayout->addWidget(m_camera_setting);
}

{
pToolLayout->addWidget(new ZLineWidget(false, QColor("#121416")));
m_depth = new QCheckBox(tr("Depth"));
m_depth->setStyleSheet("color: white;");
m_depth->setCheckState(Qt::Checked);
pToolLayout->addWidget(m_depth);
m_FPN = new QCheckBox(tr("FPN"));
m_FPN->setStyleSheet("color: white;");
pToolLayout->addWidget(m_FPN);
m_Reset = new QPushButton(tr("Reset"));
pToolLayout->addWidget(m_Reset);
}
pToolLayout->addWidget(new ZLineWidget(false, QColor("#121416")));
pToolLayout->addWidget(m_screenshoot);
pToolLayout->addWidget(m_recordVideo);
Expand Down Expand Up @@ -941,6 +953,16 @@ void DockContent_View::initConnections()
});
}

connect(m_depth, &QCheckBox::stateChanged, this, [=](int state) {
bool bChecked = (state == Qt::Checked);
zeno::getSession().userData().set2("viewport-depth-aware-navigation", bChecked);
});

connect(m_FPN, &QCheckBox::stateChanged, this, [=](int state) {
bool bChecked = (state == Qt::Checked);
zeno::getSession().userData().set2("viewport-FPN-navigation", bChecked);
});

if (m_camera_setting) {
connect(m_camera_setting, &QPushButton::clicked, this, [=](bool bToggled) {
zenovis::ZOptixCameraSettingInfo info = m_pDisplay->getCamera();
Expand All @@ -953,6 +975,13 @@ void DockContent_View::initConnections()
}
});
}
if (m_Reset) {
connect(m_Reset, &QPushButton::clicked, this, [=](bool bToggled) {
auto *scene = m_pDisplay->getZenoVis()->getSession()->get_scene();
scene->camera->reset();
m_pDisplay->updateFrame();
});
}

connect(m_smooth_shading, &ZToolBarButton::toggled, this, [=](bool bToggled) {
m_pDisplay->onCommandDispatched(ZenoMainWindow::ACTION_SMOOTH_SHADING, bToggled);
Expand Down
3 changes: 3 additions & 0 deletions ui/zenoedit/dock/docktabcontent.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ class DockContent_View : public DockToolbarWidget
QPushButton *m_camera_setting = nullptr;
QCheckBox *m_background;
QCheckBox *m_uv_mode = nullptr;
QCheckBox *m_depth = nullptr;
QCheckBox *m_FPN = nullptr;
QPushButton *m_Reset = nullptr;

QComboBox* m_cbRes;
QAction* m_pFocus;
Expand Down
22 changes: 12 additions & 10 deletions ui/zenoedit/nodesys/cameranode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,23 @@ void CameraNode::onEditClicked()
auto camera = *(scene->camera.get());

INPUT_SOCKET pos = inputs["pos"];
vec = {camera.m_lodcenter[0], camera.m_lodcenter[1], camera.m_lodcenter[2]};
vec = {camera.m_pos[0], camera.m_pos[1], camera.m_pos[2]};
info.name = "pos";
info.oldValue = pos.info.defaultValue;
info.newValue = QVariant::fromValue(vec);
pModel->updateSocketDefl(nodeid, info, this->subgIndex(), true);

auto m_lodup = camera.get_lodup();
auto m_lodfront = camera.get_lodfront();
INPUT_SOCKET up = inputs["up"];
vec = {camera.m_lodup[0], camera.m_lodup[1], camera.m_lodup[2]};
vec = {m_lodup[0], m_lodup[1], m_lodup[2]};
info.name = "up";
info.oldValue = up.info.defaultValue;
info.newValue = QVariant::fromValue(vec);
pModel->updateSocketDefl(nodeid, info, this->subgIndex(), true);

INPUT_SOCKET view = inputs["view"];
vec = {camera.m_lodfront[0], camera.m_lodfront[1], camera.m_lodfront[2]};
vec = {m_lodfront[0], m_lodfront[1], m_lodfront[2]};
info.name = "view";
info.oldValue = view.info.defaultValue;
info.newValue = QVariant::fromValue(vec);
Expand Down Expand Up @@ -137,11 +139,11 @@ void CameraNode::onEditClicked()

INPUT_SOCKET other = inputs["other"];
std::string other_prop;
auto center = camera.m_center;
auto center = camera.m_pivot;
other_prop += zeno::format("{},{},{},", center[0], center[1], center[2]);
other_prop += zeno::format("{},", camera.m_theta);
other_prop += zeno::format("{},", camera.m_phi);
other_prop += zeno::format("{},", camera.m_radius);
other_prop += zeno::format("{},", 0);
other_prop += zeno::format("{},", 0);
other_prop += zeno::format("{},", camera.get_radius());
info.name = "other";
info.oldValue = other.info.defaultValue;
info.newValue = QVariant::fromValue(QString(other_prop.c_str()));
Expand Down Expand Up @@ -191,10 +193,10 @@ void LightNode::onEditClicked(){
PARAM_UPDATE_INFO info;

auto camera = *(scene->camera.get());
auto original_pos = glm::vec3(camera.m_lodcenter);
auto original_pos = glm::vec3(camera.m_pos);
// auto pos = glm::normalize(glm::vec3(camProp[0], camProp[1], camProp[2]));
auto view = -1.0f * glm::normalize(camera.m_lodfront);
auto up = glm::normalize(camera.m_lodup);
auto view = -1.0f * glm::normalize(camera.get_lodfront());
auto up = glm::normalize(camera.get_lodup());
auto right = glm::normalize(glm::cross(up, view));

glm::mat3 rotation(right, up, view);
Expand Down
Loading

0 comments on commit 7b56d35

Please sign in to comment.