Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/zenustech/zeno
Browse files Browse the repository at this point in the history
  • Loading branch information
zhxx1987 committed Oct 30, 2024
2 parents 2aa6bb5 + 9b71388 commit bc0554b
Show file tree
Hide file tree
Showing 17 changed files with 29,741 additions and 176 deletions.
29,449 changes: 29,449 additions & 0 deletions misc/graphs/WhiteFurnace.zsg

Large diffs are not rendered by default.

21 changes: 18 additions & 3 deletions projects/CUDA/utils/Primitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ struct PrimitiveMarkIslands : INode {
}

const auto &loops = prim->loops;
const auto &polys = prim->polys;
auto &polys = prim->polys;
using IV = zs::vec<int, 2>;
zs::bht<int, 2, int, 16> tab{(std::size_t)(polys.values.back()[0] + polys.values.back()[1])};
std::vector<int> is, js;
Expand Down Expand Up @@ -568,12 +568,26 @@ struct PrimitiveMarkIslands : INode {
std::sort(kvs.begin(), kvs.end(), lessOp);
pol(enumerate(kvs), [&invMap](int no, auto kv) { invMap[kv.second] = no; });

auto &setids = prim->add_attr<int>(get_input2<std::string>("island_tag"));
auto islandTag = get_input2<std::string>("island_tag");
auto &setids = prim->add_attr<int>(islandTag);
pol(range(pos.size()), [&fas, &setids, &invMap, vtab = view<space>(vtab)](int vi) mutable {
auto ancestor = fas[vi];
auto setNo = vtab.query(ancestor);
setids[vi] = invMap[setNo];
});
if (get_input2<bool>("mark_face")) {
auto &faceids = polys.add_attr<int>(islandTag);
pol(zip(polys.values, faceids), [&](const auto &poly, int &fid) {
auto offset = poly[0];
auto vi = loops[offset];
auto vIslandId = setids[vi];
fid = vIslandId;
// auto size = poly[1];
// for (int i = 1; i < size; ++i) {
// assert(setids[loops[offset + i]] == set);
// }
});
}

if (isTris) {
primTriangulate(prim.get(), true, false);
Expand All @@ -583,7 +597,8 @@ struct PrimitiveMarkIslands : INode {
};

ZENDEFNODE(PrimitiveMarkIslands, {
{{"PrimitiveObject", "prim"}, {"string", "island_tag", "island_index"}},
{{"PrimitiveObject", "prim"}, {"string", "island_tag", "island_index"},
{"bool", "mark_face", "0"}},
{
{"PrimitiveObject", "prim"},
},
Expand Down
3 changes: 3 additions & 0 deletions projects/CuEulerian/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ target_sources(zeno PRIVATE
volume/Conversion.cu
)
]]
target_sources(zeno PRIVATE
volume/VolumeOps.cu
)

# shallow water & terrain
target_sources(zeno PRIVATE
Expand Down
103 changes: 103 additions & 0 deletions projects/CuEulerian/volume/VolumeOps.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include "Structures.hpp"
#include "zensim/cuda/execution/ExecutionPolicy.cuh"
#include "zensim/geometry/SparseGrid.hpp"
#include "zensim/omp/execution/ExecutionPolicy.hpp"
#include "zensim/zpc_tpls/fmt/color.h"
#include "zensim/zpc_tpls/fmt/format.h"

#include <zeno/types/ListObject.h>
#include <zeno/types/NumericObject.h>
#include <zeno/types/PrimitiveObject.h>

// #include <zeno/VDBGrid.h>

#include "../utils.cuh"
#include "zeno/utils/log.h"

namespace zeno {

struct ZSSParseGridDifference : INode {
void apply() override {
using namespace zs;
auto grid = get_input<ZenoSparseGrid>("ZSGrid");

auto attrTag = get_input2<std::string>("attrName");
auto chnOffset = get_input2<int>("channelOffset");

auto outputAttrTag = get_input2<std::string>("outputAttrName");
if (outputAttrTag.empty())
throw std::runtime_error(
"[outputAttrName] should not be an empty string.");

auto orientationStr = get_input2<std::string>("orientation");
int orientation =
orientationStr == "ddx" ? 0 : (orientationStr == "ddy" ? 1 : 2);

auto boundaryStr = get_input2<std::string>("boundary_type");
int boundaryType = boundaryStr == "neumann" ? 0 : /*dirichlet*/ 1;

auto &spg = grid->spg;
auto block_cnt = spg.numBlocks();
auto pol = cuda_exec();
constexpr auto space = execspace_e::cuda;

spg.append_channels(pol, {{outputAttrTag, 1}});

pol(Collapse{block_cnt, spg.block_size},
[spgv = proxy<space>(spg),
srcOffset = spg.getPropertyOffset(attrTag) + chnOffset, orientation,
dstOffset = spg.getPropertyOffset(outputAttrTag), boundaryType,
twodx = 2 * spg.voxelSize()[0]] __device__(int blockno,
int cellno) mutable {
auto icoord = spgv.iCoord(blockno, cellno);
auto val = spgv(srcOffset, blockno, cellno);
auto iCoordA = icoord;
iCoordA[orientation]++;
auto iCoordB = icoord;
iCoordB[orientation]--;

auto getVal = [&](const auto &coord) -> zs::f32 {
auto [bno, cno] = spgv.decomposeCoord(coord);
if (bno == spgv.sentinel_v) {
// boundary
if (boundaryType == 0) // neumann
return val;
else
return 0.f;
} else {
return spgv(srcOffset, bno, cno);
}
};
auto tmp = (getVal(iCoordA) - getVal(iCoordB)) / twodx;
#if 0
if (zs::abs(tmp) > 0.01) {
printf("coord (%d, %d, %d) - (%d, %d, %d) diff: %f\n", iCoordA[0],
iCoordA[1], iCoordA[2], iCoordB[0], iCoordB[1], iCoordB[2],
(float)tmp);
}
#endif
spgv(dstOffset, blockno, cellno) = tmp;
});

set_output("ZSGrid", grid);
}
};

ZENDEFNODE(ZSSParseGridDifference,
{/* inputs: */
{
"ZSGrid",
{"string", "attrName", "sdf"},
{"int", "channelOffset", "0"},
{"enum ddx ddy ddz", "orientation", "ddx"},
{"string", "outputAttrName", ""},
{"enum neumann dirichlet", "boundary_type", "neumann"},
},
/* outputs: */
{"ZSGrid"},
/* params: */
{},
/* category: */
{"Eulerian"}});

} // namespace zeno
6 changes: 4 additions & 2 deletions zenovis/src/optx/RenderEngineOptx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,8 @@ struct RenderEngineOptx : RenderEngine, zeno::disable_copy {
ensure_shadtmpl(_volume_shader_template);
ensure_shadtmpl(_light_shader_template);

if (cachedMeshesMaterials.count("Default")) {
//if (cachedMeshesMaterials.count("Default"))
{
auto tmp = std::make_shared<ShaderPrepared>();

tmp->mark = ShaderMark::Mesh;
Expand All @@ -1385,7 +1386,8 @@ struct RenderEngineOptx : RenderEngine, zeno::disable_copy {
meshMatLUT.insert({"Default", 0});
}

if (cachedSphereMaterials.count("Default")) {
//if (cachedSphereMaterials.count("Default"))
{
auto tmp = std::make_shared<ShaderPrepared>();

tmp->mark = ShaderMark::Sphere;
Expand Down
32 changes: 11 additions & 21 deletions zenovis/xinxinoptix/DeflMatShader.cu
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,6 @@ extern "C" __global__ void __closesthit__radiance()
}
prd->attenuation2 = prd->attenuation;
prd->passed = true;
prd->adepth++;
//prd->samplePdf = 0.0f;
//you shall pass!
prd->radiance = make_float3(0.0f);
prd->_tmin_ = optixGetRayTmax();
Expand Down Expand Up @@ -969,18 +967,18 @@ extern "C" __global__ void __closesthit__radiance()
backPos = wldPos;
}

shadowPRD.origin = dot(-ray_dir, wldNorm) > 0 ? frontPos : backPos;
shadowPRD.origin = dot(wi, vec3(prd->geometryNormal)) > 0 ? frontPos : backPos;
//auto shadingP = rtgems::offset_ray(shadowPRD.origin + params.cam.eye, prd->geometryNormal); // world space

shadowPRD.origin = frontPos;
if(mats.subsurface>0 && (mats.thin>0.5 || mats.doubleSide>0.5) && istransmission){
shadowPRD.origin = backPos; //rtgems::offset_ray(P, -prd->geometryNormal);
}
//shadowPRD.origin = frontPos;
//if(mats.subsurface>0 && (mats.thin>0.5 || mats.doubleSide>0.5) && istransmission){
//shadowPRD.origin = backPos; //rtgems::offset_ray(P, -prd->geometryNormal);
//}

auto shadingP = rtgems::offset_ray(P + params.cam.eye, prd->geometryNormal); // world space
if(mats.subsurface>0 && (mats.thin>0.5 || mats.doubleSide>0.5) && istransmission){
shadingP = rtgems::offset_ray(P + params.cam.eye, -prd->geometryNormal);
}
auto shadingP = rtgems::offset_ray(P + params.cam.eye, dot(wi, vec3(prd->geometryNormal)) > 0 ? prd->geometryNormal:-prd->geometryNormal); // world space
//if(mats.subsurface>0 && (mats.thin>0.5 || mats.doubleSide>0.5) && istransmission){
//shadingP = rtgems::offset_ray(P + params.cam.eye, -prd->geometryNormal);
//}

prd->radiance = {};
prd->direction = normalize(wi);
Expand All @@ -994,6 +992,7 @@ extern "C" __global__ void __closesthit__radiance()
}

prd->lightmask = DefaultMatMask;
shadowPRD.ShadowNormal = dot(wi, vec3(prd->geometryNormal)) > 0 ? prd->geometryNormal:-prd->geometryNormal;
DirectLighting<true>(prd, shadowPRD, shadingP, ray_dir, evalBxDF, &taskAux, dummy_prt);
if(mats.shadowReceiver > 0.5f)
{
Expand All @@ -1006,16 +1005,7 @@ extern "C" __global__ void __closesthit__radiance()

prd->direction = normalize(wi);

if(mats.thin<0.5f && mats.doubleSide<0.5f){
//auto p_prim = vec3(prd->origin) + optixGetRayTmax() * vec3(prd->direction);
//float3 p = p_prim;
prd->origin = next_ray_is_going_inside? backPos : frontPos;
}
else {
//auto p_prim = vec3(prd->origin) + optixGetRayTmax() * vec3(prd->direction);
//float3 p = p_prim;
prd->origin = dot(prd->direction, prd->geometryNormal) < 0? backPos : frontPos;
}
prd->origin = dot(prd->direction, prd->geometryNormal) < 0.0f ? backPos : frontPos;

if (prd->medium != DisneyBSDF::vacuum) {
prd->_mask_ = (uint8_t)(EverythingMask ^ VolumeMatMask);
Expand Down
2 changes: 1 addition & 1 deletion zenovis/xinxinoptix/DisneyBRDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ float DielectricFresnel(float cosThetaI, float eta)
float eta2 = eta * eta;

float cos2t = 1.0f - sin2 / eta2;
if(cos2t < 0) return 1.0f;
if(cos2t < 0.0f) return 1.0f;

float t0 = sqrt(cos2t);
float t1 = eta * t0;
Expand Down
Loading

0 comments on commit bc0554b

Please sign in to comment.