diff --git a/zeno/src/nodes/mtl/ShaderFinalize.cpp b/zeno/src/nodes/mtl/ShaderFinalize.cpp index 9dfb48bbe4..d76ffd260a 100644 --- a/zeno/src/nodes/mtl/ShaderFinalize.cpp +++ b/zeno/src/nodes/mtl/ShaderFinalize.cpp @@ -31,27 +31,36 @@ struct ShaderFinalize : INode { auto code = em.finalizeCode({ {1, "mat_base"}, {3, "mat_basecolor"}, - {1, "mat_metallic"}, {1, "mat_roughness"}, + {1, "mat_metallic"}, + {3, "mat_metalColor"}, {1, "mat_specular"}, - {1, "mat_subsurface"}, - {1, "mat_thickness"}, - {3, "mat_sssParam"}, - {3, "mat_sssColor"}, {1, "mat_specularTint"}, {1, "mat_anisotropic"}, {1, "mat_anisoRotation"}, + + {1, "mat_subsurface"}, + {3, "mat_sssParam"}, + {3, "mat_sssColor"}, + {1, "mat_scatterDistance"}, + {1, "mat_scatterStep"}, + {1, "mat_sheen"}, {1, "mat_sheenTint"}, + {1, "mat_clearcoat"}, - {1, "mat_clearcoatGloss"}, + {3, "mat_clearcoatColor"}, {1, "mat_clearcoatRoughness"}, {1, "mat_clearcoatIOR"}, + {1, "mat_specTrans"}, + {3, "mat_transColor"}, + {1, "mat_clarity"}, + {3, "mat_transParam"}, + {1, "mat_transDepth"}, {1, "mat_ior"}, + {1, "mat_flatness"}, - {1, "mat_scatterDistance"}, - {1, "mat_scatterStep"}, {1, "mat_thin"}, {1, "mat_doubleSide"}, {3, "mat_normal"}, @@ -61,6 +70,7 @@ struct ShaderFinalize : INode { {3, "mat_emission"}, {3, "mat_reflectance"}, {1, "mat_opacity"}, + {1, "mat_thickness"}, {1, "vol_depth"}, {1, "vol_extinction"}, @@ -73,27 +83,36 @@ struct ShaderFinalize : INode { }, { get_input("base", std::make_shared(float(1.0f))), get_input("basecolor", std::make_shared(vec3f(1.0f))), - get_input("metallic", std::make_shared(float(0.0f))), get_input("roughness", std::make_shared(float(0.4f))), + get_input("metallic", std::make_shared(float(0.0f))), + get_input("metalColor", std::make_shared(vec3f(1.0f))), get_input("specular", std::make_shared(float(1.0f))), - get_input("subsurface", std::make_shared(float(0.0f))), - get_input("thickness", std::make_shared(float(0.0f))), - get_input("sssParam", std::make_shared(vec3f(1.0f))), - get_input("sssColor", std::make_shared(vec3f(1.0f))), get_input("specularTint", std::make_shared(float(0.0f))), get_input("anisotropic", std::make_shared(float(0.0f))), get_input("anisoRotation", std::make_shared(float(0.0f))), + + get_input("subsurface", std::make_shared(float(0.0f))), + get_input("sssParam", std::make_shared(vec3f(1.0f))), + get_input("sssColor", std::make_shared(vec3f(1.0f))), + get_input("scatterDistance", std::make_shared(float(10000))), + get_input("scatterStep", std::make_shared(float(0))), + get_input("sheen", std::make_shared(float(0.0f))), get_input("sheenTint", std::make_shared(float(0.5f))), + get_input("clearcoat", std::make_shared(float(0.0f))), - get_input("clearcoatGloss", std::make_shared(float(1.0f))), + get_input("clearcoatColor", std::make_shared(vec3f(1.0f))), get_input("clearcoatRoughness", std::make_shared(float(0.0f))), get_input("clearcoatIOR", std::make_shared(float(1.5f))), + get_input("specTrans", std::make_shared(float(0.0f))), + get_input("transColor", std::make_shared(vec3f(1.0f))), + get_input("clarity", std::make_shared(float(1.0f))), + get_input("transParam", std::make_shared(vec3f(1.0f))), + get_input("transDepth", std::make_shared(float(1.0f))), get_input("ior", std::make_shared(float(1.5f))), + get_input("flatness", std::make_shared(float(0.0f))), - get_input("scatterDistance", std::make_shared(float(10000))), - get_input("scatterStep", std::make_shared(float(0))), get_input("thin", std::make_shared(float(0.0f))), get_input("doubleSide", std::make_shared(float(0.0f))), get_input("normal", std::make_shared(vec3f(0, 0, 1))), @@ -103,7 +122,8 @@ struct ShaderFinalize : INode { get_input("emission", std::make_shared(vec3f(0))), get_input("reflectance", std::make_shared(vec3f(1))), get_input("opacity", std::make_shared(float(0.0))), - + get_input("thickness", std::make_shared(float(0.0f))), + get_input("vol_depth", std::make_shared((float)(99))), get_input("vol_extinction", std::make_shared(float(1))), get_input("vol_sample_albedo", std::make_shared(vec3f(0.5))), @@ -231,30 +251,37 @@ ZENDEFNODE(ShaderFinalize, { { {"float", "base", "1"}, {"vec3f", "basecolor", "1,1,1"}, - {"float", "metallic", "0.0"}, {"float", "roughness", "0.4"}, + {"float", "metallic", "0.0"}, + {"vec3f", "metalColor","1.0,1.0,1.0"}, {"float", "specular", "1.0"}, - {"float", "subsurface", "0.0"}, - {"float", "thickness", "0.0"}, + {"float", "specularTint", "0.0"}, + {"float", "anisotropic", "0.0"}, + {"float", "anisoRotation", "0.0"}, + {"float", "subsurface", "0.0"}, {"enum Fixed Adaptive", "sssRadius", "Fixed"}, {"vec3f", "sssParam", "1.0,1.0,1.0"}, {"vec3f", "sssColor", "1.0,1.0,1.0"}, + {"float", "scatterDistance", "10000"}, + {"float", "scatterStep", "0"}, - {"float", "specularTint", "0.0"}, - {"float", "anisotropic", "0.0"}, - {"float", "anisoRotation", "0.0"}, {"float", "sheen", "0.0"}, {"float", "sheenTint", "0.0"}, + {"float", "clearcoat", "0.0"}, - {"float", "clearcoatGloss", "1.0"}, + {"vec3f", "clearcoatColor", "1.0,1.0,1.0"}, {"float", "clearcoatRoughness", "0.0"}, {"float", "clearcoatIOR", "1.5"}, + {"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"}, {"float", "ior", "1.5"}, + {"float", "flatness", "0.0"}, - {"float", "scatterDistance", "10000"}, - {"float", "scatterStep", "0"}, {"float", "thin", "0.0"}, {"float", "doubleSide", "0.0"}, {"vec3f", "normal", "0,0,1"}, @@ -264,6 +291,8 @@ ZENDEFNODE(ShaderFinalize, { {"vec3f", "emission", "0,0,0"}, {"vec3f", "reflectance", "1,1,1"}, {"float", "opacity", "0"}, + {"float", "thickness", "0.0"}, + {"string", "commonCode"}, {"string", "extensionsCode"}, {"string", "mtlid", "Mat1"}, diff --git a/zenovis/xinxinoptix/DeflMatShader.cu b/zenovis/xinxinoptix/DeflMatShader.cu index 4f9787ded1..513df43ebd 100644 --- a/zenovis/xinxinoptix/DeflMatShader.cu +++ b/zenovis/xinxinoptix/DeflMatShader.cu @@ -44,32 +44,43 @@ static __inline__ __device__ MatOutput evalMat(cudaTextureObject_t zenotex[], fl /** generated code here beg **/ //GENERATED_BEGIN_MARK /* MODME */ - float mat_base = 1.0; - vec3 mat_basecolor = vec3(1.0, 1.0, 1.0); - float mat_metallic = 0.0; - float mat_roughness = 0.5; - float mat_subsurface = 0.0; - float mat_specular = 0; - float mat_specularTint = 0.0; - float mat_anisotropic = 0.0; - float mat_anisoRotation = 0.0; - float mat_sheen = 0.0; - float mat_sheenTint = 0.0; - float mat_clearcoat = 0.0; - float mat_clearcoatGloss = 0.0; - float mat_clearcoatRoughness = 0.0; - float mat_clearcoatIOR = 1.5; - float mat_opacity = 0.0; - float mat_specTrans = 0.0; - float mat_ior = 1.0; - float mat_scatterDistance = 0.0; - float mat_flatness = 0.0; - float mat_thin = 0.0; - float mat_doubleSide= 0.0; + float mat_base = 1.0f; + vec3 mat_basecolor = vec3(1.0f, 1.0f, 1.0f); + float mat_roughness = 0.5f; + float mat_metallic = 0.0f; + vec3 mat_metalColor = vec3(1.0f,1.0f,1.0f); + float mat_specular = 0.0f; + float mat_specularTint = 0.0f; + float mat_anisotropic = 0.0f; + float mat_anisoRotation = 0.0f; + + float mat_subsurface = 0.0f; + vec3 mat_sssParam = vec3(0.0f,0.0f,0.0f); + vec3 mat_sssColor = vec3(0.0f,0.0f,0.0f); + float mat_scatterDistance = 0.0f; float mat_scatterStep = 0.0f; + + float mat_sheen = 0.0f; + float mat_sheenTint = 0.0f; + + + float mat_clearcoat = 0.0f; + vec3 mat_clearcoatColor = vec3(1.0f,1.0f,1.0f); + float mat_clearcoatRoughness = 0.0f; + float mat_clearcoatIOR = 1.5f; + float mat_opacity = 0.0f; + + 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; + float mat_ior = 1.0f; + + float mat_flatness = 0.0f; + float mat_thin = 0.0f; + float mat_doubleSide= 0.0f; float mat_smoothness = 0.0f; - vec3 mat_sssColor = vec3(0.0f,0.0f,0.0f); - vec3 mat_sssParam = vec3(0.0f,0.0f,0.0f); vec3 mat_normal = vec3(0.0f, 0.0f, 1.0f); float mat_emissionIntensity = float(0); vec3 mat_emission = vec3(1.0f, 1.0f, 1.0f); @@ -77,6 +88,7 @@ static __inline__ __device__ MatOutput evalMat(cudaTextureObject_t zenotex[], fl float mat_NoL = 1.0f; float mat_LoV = 1.0f; vec3 mat_reflectance = att_reflectance; + vec3 mat_transColor = vec3(1.0f,1.0f,1.0f); //GENERATED_END_MARK /** generated code here end **/ MatOutput mats; @@ -87,31 +99,47 @@ static __inline__ __device__ MatOutput evalMat(cudaTextureObject_t zenotex[], fl }else { /* MODME */ mats.basecolor = mat_base * mat_basecolor; - mats.metallic = clamp(mat_metallic, 0.0f, 1.0f); mats.roughness = clamp(mat_roughness, 0.01, 0.99); - mats.subsurface = mat_subsurface; + mats.metallic = clamp(mat_metallic, 0.0f, 1.0f); + mats.metalColor = mat_metalColor; mats.specular = mat_specular; mats.specularTint = mat_specularTint; mats.anisotropic = clamp(mat_anisotropic, 0.0f, 1.0f); mats.anisoRotation = clamp(mat_anisoRotation, 0.0f, 1.0f); + + mats.subsurface = mat_subsurface; + mats.sssColor = mat_sssColor; + mats.sssParam = mat_sssParam; + mats.scatterDistance = max(0.0f,mat_scatterDistance); + mats.scatterStep = clamp(mat_scatterStep,0.0f,1.0f); + mats.sheen = mat_sheen; mats.sheenTint = mat_sheenTint; + mats.clearcoat = clamp(mat_clearcoat, 0.0f, 1.0f); - mats.clearcoatGloss = mat_clearcoatGloss; + mats.clearcoatColor = mat_clearcoatColor; mats.clearcoatRoughness = clamp(mat_clearcoatRoughness, 0.01, 0.99); mats.clearcoatIOR = mat_clearcoatIOR; + + 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.ior = max(0.0f,mat_ior); + + mats.opacity = mat_opacity; mats.nrm = mat_normal; mats.emission = mat_emissionIntensity * mat_emission; - mats.specTrans = clamp(mat_specTrans, 0.0f, 1.0f); - mats.ior = mat_ior; - mats.scatterDistance = mat_scatterDistance; + + + mats.flatness = mat_flatness; mats.thin = mat_thin; mats.doubleSide = mat_doubleSide; - mats.sssColor = mat_sssColor; - mats.sssParam = mat_sssParam; - mats.scatterStep = mat_scatterStep; + + mats.smoothness = mat_smoothness; return mats; } @@ -332,7 +360,6 @@ extern "C" __global__ void __anyhit__shadow_cutout() auto sheen = mats.sheen; auto sheenTint = mats.sheenTint; auto clearcoat = mats.clearcoat; - auto clearcoatGloss = mats.clearcoatGloss; auto opacity = mats.opacity; auto flatness = mats.flatness; auto specTrans = mats.specTrans; @@ -634,56 +661,29 @@ 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; /* MODME */ - auto basecolor = mats.basecolor; - auto metallic = mats.metallic; - auto roughness = mats.roughness; + if(prd->diffDepth>=1) - roughness = clamp(roughness, 0.2,0.99); + mats.roughness = clamp(mats.roughness, 0.2,0.99); if(prd->diffDepth>=2) - roughness = clamp(roughness, 0.3,0.99); + mats.roughness = clamp(mats.roughness, 0.3,0.99); if(prd->diffDepth>=3) - roughness = clamp(roughness, 0.5,0.99); - - auto subsurface = mats.subsurface; - auto specular = mats.specular; - auto specularTint = mats.specularTint; - auto anisotropic = mats.anisotropic; - auto anisoRotation = mats.anisoRotation; - auto sheen = mats.sheen; - auto sheenTint = mats.sheenTint; - auto clearcoat = mats.clearcoat; - auto clearcoatGloss = mats.clearcoatGloss; - auto ccRough = mats.clearcoatRoughness; - auto ccIor = mats.clearcoatIOR; - auto opacity = mats.opacity; - auto flatness = mats.flatness; - auto specTrans = mats.specTrans; - auto scatterDistance = mats.scatterDistance; - auto ior = mats.ior; - auto thin = mats.thin; - - auto sssColor = mats.sssColor; - auto sssParam = mats.sssParam; + mats.roughness = clamp(mats.roughness, 0.5,0.99); - auto scatterStep = mats.scatterStep; - sssParam = subsurface>0? sssParam*subsurface : sssParam; - subsurface = subsurface>0? 1 : 0; - //discard fully opacity pixels - //opacity = clamp(opacity, 0.0f, 0.99f); - prd->opacity = opacity; if(prd->isSS == true) { - basecolor = vec3(1.0f); - roughness = 1.0; - anisotropic = 0; - sheen = 0; - clearcoat = 0; - specTrans = 0; - ior = 1; + mats.basecolor = vec3(1.0f); + mats.roughness = 1.0; + mats.anisotropic = 0; + mats.sheen = 0; + mats.clearcoat = 0; + mats.specTrans = 0; + mats.ior = 1; } - if(prd->isSS == true && subsurface>0 && dot(-normalize(ray_dir), N)>0) + if(prd->isSS == true && mats.subsurface>0 && dot(-normalize(ray_dir), N)>0) { prd->attenuation2 = make_float3(0,0,0); prd->attenuation = make_float3(0,0,0); @@ -691,12 +691,11 @@ extern "C" __global__ void __closesthit__radiance() prd->done = true; return; } - if(prd->isSS == true && subsurface==0 ) + if(prd->isSS == true && mats.subsurface==0 ) { prd->passed = true; prd->samplePdf = 1.0f; prd->radiance = make_float3(0.0f, 0.0f, 0.0f); - prd->opacity = 0; prd->readMat(prd->sigma_t, prd->ss_alpha); auto trans = DisneyBSDF::Transmission2(prd->sigma_s(), prd->sigma_t, prd->channelPDF, optixGetRayTmax(), true); prd->attenuation2 *= trans; @@ -728,7 +727,7 @@ extern "C" __global__ void __closesthit__radiance() } prd->prob2 = prd->prob; prd->passed = false; - if(opacity>0.99f) + if(mats.opacity>0.99f) { if (prd->curMatIdx > 0) { vec3 sigma_t, ss_alpha; @@ -748,11 +747,11 @@ extern "C" __global__ void __closesthit__radiance() prd->offsetUpdateRay(P, ray_dir); return; } - if(opacity<=0.99f) + if(mats.opacity<=0.99f) { //we have some simple transparent thing //roll a dice to see if just pass - if(rnd(prd->seed)seed)curMatIdx > 0) { vec3 sigma_t, ss_alpha; @@ -779,7 +778,7 @@ extern "C" __global__ void __closesthit__radiance() return; } } - if(prd->depth==0&&flatness>0.5) + if(prd->depth==0&&mats.flatness>0.5) { prd->radiance = make_float3(0.0f); prd->done = true; @@ -820,32 +819,13 @@ extern "C" __global__ void __closesthit__radiance() while(DisneyBSDF::SampleDisney2( prd->seed, prd->eventseed, - basecolor, - sssParam, - sssColor, - metallic, - subsurface, - specular, - roughness, - specularTint, - anisotropic, - anisoRotation, - sheen, - sheenTint, - clearcoat, - clearcoatGloss, - ccRough, - ccIor, - flatness, - specTrans, - scatterDistance, - ior, + mats, T, B, N, prd->geometryNormal, -normalize(ray_dir), - thin>0.5f, + mats.thin>0.5f, next_ray_is_going_inside, wi, reflectance, @@ -867,10 +847,11 @@ extern "C" __global__ void __closesthit__radiance() prd->done = fPdf>0?true:prd->done; flag = DisneyBSDF::scatterEvent; } - prd->samplePdf = fPdf; - reflectance = fPdf>0?reflectance/fPdf:vec3(0.0f); - prd->done = fPdf>0?prd->done:true; - prd->isSS = isSS; + + prd->samplePdf = fPdf; + reflectance = fPdf>0?reflectance/fPdf:vec3(0.0f); + prd->done = fPdf>0?prd->done:true; + prd->isSS = isSS; pdf = 1.0; if(isDiff || prd->diffDepth>0){ prd->diffDepth++; @@ -887,7 +868,7 @@ extern "C" __global__ void __closesthit__radiance() next_ray_is_going_inside = dot(vec3(prd->geometryNormal),vec3(wi))<=0; } - if(thin>0.5f || mats.doubleSide>0.5f) + if(mats.thin>0.5f || mats.doubleSide>0.5f) { if (prd->curMatIdx > 0) { vec3 sigma_t, ss_alpha; @@ -918,7 +899,7 @@ extern "C" __global__ void __closesthit__radiance() if (prd->curMatIdx > 0) { vec3 sigma_t, ss_alpha; - //vec3 sigma_t, ss_alpha; + //vec3 sigma_t, ss_alpha;0 prd->readMat(sigma_t, ss_alpha); if (ss_alpha.x < 0.0f) { // is inside Glass prd->attenuation *= DisneyBSDF::Transmission(sigma_t, optixGetRayTmax()); @@ -929,9 +910,10 @@ extern "C" __global__ void __closesthit__radiance() prd->channelPDF = vec3(1.0f/3.0f); if (isTrans) { vec3 channelPDF = vec3(1.0f/3.0f); - prd->maxDistance = scatterStep>0.5f? DisneyBSDF::SampleDistance2(prd->seed, extinction, extinction, channelPDF) : 1e16f; prd->pushMat(extinction); prd->isSS = false; + prd->scatterDistance = 1000.0f * mats.clarity * mats.clarity; + prd->maxDistance = mats.scatterStep>0.5f? DisneyBSDF::SampleDistance(prd->seed, prd->scatterDistance) : 1e16f; } else { prd->maxDistance = DisneyBSDF::SampleDistance2(prd->seed, vec3(prd->attenuation) * prd->ss_alpha, prd->sigma_t, prd->channelPDF); @@ -944,10 +926,11 @@ extern "C" __global__ void __closesthit__radiance() // already calculated in BxDF prd->pushMat(prd->sigma_t, prd->ss_alpha); prd->isSS = true; + prd->scatterDistance = mats.scatterDistance; } - prd->scatterDistance = scatterDistance; - prd->scatterStep = scatterStep; + + prd->scatterStep = mats.scatterStep; } else{ outToIn = false; @@ -997,7 +980,7 @@ extern "C" __global__ void __closesthit__radiance() else if (ss_alpha.x<0.0f) { // Glass trans = DisneyBSDF::Transmission(sigma_t, optixGetRayTmax()); vec3 channelPDF = vec3(1.0f/3.0f); - prd->maxDistance = scatterStep>0.5f? DisneyBSDF::SampleDistance2(prd->seed, sigma_t, sigma_t, channelPDF) : 1e16f; + prd->maxDistance = mats.scatterStep>0.5f? DisneyBSDF::SampleDistance2(prd->seed, sigma_t, sigma_t, channelPDF) : 1e16f; } else { // SSS trans = DisneyBSDF::Transmission2(sigma_t * ss_alpha, sigma_t, prd->channelPDF, optixGetRayTmax(), true); prd->maxDistance = DisneyBSDF::SampleDistance2(prd->seed, vec3(prd->attenuation) * ss_alpha, sigma_t, prd->channelPDF); @@ -1019,7 +1002,7 @@ extern "C" __global__ void __closesthit__radiance() prd->medium = next_ray_is_going_inside?DisneyBSDF::PhaseFunctions::isotropic : prd->curMatIdx==0?DisneyBSDF::PhaseFunctions::vacuum : DisneyBSDF::PhaseFunctions::isotropic; - if(thin>0.5f){ + if(mats.thin>0.5f){ vec3 H = normalize(vec3(normalize(wi)) + vec3(-normalize(ray_dir))); attrs.N = N; attrs.T = cross(B,N); @@ -1027,7 +1010,7 @@ extern "C" __global__ void __closesthit__radiance() attrs.V = vec3(-normalize(ray_dir)); attrs.H = normalize(H); attrs.reflectance = reflectance; - attrs.fresnel = DisneyBSDF::DisneyFresnel( basecolor, metallic, ior, specularTint, dot(attrs.H, attrs.V), dot(attrs.H, attrs.L), false); + attrs.fresnel = DisneyBSDF::DisneyFresnel(mats.basecolor, mats.metallic, mats.ior, mats.specularTint, dot(attrs.H, attrs.V), dot(attrs.H, attrs.L), false); MatOutput mat2 = evalReflectance(zenotex, rt_data->uniforms, attrs); reflectance = mat2.reflectance; } @@ -1040,7 +1023,7 @@ extern "C" __global__ void __closesthit__radiance() prd->radiance = make_float3(0.0f,0.0f,0.0f); if(prd->depth>=3) - roughness = clamp(roughness, 0.5f,0.99f); + mats.roughness = clamp(mats.roughness, 0.5f,0.99f); vec3 rd, rs, rt; // captured by lambda @@ -1049,14 +1032,12 @@ extern "C" __global__ void __closesthit__radiance() const auto& L = _wi_; // pre-normalized const vec3& V = _wo_; // pre-normalized - float3 lbrdf = DisneyBSDF::EvaluateDisney2(illum, - basecolor, sssColor, metallic, subsurface, specular, max(prd->minSpecRough,roughness), specularTint, anisotropic, anisoRotation, sheen, sheenTint, - clearcoat, clearcoatGloss, ccRough, ccIor, specTrans, scatterDistance, ior, flatness, L, V, T, B, N,prd->geometryNormal, - thin > 0.5f, flag == DisneyBSDF::transmissionEvent ? inToOut : next_ray_is_going_inside, thisPDF, rrPdf, + float3 lbrdf = DisneyBSDF::EvaluateDisney2(illum,mats, L, V, T, B, N,prd->geometryNormal, + mats.thin > 0.5f, flag == DisneyBSDF::transmissionEvent ? inToOut : next_ray_is_going_inside, thisPDF, rrPdf, dot(N, L), rd, rs, rt); MatOutput mat2; - if(thin>0.5f){ + if(mats.thin>0.5f){ vec3 H = normalize(vec3(normalize(L)) + V); attrs.N = N; attrs.T = cross(B,N); @@ -1064,11 +1045,11 @@ extern "C" __global__ void __closesthit__radiance() attrs.V = V; attrs.H = normalize(H); attrs.reflectance = lbrdf; - attrs.fresnel = DisneyBSDF::DisneyFresnel( basecolor, metallic, ior, specularTint, dot(attrs.H, attrs.V), dot(attrs.H, attrs.L), false); + attrs.fresnel = DisneyBSDF::DisneyFresnel( mats.basecolor, mats.metallic, mats.ior, mats.specularTint, dot(attrs.H, attrs.V), dot(attrs.H, attrs.L), false); mat2 = evalReflectance(zenotex, rt_data->uniforms, attrs); } - return (thin>0.5f? float3(mat2.reflectance):lbrdf); + return (mats.thin>0.5f? float3(mat2.reflectance):lbrdf); }; auto taskAux = [&](const vec3& weight) { @@ -1080,13 +1061,13 @@ extern "C" __global__ void __closesthit__radiance() RadiancePRD shadow_prd {}; shadow_prd.seed = prd->seed; shadow_prd.shadowAttanuation = make_float3(1.0f, 1.0f, 1.0f); - shadow_prd.nonThinTransHit = (thin == false && specTrans > 0) ? 1 : 0; + shadow_prd.nonThinTransHit = (mats.thin == false && mats.specTrans > 0) ? 1 : 0; prd->direction = normalize(wi); DirectLighting(prd, shadow_prd, shadingP, ray_dir, evalBxDF, &taskAux); - if(thin<0.5f && mats.doubleSide<0.5f){ + if(mats.thin<0.5f && mats.doubleSide<0.5f){ prd->origin = rtgems::offset_ray(P, (next_ray_is_going_inside)? -prd->geometryNormal : prd->geometryNormal); } else { diff --git a/zenovis/xinxinoptix/DisneyBSDF.h b/zenovis/xinxinoptix/DisneyBSDF.h index 045299e573..bcbf50d82f 100644 --- a/zenovis/xinxinoptix/DisneyBSDF.h +++ b/zenovis/xinxinoptix/DisneyBSDF.h @@ -1,36 +1,9 @@ #pragma once #include "zxxglslvec.h" #include "TraceStuff.h" - +#include "IOMat.h" #include "DisneyBRDF.h" -//list of component: -//Sheen -//Clearcoat -//Specular BRDF -//Specular BSDF -//Diffuse BRDF -// -//params -// -//vec3 baseColor, -//float metallic, -//float subsurface, -//float specular, -//float roughness, -//float specularTint, -//float anisotropic, -//float sheen, -//float sheenTint, -//float clearCoat, -//float clearcoatGloss, - -//vec3 transmiianceColor -//float flatness -//float specTrans, -//float scatterDistance, -//float ior, - namespace DisneyBSDF{ enum SurfaceEventFlags{ scatterEvent = 0x01, @@ -208,6 +181,13 @@ namespace DisneyBSDF{ return s; } + static __inline__ __device__ + float SampleDistance(unsigned int &seed, float scatterDistance){ + float r = rnd(seed); + return -log(max(1.0f-rnd(seed),_FLT_MIN_)) * scatterDistance; + + } + static __inline__ __device__ void world2local(vec3& v, vec3 T, vec3 B, vec3 N){ v = normalize(vec3(dot(T,v), dot(B,v), dot(N,v))); @@ -271,26 +251,7 @@ namespace DisneyBSDF{ static __inline__ __device__ float3 EvaluateDisney2( vec3 illum, - vec3 baseColor, - vec3 sssColor, - float metallic, - float subsurface, - float specular, - float roughness, - float specularTint, - float anisotropic, - float anisoRotation, - float sheen, - float sheenTint, - float clearCoat, - float clearcoatGloss, - float ccRough, - float ccIor, - float specTrans, - float scatterDistance, - float ior, - float flatness, - + struct MatOutput mat, vec3 wi, //in world space vec3 wo, //in world space vec3 T, @@ -312,10 +273,10 @@ namespace DisneyBSDF{ { wo = normalize(wo - 1.01f * dot(wo, N) * N); } - float eta = dot(wo, N)>0?ior:1.0f/ior; + float eta = dot(wo, N)>0?mat.ior:1.0f/mat.ior; vec3 f = vec3(0.0f); fPdf = 0.0f; - rotateTangent(T, B, N, anisoRotation * 2 * 3.1415926f); + rotateTangent(T, B, N, mat.anisoRotation * 2 * 3.1415926f); // Onb tbn = Onb(N); world2local(wi, T, B, N); world2local(wo, T, B, N); @@ -328,22 +289,22 @@ namespace DisneyBSDF{ vec3 wm = reflect? normalize(wi + wo):normalize(wi + wo * eta); wm = wm.z<0.0f?-wm:wm; - BRDFBasics::TintColors(mix(baseColor, sssColor, subsurface), eta, specularTint, sheenTint, F0, Csheen, Cspec0); + BRDFBasics::TintColors(mix(mat.basecolor, mat.sssColor, mat.subsurface), eta, mat.specularTint, mat.sheenTint, F0, Csheen, Cspec0); Cspec0 = Cspec0; //material layer mix weight - float dielectricWt = (1.0 - metallic) * (1.0 - specTrans); - float metalWt = metallic; - float glassWt = (1.0 - metallic) * specTrans; + float dielectricWt = (1.0 - mat.metallic) * (1.0 - mat.specTrans); + float metalWt = mat.metallic; + float glassWt = (1.0 - mat.metallic) * mat.specTrans; float schlickWt = BRDFBasics::SchlickWeight(abs(dot(wo, wm))); - float psss = subsurface; + float psss = mat.subsurface; //event probability float diffPr = dielectricWt; float sssPr = dielectricWt * psss; float dielectricPr = dielectricWt * Luminance(mix(Cspec0, vec3(1.0), schlickWt)); - float metalPr = metalWt * Luminance(mix(baseColor, vec3(1.0), schlickWt)); + float metalPr = metalWt * Luminance(mix(mat.basecolor, vec3(1.0), schlickWt)); float glassPr = glassWt; - float clearCtPr = 0.25 * clearCoat; + float clearCtPr = 0.25 * mat.clearcoat; float invTotalWt = 1.0 / (diffPr + sssPr + dielectricPr + metalPr + glassPr + clearCtPr); diffPr *= invTotalWt; @@ -372,7 +333,7 @@ namespace DisneyBSDF{ if(diffPr > 0.0 && reflect) { - vec3 d = BRDFBasics::EvalDisneyDiffuse(mix(baseColor,sssColor,subsurface), subsurface, roughness, sheen, + vec3 d = BRDFBasics::EvalDisneyDiffuse(mix(mat.basecolor,mat.sssColor,mat.subsurface), mat.subsurface, mat.roughness, mat.sheen, Csheen, wo, wi, wm, tmpPdf) * dielectricWt * illum; dterm = dterm + d; f = f + d; @@ -380,20 +341,20 @@ namespace DisneyBSDF{ } if(dielectricPr>0.0 && reflect) { - float F = BRDFBasics::DielectricFresnel(abs(dot(wm, wo)), ior); + float F = BRDFBasics::DielectricFresnel(abs(dot(wm, wo)), mat.ior); float ax, ay; - BRDFBasics::CalculateAnisotropicParams(roughness,anisotropic,ax,ay); + BRDFBasics::CalculateAnisotropicParams(mat.roughness,mat.anisotropic,ax,ay); vec3 s = BRDFBasics::EvalMicrofacetReflection(ax, ay, wo, wi, wm, - mix(Cspec0, vec3(1.0f), F) * specular * 0.5f, tmpPdf) * dielectricWt * illum; + mix(Cspec0, vec3(1.0f), F) * mat.specular * 0.5f, tmpPdf) * dielectricWt * illum; sterm = sterm + s; f = f + s; fPdf += tmpPdf * dielectricPr; } if(metalPr>0.0 && reflect) { - vec3 F = mix(baseColor, vec3(1.0), BRDFBasics::SchlickWeight(HoV)); + vec3 F = mix(mat.basecolor, vec3(1.0), BRDFBasics::SchlickWeight(HoV)); float ax, ay; - BRDFBasics::CalculateAnisotropicParams(roughness,anisotropic,ax,ay); + BRDFBasics::CalculateAnisotropicParams(mat.roughness,mat.anisotropic,ax,ay); vec3 s = BRDFBasics::EvalMicrofacetReflection(ax, ay, wo, wi, wm, F, tmpPdf) * metalWt * illum; sterm = sterm + s; f = f + s; @@ -405,47 +366,34 @@ namespace DisneyBSDF{ //float F = BRDFBasics::DielectricFresnel(, eta); float ax, ay; - BRDFBasics::CalculateAnisotropicParams(roughness,anisotropic,ax,ay); + BRDFBasics::CalculateAnisotropicParams(mat.roughness,mat.anisotropic,ax,ay); if (reflect) { vec3 wm = normalize(wi + wo); - float F = BRDFBasics::DielectricFresnel(abs(dot(wm, wo)), entering?ior:1.0/ior); - vec3 s = BRDFBasics::EvalMicrofacetReflection(ax, ay, wo, wi, wm, vec3(F) * specular, + float F = BRDFBasics::DielectricFresnel(abs(dot(wm, wo)), entering?mat.ior:1.0/mat.ior); + vec3 s = BRDFBasics::EvalMicrofacetReflection(ax, ay, wo, wi, wm, vec3(F) * mat.specular, tmpPdf) * glassWt; sterm = sterm + s; f = f + s; fPdf += tmpPdf * glassPr * F; } else { - if(thin || ior<1.01f) + if(thin || mat.ior<1.01f) { - vec3 t = sqrt(sssColor) * glassWt; + vec3 t = sqrt(mat.sssColor) * glassWt; tterm = tterm + t; f = f + t; fPdf += 1.0f * glassPr; }else { - vec3 wm = entering?-normalize(wo + ior * wi) : normalize(wo + 1.0f/ior * wi); - float F = BRDFBasics::DielectricFresnel(abs(dot(wm, wo)), entering?ior:1.0/ior); + vec3 wm = entering?-normalize(wo + mat.ior * wi) : normalize(wo + 1.0f/mat.ior * wi); + float F = BRDFBasics::DielectricFresnel(abs(dot(wm, wo)), entering?mat.ior:1.0/mat.ior); float tmpPdf; - vec3 brdf = BRDFBasics::EvalMicrofacetRefraction(sssColor, + vec3 brdf = BRDFBasics::EvalMicrofacetRefraction(mat.transColor, ax, ay, - entering? ior:1.0f/ior, + entering? mat.ior:1.0f/mat.ior, wo, wi, wm, vec3(F), tmpPdf); -// float tmpPdf1; -// wm = normalize(wi + wo * ior); -// vec3 brdf1 = BRDFBasics::EvalMicrofacetRefraction(sssColor, -// ax, ay, -// ior, -// wo, wi, wm, -// vec3(F), tmpPdf1); -// float tmpPdf2; -// wm = normalize(wo + wi * ior); -// vec3 brdf2 = BRDFBasics::EvalMicrofacetRefraction(sssColor, -// ax, ay, -// ior, -// wi, wo, wm, -// vec3(F), tmpPdf2); + vec3 t = brdf * glassWt * illum; tterm = tterm + t; f = f + t; @@ -457,8 +405,8 @@ namespace DisneyBSDF{ } if(clearCtPr>0.0 && reflect) { - vec3 s = BRDFBasics::EvalClearcoat(ccRough, wo, wi, - wm, tmpPdf) * 0.25 * clearCoat * illum; + vec3 s = BRDFBasics::EvalClearcoat(mat.clearcoatRoughness, wo, wi, + wm, tmpPdf) * 0.25 * mat.clearcoat * illum; sterm = sterm + s; f = f + s; fPdf += tmpPdf * clearCtPr; @@ -471,7 +419,7 @@ namespace DisneyBSDF{ float term = wo.z>0?FV:FL; float tmpPdf = trans? 1.0f : 0.0f;//0.5/M_PIf:0.0f; // vec3 d = 1.0f/M_PIf * (1.0f - 0.5f * term) * (trans?vec3(1.0f):vec3(0.0f)) * dielectricWt * subsurface; - vec3 d = (trans?vec3(1.0f):vec3(0.0f)) * dielectricWt * subsurface; + vec3 d = (trans?vec3(1.0f):vec3(0.0f)) * dielectricWt * mat.subsurface; dterm = dterm + d; f = f + d; fPdf += tmpPdf * sssPr; @@ -567,27 +515,7 @@ namespace DisneyBSDF{ bool SampleDisney2( unsigned int& seed, unsigned int& eventseed, - vec3 baseColor, - vec3 transmiianceColor, - vec3 sssColor, - float metallic, - float subsurface, - float specular, - float roughness, - float specularTint, - float anisotropic, - float anisoRotation, - float sheen, - float sheenTint, - float clearCoat, - float clearcoatGloss, - float ccRough, - float ccIor, - float flatness, - float specTrans, - float scatterDistance, - float ior, - + struct MatOutput mat, vec3 T, vec3 B, vec3 N, @@ -614,8 +542,8 @@ namespace DisneyBSDF{ { wo = normalize(wo - 1.01f * dot(wo, N) * N); } - float eta = dot(wo, N)>0?ior:1.0f/ior; - rotateTangent(T, B, N, anisoRotation * 2 * 3.1415926f); + float eta = dot(wo, N)>0?mat.ior:1.0f/mat.ior; + rotateTangent(T, B, N, mat.anisoRotation * 2 * 3.1415926f); world2local(wo, T, B, N); float2 r = sobolRnd(eventseed); float r1 = r.x; @@ -626,33 +554,33 @@ namespace DisneyBSDF{ vec3 Csheen, Cspec0; float F0; - BRDFBasics::TintColors(mix(baseColor, sssColor, subsurface), eta, specularTint, sheenTint, F0, Csheen, Cspec0); + BRDFBasics::TintColors(mix(mat.basecolor, mat.sssColor, mat.subsurface), eta, mat.specularTint, mat.sheenTint, F0, Csheen, Cspec0); Cspec0 = Cspec0; //material layer mix weight - float dielectricWt = (1.0 - metallic) * (1.0 - specTrans); - float metalWt = metallic; - float glassWt = (1.0 - metallic) * specTrans; + float dielectricWt = (1.0 - mat.metallic) * (1.0 - mat.specTrans); + float metalWt = mat.metallic; + float glassWt = (1.0 - mat.metallic) * mat.specTrans; float ax, ay; - BRDFBasics::CalculateAnisotropicParams(roughness,anisotropic,ax,ay); + BRDFBasics::CalculateAnisotropicParams(mat.roughness,mat.anisotropic,ax,ay); vec3 wm = BRDFBasics::SampleGGXVNDF(wo, ax, ay, r1, r2); float hov1 = abs(wo.z); float hov2 = abs(dot(wo, wm)); - float c = pow(smoothstep(0.0f,0.2f,roughness),2.0f); + float c = pow(smoothstep(0.0f,0.2f,mat.roughness),2.0f); float hov = mix(hov1, hov2, c); float schlickWt = BRDFBasics::SchlickWeight(hov); - float psss = subsurface; + float psss = mat.subsurface; //dielectricWt *= 1.0f - psub; //event probability float diffPr = dielectricWt ; float sssPr = dielectricWt * psss; float dielectricPr = dielectricWt * Luminance(mix(Cspec0, vec3(1.0), schlickWt)); - float metalPr = metalWt * Luminance(mix(baseColor, vec3(1.0), schlickWt)); + float metalPr = metalWt * Luminance(mix(mat.basecolor, vec3(1.0), schlickWt)); float glassPr = glassWt; - float clearCtPr = 0.25 * clearCoat; + float clearCtPr = 0.25 * mat.clearcoat; float invTotalWt = 1.0 / (diffPr + sssPr + dielectricPr + metalPr + glassPr + clearCtPr); diffPr *= invTotalWt; @@ -678,7 +606,7 @@ namespace DisneyBSDF{ auto first_hit_type = prd->first_hit_type; prd->first_hit_type = prd->depth==0?DIFFUSE_HIT:first_hit_type; - if(wo.z<0 && subsurface>0)//inside, scattering, go out for sure + if(wo.z<0 && mat.subsurface>0)//inside, scattering, go out for sure { wi = BRDFBasics::UniformSampleHemisphere(r1, r2); flag = transmissionEvent; @@ -698,9 +626,9 @@ namespace DisneyBSDF{ wi = -BRDFBasics::UniformSampleHemisphere(r1, r2); isSS = true; flag = transmissionEvent; - vec3 color = mix(baseColor, sssColor, subsurface); + vec3 color = mix(mat.basecolor, mat.sssColor, mat.subsurface); color = clamp(color, vec3(0.05), vec3(0.99)); - vec3 sssRadius = transmiianceColor * subsurface; + vec3 sssRadius = mat.sssParam * mat.subsurface; RadiancePRD *prd = getPRD(); prd->ss_alpha = color; if (isSS) { @@ -727,7 +655,7 @@ namespace DisneyBSDF{ auto first_hit_type = prd->first_hit_type; prd->first_hit_type = prd->depth==0?SPECULAR_HIT:first_hit_type; float ax, ay; - BRDFBasics::CalculateAnisotropicParams(roughness,anisotropic,ax,ay); + BRDFBasics::CalculateAnisotropicParams(mat.roughness,mat.anisotropic,ax,ay); vec3 wm = BRDFBasics::SampleGGXVNDF(wo.z>0?wo:-wo, ax, ay, r1, r2); @@ -749,30 +677,30 @@ namespace DisneyBSDF{ bool entering = wo.z>0?true:false; float ax, ay; - BRDFBasics::CalculateAnisotropicParams(roughness,anisotropic,ax,ay); + BRDFBasics::CalculateAnisotropicParams(mat.roughness,mat.anisotropic,ax,ay); vec3 swo = wo.z>0?wo:-wo; vec3 wm = BRDFBasics::SampleGGXVNDF(swo, ax, ay, r1, r2); wm = wm.z<0?-wm:wm; wm = entering?wm:-wm; - float F = BRDFBasics::DielectricFresnel(abs(dot(wm, wo)), entering?ior:1.0f/ior); + float F = BRDFBasics::DielectricFresnel(abs(dot(wm, wo)), entering?mat.ior:1.0f/mat.ior); float p = rnd(seed); if(p0.0f; if(sameside2 == false) { @@ -786,7 +714,7 @@ namespace DisneyBSDF{ auto first_hit_type = prd->first_hit_type; prd->first_hit_type = prd->depth==0?SPECULAR_HIT:first_hit_type; - vec3 wm = BRDFBasics::SampleGTR1(ccRough, r1, r2); + vec3 wm = BRDFBasics::SampleGTR1(mat.clearcoatRoughness, r1, r2); if (wm.z < 0.0) wm = -wm; @@ -802,10 +730,7 @@ namespace DisneyBSDF{ tbn.inverse_transform(wo); float pdf, pdf2; vec3 rd, rs, rt; - reflectance = EvaluateDisney2(vec3(1.0f), baseColor, sssColor, metallic, subsurface, - specular, roughness, specularTint, anisotropic, anisoRotation, sheen, - sheenTint, clearCoat, clearcoatGloss, ccRough, ccIor, specTrans, - scatterDistance, ior, flatness, wi, wo, T, B, N, N2, thin, + reflectance = EvaluateDisney2(vec3(1.0f), mat, wi, wo, T, B, N, N2, thin, is_inside, pdf, pdf2, 0, rd, rs, rt); fPdf = pdf>1e-5?pdf:0.0f; reflectance = pdf>1e-5?reflectance:vec3(0.0f); diff --git a/zenovis/xinxinoptix/IOMat.h b/zenovis/xinxinoptix/IOMat.h index 07b1f91062..73a49a9796 100644 --- a/zenovis/xinxinoptix/IOMat.h +++ b/zenovis/xinxinoptix/IOMat.h @@ -3,33 +3,43 @@ #include "zxxglslvec.h" struct MatOutput { - vec3 basecolor; - float metallic; + vec3 basecolor; float roughness; - float subsurface; - float specular; - float specularTint; + float opacity; + float thin; + float flatness; + float doubleSide; float anisotropic; float anisoRotation; + float ior; + vec3 reflectance; + + float metallic; + vec3 metalColor; + + float specular; + float specularTint; float sheen; float sheenTint; + float clearcoat; - float clearcoatGloss; + vec3 clearcoatColor; float clearcoatRoughness; float clearcoatIOR; - float opacity; - float ior; - float flatness; + float specTrans; + vec3 transColor; + vec3 transParam; + float clarity; + float transDepth; + + float subsurface; + vec3 sssColor; + vec3 sssParam; float scatterDistance; - float thin; - float doubleSide; float scatterStep; float smoothness; - vec3 sssColor; - vec3 sssParam; float displacement; - vec3 reflectance; vec3 nrm; vec3 emission; diff --git a/zenovis/xinxinoptix/PTKernel.cu b/zenovis/xinxinoptix/PTKernel.cu index 880d32f239..8a21e9f327 100644 --- a/zenovis/xinxinoptix/PTKernel.cu +++ b/zenovis/xinxinoptix/PTKernel.cu @@ -128,7 +128,6 @@ extern "C" __global__ void __raygen__rg() prd.done = false; prd.seed = seed; prd.eventseed = eventseed; - prd.opacity = 0; prd.flags = 0; prd.maxDistance = 1e16f; prd.medium = DisneyBSDF::PhaseFunctions::vacuum; @@ -360,7 +359,7 @@ extern "C" __global__ void __miss__radiance() vec3 channelPDF = vec3(1.0f/3.0f); prd->channelPDF = channelPDF; if (ss_alpha.x < 0.0f) { // is inside Glass - prd->maxDistance = DisneyBSDF::SampleDistance2(prd->seed, sigma_t, sigma_t, channelPDF); + prd->maxDistance = DisneyBSDF::SampleDistance(prd->seed, prd->scatterDistance); } else { prd->maxDistance = diff --git a/zenovis/xinxinoptix/TraceStuff.h b/zenovis/xinxinoptix/TraceStuff.h index 5c07413c59..6332077924 100644 --- a/zenovis/xinxinoptix/TraceStuff.h +++ b/zenovis/xinxinoptix/TraceStuff.h @@ -57,7 +57,6 @@ struct RadiancePRD float3 direction; float minSpecRough; bool passed; - float opacity; float prob; float prob2; unsigned int seed; @@ -66,7 +65,6 @@ struct RadiancePRD bool hitEnv; int countEmitted; int done; - int pad; float3 shadowAttanuation; int medium; float scatterDistance; @@ -287,4 +285,4 @@ static __forceinline__ __device__ void cosine_sample_hemisphere(const float u1, // Project up to hemisphere. p.z = sqrtf( fmaxf( 0.0f, 1.0f - p.x*p.x - p.y*p.y ) ); -} \ No newline at end of file +}