Skip to content

Commit

Permalink
Merge pull request #1622 from zenustech/tbn
Browse files Browse the repository at this point in the history
Dirty TBN
  • Loading branch information
zhxx1987 authored Dec 12, 2023
2 parents 39990e0 + 47cb3d3 commit 31745a8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
57 changes: 57 additions & 0 deletions projects/FBX/MayaCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,63 @@ ZENO_DEFNODE(LightNode)({
{"shader"},
});

struct DirtyTBN : INode {
virtual void apply() override {

auto AxisT = get_input2<zeno::vec3f>("T");
auto AxisB = get_input2<zeno::vec3f>("B");
//auto AxisN = get_input2<zeno::vec3f>("N");

if (lengthSquared(AxisT) == 0 ) {
AxisT = {1,0,0};
}
AxisT = zeno::normalize(AxisT);

if (lengthSquared(AxisB) == 0 ) {
AxisB = {0,0,1};
}
AxisB = zeno::normalize(AxisB);

auto tmp = zeno::dot(AxisT, AxisB);
if (abs(tmp) > 0.0) { // not vertical
AxisB -= AxisT * tmp;
AxisB = zeno::normalize(AxisB);
}

if (has_input("prim")) {
auto prim = get_input<PrimitiveObject>("prim");

auto pos = prim->userData().get2<zeno::vec3f>("pos", {0,0,0});
auto scale = prim->userData().get2<zeno::vec3f>("scale", {1,1,1});

auto v0 = pos - AxisT * scale[0] * 0.5f - AxisB * scale[2] * 0.5f;
auto e1 = AxisT * scale[0];
auto e2 = AxisB * scale[2];

prim->verts[0] = v0 + e1 + e2;
prim->verts[1] = v0 + e1;
prim->verts[2] = v0 + e2;
prim->verts[3] = v0;

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


ZENO_DEFNODE(DirtyTBN)({
{
{"PrimitiveObject", "prim"},
{"vec3f", "T", "1, 0, 0"},
{"vec3f", "B", "0, 0, 1"},
},
{
"prim"
},
{},
{"shader"},
});

struct LiveMeshNode : INode {
typedef std::vector<std::vector<float>> UVS;
typedef std::vector<std::vector<float>> VERTICES;
Expand Down
4 changes: 3 additions & 1 deletion zenovis/src/optx/RenderEngineOptx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,9 @@ struct GraphicsManager {
e2 = -e2; // invert e2

// facing down in local space
nor = zeno::normalize(zeno::cross(e2, e1));
auto ne2 = zeno::normalize(e2);
auto ne1 = zeno::normalize(e1);
nor = zeno::normalize(zeno::cross(ne2, ne1));
if (ivD) { nor *= -1; }

if (prim_in->verts.has_attr("clr")) {
Expand Down

0 comments on commit 31745a8

Please sign in to comment.