Skip to content

Commit

Permalink
Merge pull request #1627 from zenustech/fixDtermProblem
Browse files Browse the repository at this point in the history
Fix dterm problem
  • Loading branch information
zhxx1987 authored Dec 14, 2023
2 parents e16853e + 501efe6 commit 5262681
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
42 changes: 34 additions & 8 deletions zeno/src/nodes/mtl/ShaderTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,47 @@ struct SmartTexture2D : ShaderNodeClone<SmartTexture2D>
if(!std::filesystem::exists(texture_path)){
zeno::log_warn("texture file not found!");
auto type = get_input2<std::string>("type");
auto number = em->determineType(get_input("value").get());
vec4f number= vec4f(0,0,0,0);
if(has_input2<float>("value"))
{
number[0] = get_input2<float>("value");
}
if(has_input2<vec2f>("value"))
{
auto in = get_input2<vec2f>("value");
number[0] = in[0];
number[1] = in[1];
}
if(has_input2<vec3f>("value"))
{
auto in = get_input2<vec3f>("value");
number[0] = in[0];
number[1] = in[1];
number[2] = in[2];
}
if(has_input2<vec4f>("value"))
{
auto in = get_input2<vec4f>("value");
number[0] = in[0];
number[1] = in[1];
number[2] = in[2];
number[3] = in[3];
}

if (type == "float" || type == "R")
em->emitCode(zeno::format("vec4({}).x",number));
em->emitCode(zeno::format("{}",number[0]));
else if (type == "G")
em->emitCode(zeno::format("vec4({}).y",number));
em->emitCode(zeno::format("{}",number[1]));
else if (type == "B")
em->emitCode(zeno::format("vec4({}).z",number));
em->emitCode(zeno::format("{}",number[2]));
else if (type == "A")
em->emitCode(zeno::format("vec4({}).w",number));
em->emitCode(zeno::format("{}",number[3]));
else if (type == "vec2")
em->emitCode(zeno::format("vec2({})",number));
em->emitCode(zeno::format("vec2({},{})",number[0],number[1]));
else if (type == "vec3")
em->emitCode(zeno::format("vec3({})",number));
em->emitCode(zeno::format("vec3({},{},{})",number[0],number[1],number[2]));
else if (type == "vec4")
em->emitCode(zeno::format("vec4({})",number));
em->emitCode(zeno::format("vec3({},{},{},{})",number[0],number[1],number[2],number[4]));
else
throw zeno::Exception("ShaderTexture2D got bad type: " + type);

Expand Down
6 changes: 3 additions & 3 deletions zenovis/xinxinoptix/DisneyBRDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ vec3 EvalMicrofacetReflection(float ax, float ay, vec3 V, vec3 L, vec3 H, vec3 F
if (L.z * V.z <= 0.0)
return vec3(0.0);

float D = GTR2Aniso(abs(H.z), H.x, H.y, ax, ay);
float D = clamp(GTR2Aniso(abs(H.z), H.x, H.y, ax, ay),0.0f, 10.0f);
float G1 = SmithGAniso(abs(V.z), V.x, V.y, ax, ay);
float G2 = G1 * SmithGAniso(abs(L.z), L.x, L.y, ax, ay);

Expand All @@ -463,7 +463,7 @@ vec3 EvalMicrofacetRefraction(vec3 baseColor, float ax, float ay, float eta, vec
float LDotH = dot(L, H); //always negative
float VDotH = dot(V, H); //always positive

float D = GTR2Aniso(abs(H.z), H.x, H.y, ax, ay);
float D = clamp(GTR2Aniso(abs(H.z), H.x, H.y, ax, ay),0.0f, 10.0f);
float G1 = SmithGAniso(abs(V.z), V.x, V.y, ax, ay);
float G2 = G1 * SmithGAniso(abs(L.z), L.x, L.y, ax, ay);
float denom = LDotH * eta + VDotH;
Expand Down Expand Up @@ -493,7 +493,7 @@ vec3 EvalClearcoat(float ccR, vec3 V, vec3 L, vec3 H, float &pdf)
float VDotH = abs(dot(V, H));

float F = mix(0.04, 1.0, SchlickWeight(VDotH));
float D = GTR1(H.z, ccR);
float D = clamp(GTR1(H.z, ccR),0.0f, 10.0f);
float G = SmithG(L.z, 0.25f) * SmithG(V.z, 0.25f);
float jacobian = 1.0f / (4.0f * VDotH);

Expand Down

0 comments on commit 5262681

Please sign in to comment.