Skip to content

Commit

Permalink
Merge pull request zenustech#658 from zenustech/202209051155
Browse files Browse the repository at this point in the history
finally got transmission logic right
  • Loading branch information
zhxx1987 authored Sep 5, 2022
2 parents 4ce876d + 78544c0 commit e02cdf4
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 17 deletions.
82 changes: 67 additions & 15 deletions zenovis/xinxinoptix/DeflMatShader.cu
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,11 @@ extern "C" __global__ void __closesthit__radiance()
}
bool inToOut = false;
bool outToIn = false;
if(flag == DisneyBSDF::transmissionEvent) {
prd->is_inside = !prd->is_inside;
}

if(flag == DisneyBSDF::transmissionEvent){
prd->is_inside = !prd->is_inside;
if(prd->is_inside){
outToIn = true;
inToOut = false;
Expand All @@ -659,22 +661,23 @@ extern "C" __global__ void __closesthit__radiance()
else{
outToIn = false;
inToOut = true;
prd->attenuation2 *= DisneyBSDF::Transmission(prd->extinction,optixGetRayTmax());
//prd->attenuation2 *= DisneyBSDF::Transmission(prd->extinction,optixGetRayTmax());
prd->attenuation *= DisneyBSDF::Transmission(prd->extinction,optixGetRayTmax());
prd->maxDistance = 1e16f;
prd->medium = DisneyBSDF::PhaseFunctions::vacuum;
prd->scatterPDF = 1.0;
}
}else{
if(prd->medium == DisneyBSDF::PhaseFunctions::isotropic){
prd->attenuation2 *= DisneyBSDF::Transmission(prd->extinction,optixGetRayTmax());
//prd->attenuation2 *= DisneyBSDF::Transmission(prd->extinction,optixGetRayTmax());
prd->attenuation *= DisneyBSDF::Transmission(prd->extinction,optixGetRayTmax());
float tmpPDF = 1.0f;
prd->maxDistance = DisneyBSDF::SampleDistance(prd->seed,prd->scatterStep,prd->extinction,tmpPDF);
prd->scatterPDF = tmpPDF;

}
}
prd->medium = prd->is_inside?DisneyBSDF::PhaseFunctions::isotropic : DisneyBSDF::PhaseFunctions::vacuum;



Expand Down Expand Up @@ -765,19 +768,68 @@ extern "C" __global__ void __closesthit__radiance()
}

}
auto env_dir = BRDFBasics::halfPlaneSample(prd->seed, N, 1.0);
RadiancePRD shadow_prd2;
shadow_prd2.shadowAttanuation = make_float3(1.0f, 1.0f, 1.0f);
shadow_prd2.nonThinTransHit = (thin==false && specTrans>0)? 1:0;
traceOcclusion(params.handle, P, env_dir,
1e-5f, // tmin
1e16f, // tmax,
&shadow_prd2);
float3 lbrdf = DisneyBSDF::EvaluateDisney(basecolor, metallic, subsurface, specular, clamp(roughness,0.5,0.99),
specularTint, anisotropic, sheen, sheenTint, clearcoat,
clearcoatGloss, specTrans, scatterDistance, ior, flatness, env_dir,
-normalize(inDir), T, B, N, thin > 0.5f, flag == DisneyBSDF::transmissionEvent ? inToOut : prd->is_inside, ffPdf, rrPdf,dot(N, float3(env_dir)));
prd->radiance += shadow_prd2.shadowAttanuation * float3(proceduralSky(env_dir)) * lbrdf;
float3 lbrdf;
vec3 env_dir;
bool inside=false;

// {
// while(DisneyBSDF::SampleDisney(
// prd->seed,
// basecolor,
// transmittanceColor,
// sssColor,
// metallic,
// 0,
// specular,
// roughness,
// specularTint,
// anisotropic,
// sheen,
// sheenTint,
// clearcoat,
// clearcoatGloss,
// flatness,
// specTrans,
// scatterDistance,
// ior,
// T,
// B,
// N,
// -normalize(ray_dir),
// thin>0.5f,
// inside,
// env_dir,
// reflectance,
// rPdf,
// fPdf,
// flag,
// prd->medium,
// extinction,
// isDiff,
// isSS
// ) == false)
// {
//
// rPdf = 0.0f;
// fPdf = 0.0f;
// reflectance = vec3(0.0f);
// }
//
// shadow_prd2;
// shadow_prd2.shadowAttanuation = make_float3(1.0f, 1.0f, 1.0f);
// shadow_prd2.nonThinTransHit = (thin == false && specTrans > 0) ? 1 : 0;
// traceOcclusion(params.handle, P, env_dir,
// 1e-5f, // tmin
// 1e16f, // tmax,
// &shadow_prd2);
// lbrdf = DisneyBSDF::EvaluateDisney(
// basecolor, metallic, subsurface, specular, roughness, specularTint, anisotropic, sheen,
// sheenTint, clearcoat, clearcoatGloss, specTrans, scatterDistance, ior, flatness, env_dir, -normalize(inDir),
// T, B, N, thin > 0.5f, flag == DisneyBSDF::transmissionEvent ? inToOut : prd->is_inside, ffPdf, rrPdf,
// dot(N, float3(env_dir)));
// prd->radiance += shadow_prd2.shadowAttanuation * float3(proceduralSky(env_dir)) * lbrdf;
// }

auto sun_dir = normalize(vec3(-1.2,.8,0.5));
shadow_prd2.shadowAttanuation = make_float3(1.0f, 1.0f, 1.0f);
Expand Down
8 changes: 7 additions & 1 deletion zenovis/xinxinoptix/DisneyBSDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,13 @@ namespace DisneyBSDF{
float2 r01 = sobolRnd(seed);
float r0 = r01.x;//rnd(seed);
float r1 = r01.y;//rnd(seed);
vec3 wm = BRDFBasics::SampleGgxVndfAnisotropic(wo, tax, tay, r0, r1);
auto wx = wo;
if(thin == false && wx.z<0)
{
wx.z = -wx.z;
}
vec3 wm = BRDFBasics::SampleGgxVndfAnisotropic(wx, tax, tay, r0, r1);


float VoH = dot(wm,wo);
if(wm.z < 0.0f){
Expand Down
2 changes: 1 addition & 1 deletion zenovis/xinxinoptix/PTKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ extern "C" __global__ void __miss__radiance()
prd->passed = false;
prd->countEmitted = false;

if(prd->medium != DisneyBSDF::isotropic){
if(prd->medium != DisneyBSDF::PhaseFunctions::isotropic){
prd->radiance = proceduralSky(normalize(prd->direction));

//prd->radiance = vec3(0,0,0);
Expand Down

0 comments on commit e02cdf4

Please sign in to comment.