Skip to content

Commit

Permalink
Merge pull request #1651 from zenustech/fixDtermProblem
Browse files Browse the repository at this point in the history
aov fix 90%
  • Loading branch information
zhxx1987 authored Dec 20, 2023
2 parents dd34d71 + 955c09b commit e1c2256
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 27 deletions.
12 changes: 7 additions & 5 deletions zenovis/xinxinoptix/DeflMatShader.cu
Original file line number Diff line number Diff line change
Expand Up @@ -966,18 +966,20 @@ extern "C" __global__ void __closesthit__radiance()
if(prd->depth>=3)
mats.roughness = clamp(mats.roughness, 0.5f,0.99f);

vec3 rd, rs, rt; // captured by lambda

auto evalBxDF = [&](const float3& _wi_, const float3& _wo_, float& thisPDF, vec3 illum = vec3(1.0f)) -> float3 {

const auto& L = _wi_; // pre-normalized
const vec3& V = _wo_; // pre-normalized
vec3 rd, rs, rt; // captured by lambda

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);


prd->radiance_d = rd;
prd->radiance_s = rs;
prd->radiance_t = rt;
// MatOutput mat2;
// if(mats.thin>0.5f){
// vec3 H = normalize(vec3(normalize(L)) + V);
Expand All @@ -996,9 +998,9 @@ extern "C" __global__ void __closesthit__radiance()
};

auto taskAux = [&](const vec3& weight) {
prd->radiance_d = rd * weight;
prd->radiance_s = rs * weight;
prd->radiance_t = rt * weight;
prd->radiance_d *= weight;
prd->radiance_s *= weight;
prd->radiance_t *= weight;
};

