Skip to content

Commit

Permalink
improve shader nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
iaomw committed Jan 6, 2025
1 parent d3a49a9 commit ff96d09
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 7 deletions.
28 changes: 26 additions & 2 deletions zeno/src/nodes/mtl/ShaderBuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
#include <array>
#include <zeno/zeno.h>
#include <zeno/extra/ShaderNode.h>
#include <zeno/types/ShaderObject.h>

namespace zeno {

struct ImplShaderBuffer : ShaderNodeClone<ImplShaderBuffer> {
int out;

struct ShaderBuffer : ShaderNodeClone<ShaderBuffer> {
virtual int determineType(EmissionPass *em) override {
return TypeHint.at("uint64");
}

virtual void emitCode(EmissionPass *em) override {

auto name = get_input2<std::string>("name");
return em->emitCode("reinterpret_cast<uint64_t>("+ name + "_buffer" +")");

if ( out > 0 ) {
return em->emitCode(name + "_bfsize");
}
return em->emitCode("reinterpret_cast<uint64_t>("+ name + "_buffer)");
}
};

struct ShaderBuffer : INode {

virtual void apply() override {

static const auto list = std::array {"out", "size"};

for(int i=0; i<list.size(); ++i) {

auto node = std::make_shared<ImplShaderBuffer>();
node->inputs["name"] = get_input("name");
node->out = i;
auto shader = std::make_shared<ShaderObject>(node.get());
set_output(list[i], std::move(shader));
}
}
};

Expand Down
53 changes: 52 additions & 1 deletion zeno/src/nodes/mtl/ShaderTypeCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include <zeno/extra/ShaderNode.h>
#include <zeno/types/ShaderObject.h>

#include <iomanip>
#include <sstream>
#include <iostream>

namespace zeno {

static std::string dataTypeDefaultString() {
Expand Down Expand Up @@ -43,8 +47,55 @@ ZENDEFNODE(ShaderTypeCast, {
},
{
{"enum bit_cast data_cast ", "op", "bit_cast"},
{"enum" + ShaderDataTypeNamesString, "type", "bool"},
{"enum " + ShaderDataTypeNamesString, "type", "bool"},
},
{"shader"},
});

struct ShaderPrint : ShaderNodeClone<ShaderPrint> {
virtual int determineType(EmissionPass *em) override {
auto in = get_input("in").get();
auto in_type = em->determineType(in);
return in_type;
}

virtual void emitCode(EmissionPass *em) override {

auto in = get_input("in").get();
auto in_type = em->determineType(in);
auto in_expr = em->determineExpr(in);

auto str = get_input2<std::string>("str");

static const std::map<std::string, std::string> typeTable {
{"float", "%f"}, {"bool", "%d"},
{"int", "%d"}, {"uint", "%u"},
{"int64", "%ll"}, {"uint64", "%llu"}
};

auto typeStr = TypeHintReverse.at(in_type);
auto typePri = typeTable.at(typeStr);
auto content = str + ": " + typePri + "\\n";

std::stringstream ss;
ss << "printf(";
ss << std::quoted(content, '"', '\n');
ss << "," << in_expr << ");";

em->lines.back() += ss.str();
em->emitCode(in_expr);
}
};

ZENDEFNODE(ShaderPrint, {
{
{"in"},
{"string", "str", ""}
},
{
{"shader", "out"},
},
{},
{"shader"},
});

Expand Down
4 changes: 2 additions & 2 deletions zenovis/xinxinoptix/CallableDefault.cu
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ extern "C" __device__ MatOutput __direct_callable__evalmat(cudaTextureObject_t z
auto att_instTang = attrs.instTang;
auto att_rayLength = attrs.rayLength;

auto att_isBackFace = attrs.isBackFace ? 1.0f:0.0f;
auto att_isShadowRay = attrs.isShadowRay ? 1.0f:0.0f;
auto att_isBackFace = attrs.isBackFace;
auto att_isShadowRay = attrs.isShadowRay;

vec3 b = normalize(cross(attrs.T, attrs.N));
vec3 t = normalize(cross(attrs.N, b));
Expand Down
5 changes: 3 additions & 2 deletions zenovis/xinxinoptix/CallableVolume.cu
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,9 @@ extern "C" __device__ void __direct_callable__evalmat(const float4* uniforms, vo
auto vdb_grids = sbt_data->vdb_grids;
auto vdb_max_v = sbt_data->vdb_max_v;

auto att_isShadowRay = attrs.isShadowRay ? 1.0f:0.0f;

auto att_isBackFace = false;
auto att_isShadowRay = attrs.isShadowRay;

#ifndef _FALLBACK_

//GENERATED_BEGIN_MARK
Expand Down

0 comments on commit ff96d09

Please sign in to comment.