Skip to content

Commit

Permalink
Merge pull request #1478 from zenustech/OptixBSDF
Browse files Browse the repository at this point in the history
Optix bsdf
  • Loading branch information
iaomw authored Oct 19, 2023
2 parents 1eef107 + 4bb60c9 commit 2795120
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 25 deletions.
21 changes: 12 additions & 9 deletions zeno/src/nodes/mtl/ShaderFinalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ struct ShaderFinalize : INode {

{1, "mat_specTrans"},
{3, "mat_transColor"},
{1, "mat_clarity"},
{3, "mat_transParam"},
{1, "mat_transDepth"},
{3, "mat_transTint"},
{1, "mat_transTintDepth"},
{1, "mat_transDistance"},
{3, "mat_transScatterColor"},
{1, "mat_ior"},

{1, "mat_flatness"},
Expand Down Expand Up @@ -107,9 +108,10 @@ struct ShaderFinalize : INode {

get_input<IObject>("specTrans", std::make_shared<NumericObject>(float(0.0f))),
get_input<IObject>("transColor", std::make_shared<NumericObject>(vec3f(1.0f))),
get_input<IObject>("clarity", std::make_shared<NumericObject>(float(1.0f))),
get_input<IObject>("transParam", std::make_shared<NumericObject>(vec3f(1.0f))),
get_input<IObject>("transDepth", std::make_shared<NumericObject>(float(1.0f))),
get_input<IObject>("transTint", std::make_shared<NumericObject>(vec3f(1.0f))),
get_input<IObject>("transTintDepth", std::make_shared<NumericObject>(float(1.0f))),
get_input<IObject>("transDistance", std::make_shared<NumericObject>(float(1.0f))),
get_input<IObject>("transScatterColor", std::make_shared<NumericObject>(vec3f(1.0f))),
get_input<IObject>("ior", std::make_shared<NumericObject>(float(1.5f))),

get_input<IObject>("flatness", std::make_shared<NumericObject>(float(0.0f))),
Expand Down Expand Up @@ -276,9 +278,10 @@ ZENDEFNODE(ShaderFinalize, {

{"float", "specTrans", "0.0"},
{"vec3f", "transColor", "1.0,1.0,1.0"},
{"float", "clarity", "0.0"},
{"vec3f", "transParam", "1.0,1.0,1.0"},
{"float", "transDepth", "0.0"},
{"vec3f", "transTint", "1.0,1.0,1.0"},
{"float", "transTintDepth", "0.0"},
{"float", "transDistance", "10.0"},
{"vec3f", "transScatterColor", "1.0,1.0,1.0"},
{"float", "ior", "1.5"},

{"float", "flatness", "0.0"},
Expand Down
18 changes: 10 additions & 8 deletions zenovis/xinxinoptix/DeflMatShader.cu
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ static __inline__ __device__ MatOutput evalMat(cudaTextureObject_t zenotex[], fl

float mat_specTrans = 0.0f;
vec3 mat_transColor = vec3(1.0f,1.0f,1.0f);
float mat_clarity = 0.0f;
vec3 mat_transParam = vec3(1.0f,1.0f,1.0f);
float mat_transDepth = 0.0f;
vec3 mat_transTint = vec3(1.0f,1.0f,1.0f);
float mat_transTintDepth = 0.0f;
float mat_transDistance = 0.0f;
vec3 mat_transScatterColor = vec3(1.0f,1.0f,1.0f);
float mat_ior = 1.0f;

float mat_flatness = 0.0f;
Expand Down Expand Up @@ -123,9 +124,10 @@ static __inline__ __device__ MatOutput evalMat(cudaTextureObject_t zenotex[], fl

mats.specTrans = clamp(mat_specTrans, 0.0f, 1.0f);
mats.transColor = mat_transColor;
mats.clarity = clamp(mat_clarity,0.0f,1.0f);
mats.transParam = mat_transParam;
mats.transDepth = max(0.0f,mat_transDepth);
mats.transTint = mat_transTint;
mats.transTintDepth = max(0.0f,mat_transTintDepth);
mats.transDistance = max(mat_transDistance,0.1f);
mats.transScatterColor = mat_transScatterColor;
mats.ior = max(0.0f,mat_ior);


Expand Down Expand Up @@ -662,7 +664,7 @@ extern "C" __global__ void __closesthit__radiance()

bool next_ray_is_going_inside = false;
mats.sssParam = mats.subsurface>0 ? mats.subsurface*mats.sssParam : mats.sssParam;
mats.subsurface = mats.subsurface>0 ? 1 : 0;
//mats.subsurface = mats.subsurface>0 ? 1 : 0;

/* MODME */

Expand Down Expand Up @@ -912,7 +914,7 @@ extern "C" __global__ void __closesthit__radiance()
vec3 channelPDF = vec3(1.0f/3.0f);
prd->pushMat(extinction);
prd->isSS = false;
prd->scatterDistance = 1000.0f * mats.clarity * mats.clarity;
prd->scatterDistance = mats.transDistance;
prd->maxDistance = mats.scatterStep>0.5f? DisneyBSDF::SampleDistance(prd->seed, prd->scatterDistance) : 1e16f;
} else {

Expand Down
7 changes: 4 additions & 3 deletions zenovis/xinxinoptix/DisneyBSDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ namespace DisneyBSDF{
}

static __inline__ __device__
vec3 CalculateExtinction(vec3 apparantColor, float scatterDistance)
vec3 CalculateExtinction(vec3 apparantColor, float scaler)
{
return 1.0/(max(apparantColor * scatterDistance,vec3(0.000001)));
// return 1.0/(max(apparantColor * scaler,vec3(0.000001)));
return (1.0f - apparantColor) * scaler;
}

static __inline__ __device__
Expand Down Expand Up @@ -694,7 +695,7 @@ namespace DisneyBSDF{
wi = normalize(refract(wo, wm, entering?1.0f/mat.ior:mat.ior));
flag = transmissionEvent;
isTrans = true;
extinction = CalculateExtinction(mat.transParam, mat.transDepth);
extinction = CalculateExtinction(mat.transTint, mat.transTintDepth);
extinction = entering? extinction : vec3(0.0f);
}

Expand Down
9 changes: 6 additions & 3 deletions zenovis/xinxinoptix/IOMat.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ struct MatOutput {

float specTrans;
vec3 transColor;
vec3 transParam;
float clarity;
float transDepth;
vec3 transTint;
float transTintDepth;
float transDistance;
vec3 transScatterColor;



float subsurface;
vec3 sssColor;
Expand Down
2 changes: 1 addition & 1 deletion zenovis/xinxinoptix/PTKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ extern "C" __global__ void __raygen__rg()

float r0 = r01.x * 2.0f * M_PIf;
float r1 = r01.y * aperture * aperture;
r1 = sqrt(r1);
r1 = sqrtf(r1);

float3 eye_shake = r1 * ( cosf(r0)* normalize(cam.right) + sinf(r0)* normalize(cam.up)); // Camera local space
float3 ray_origin = cam.eye + eye_shake;
Expand Down
2 changes: 1 addition & 1 deletion zenovis/xinxinoptix/volume.cu
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ extern "C" __global__ void __closesthit__radiance_volume()
testPRD.vol_t1 = _FLT_MAX_;
testPRD.test_distance = true;
testPRD.isSS = false;
testPRD.opacity = 0.0f;


uint16_t _mask_ = EverythingMask ^ VolumeMatMask;

Expand Down

0 comments on commit 2795120

Please sign in to comment.