RadiancePRD shadow_prd {};
Expand Down
4 changes: 0 additions & 4 deletions zenovis/xinxinoptix/DisneyBSDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,6 @@ namespace DisneyBSDF{
float term = wo.z>0?FV:FL;
float tmpPdf = trans? 1.0f : 0.0f;//0.5/M_PIf:0.0f;

// auto wo2 = wo;
// wo2.z *= -1.0f;
// vec3 d2 = BRDFBasics::EvalDisneyDiffuse(mix(mat.basecolor,mat.sssColor,mat.subsurface), mat.subsurface, mat.roughness, mat.sheen,
// Csheen, wo2, wi, wm, tmpPdf) * illum;


// vec3 d = 1.0f/M_PIf * (1.0f - 0.5f * term) * (trans?vec3(1.0f):vec3(0.0f)) * dielectricWt * subsurface;
Expand Down
22 changes: 13 additions & 9 deletions zenovis/xinxinoptix/Light.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,31 +404,35 @@ void DirectLighting(RadiancePRD *prd, RadiancePRD& shadow_prd, const float3& sha
light_attenuation = shadow_prd.shadowAttanuation;

if (nullptr==RadianceWithoutShadow && lengthSquared(light_attenuation) == 0.0f) return;

auto bxdf_value = evalBxDF(lsr.dir, wo, scatterPDF);
auto misWeight = 1.0f;

emission *= lsr.intensity;
auto bxdf_value = evalBxDF(lsr.dir, wo, scatterPDF, vec3(emission));
auto misWeight = 1.0f;

if constexpr(_MIS_) {
if (!light.isDeltaLight() && !lsr.isDelta) {
misWeight = BRDFBasics::PowerHeuristic(lsr.PDF, scatterPDF);
}
}

emission *= lsr.intensity;

float3 radianceNoShadow = emission * bxdf_value;

float3 radianceNoShadow = bxdf_value;
radianceNoShadow *= misWeight / lsr.PDF;

if (nullptr != RadianceWithoutShadow) {
*RadianceWithoutShadow = radianceNoShadow;
}

if constexpr (!detail::is_void<TypeAux>::value) {
auto tmp = light_attenuation * misWeight / lsr.PDF;
(*taskAux)(tmp);
}// TypeAux
//if constexpr (!detail::is_void<TypeAux>::value) {
//auto tmp = light_attenuation * misWeight / lsr.PDF;
//(*taskAux)(vec3(tmp));
//}// TypeAux

prd->radiance = radianceNoShadow * light_attenuation; // with shadow
prd->radiance_d *= light_attenuation * misWeight / lsr.PDF;
prd->radiance_s *= light_attenuation * misWeight / lsr.PDF;
prd->radiance_t *= light_attenuation * misWeight / lsr.PDF;
}

} else {
Expand Down
31 changes: 22 additions & 9 deletions zenovis/xinxinoptix/PTKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ extern "C" __global__ void __raygen__rg()
float3 result_s = make_float3( 0.0f );
float3 result_t = make_float3( 0.0f );
float3 result_b = make_float3( 0.0f );
float3 aov[4];
int i = params.samples_per_launch;

float3 tmp_albedo{};
Expand Down Expand Up @@ -203,7 +204,7 @@ extern "C" __global__ void __raygen__rg()
unsigned char background_trace = 0;
prd.alphaHit = false;
traceRadiance(params.handle, ray_origin, ray_direction, _tmin_, prd.maxDistance, &prd, _mask_);
const auto primary_hit_type = prd.hit_type;
auto primary_hit_type = prd.hit_type;
background_trace = primary_hit_type;

if(primary_hit_type > 0) {
Expand All @@ -218,15 +219,18 @@ extern "C" __global__ void __raygen__rg()
prd.trace_denoise_albedo = false;
prd.trace_denoise_normal = false;

float3* aov[4] = {&result_b, &result_d, &result_s, &result_t};
aov[0] = result_b;
aov[1] = result_d;
aov[2] = result_s;
aov[3] = result_t;

for(;;)
{
_tmin_ = prd._tmin_;
_mask_ = prd._mask_;

prd._tmin_ = 0;
prd._mask_ = EverythingMask;
prd._mask_ = EverythingMask;

ray_origin = prd.origin;
ray_direction = prd.direction;
Expand All @@ -240,7 +244,7 @@ extern "C" __global__ void __raygen__rg()
result += prd.depth>1?clampped:temp_radiance;

if(primary_hit_type > 0 && ( prd.depth>1 || (prd.depth==1 && prd.hit_type == 0) )) {
*aov[primary_hit_type] += clampped;
aov[primary_hit_type] += prd.depth>1?clampped:temp_radiance;
}
}

Expand Down Expand Up @@ -271,13 +275,22 @@ extern "C" __global__ void __raygen__rg()
prd.radiance_s = make_float3(0);
prd.radiance_t = make_float3(0);
prd.alphaHit = false;

traceRadiance(params.handle, ray_origin, ray_direction, _tmin_, prd.maxDistance, &prd, _mask_);
background_trace = prd.hit_type;


if(prd.hit_type>0 && primary_hit_type==0)
{
primary_hit_type = prd.hit_type;
aov[primary_hit_type] += (prd.hit_type==1?prd.radiance_d:(prd.hit_type==2?prd.radiance_s:prd.radiance_t))*prd.attenuation2;
}
background_trace += prd.hit_type>0?1:0;

}

seed = prd.seed;

if (background_trace > 0) {
if (!(background_trace == 0)) {
result_b += make_float3(1);
}
}
Expand All @@ -286,9 +299,9 @@ extern "C" __global__ void __raygen__rg()
auto samples_per_launch = static_cast<float>( params.samples_per_launch );

float3 accum_color = result / samples_per_launch;
float3 accum_color_d = result_d / samples_per_launch;
float3 accum_color_s = result_s / samples_per_launch;
float3 accum_color_t = result_t / samples_per_launch;
float3 accum_color_d = aov[1] / samples_per_launch;
float3 accum_color_s = aov[2] / samples_per_launch;
float3 accum_color_t = aov[3] / samples_per_launch;
float3 accum_color_b = result_b / samples_per_launch;

if( subframe_index > 0 )
Expand Down

0 comments on commit e1c2256

Please sign in to comment.