Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve light aux lambda #1579

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions zenovis/xinxinoptix/DeflMatShader.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1047,10 +1047,13 @@ extern "C" __global__ void __closesthit__radiance()
return lbrdf;
};

auto taskAux = [&](const vec3& weight) {
float3 radianceNoShadow = make_float3(0,0,0);
auto taskAux = [&](const vec3& weight, const float3& radianceNoBlock) {
prd->radiance_d = rd * weight;
prd->radiance_s = rs * weight;
prd->radiance_t = rt * weight;

radianceNoShadow = radianceNoBlock;
};

RadiancePRD shadow_prd {};
Expand All @@ -1059,8 +1062,8 @@ extern "C" __global__ void __closesthit__radiance()
shadow_prd.nonThinTransHit = (mats.thin == false && mats.specTrans > 0) ? 1 : 0;

prd->direction = normalize(wi);
float3 radianceNoShadow = make_float3(0,0,0);
DirectLighting<true>(prd, shadow_prd, shadingP, ray_dir, evalBxDF, radianceNoShadow, &taskAux);

DirectLighting<true>(prd, shadow_prd, shadingP, ray_dir, evalBxDF, &taskAux);
if(mats.shadowReceiver > 0.5f)
{
auto radiance = length(prd->radiance);
Expand Down
33 changes: 20 additions & 13 deletions zenovis/xinxinoptix/Light.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ namespace detail {

template<bool _MIS_, typename TypeEvalBxDF, typename TypeAux = void>
static __forceinline__ __device__
void DirectLighting(RadiancePRD *prd, RadiancePRD& shadow_prd, const float3& shadingP, const float3& ray_dir, TypeEvalBxDF& evalBxDF, float3 &radianceNoShadow, TypeAux* taskAux=nullptr) {
void DirectLighting(RadiancePRD *prd, RadiancePRD& shadow_prd, const float3& shadingP, const float3& ray_dir, TypeEvalBxDF& evalBxDF, TypeAux* taskAux=nullptr) {

const float3 wo = normalize(-ray_dir);
float3 light_attenuation = vec3(1.0f);
Expand Down Expand Up @@ -400,23 +400,30 @@ void DirectLighting(RadiancePRD *prd, RadiancePRD& shadow_prd, const float3& sha
if (lsr.NoL > _FLT_EPL_ && lsr.PDF > _FLT_EPL_) {

traceOcclusion(params.handle, shadingP, lsr.dir, 0, lsr.dist, &shadow_prd);

light_attenuation = shadow_prd.shadowAttanuation;

//if (lengthSquared(light_attenuation) > 0.0f) {

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

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

emission *= lsr.intensity;

prd->radiance = light_attenuation * emission * bxdf_value;
prd->radiance *= misWeight / lsr.PDF;
radianceNoShadow = emission * bxdf_value * misWeight / lsr.PDF;
float3 radianceNoShadow = emission * bxdf_value;
radianceNoShadow *= misWeight / lsr.PDF;

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

prd->radiance = radianceNoShadow * light_attenuation; // with shadow
//}
}

Expand Down Expand Up @@ -461,26 +468,26 @@ void DirectLighting(RadiancePRD *prd, RadiancePRD& shadow_prd, const float3& sha
auto inverseProb = 1.0f/_SKY_PROB_;
auto bxdf_value = evalBxDF(sun_dir, wo, scatterPDF, illum);

vec3 tmp(1.0f);
float tmp = 1.0f;

if constexpr(_MIS_) {
float misWeight = BRDFBasics::PowerHeuristic(tmpPdf, scatterPDF);
misWeight = misWeight>0.0f?misWeight:1.0f;
misWeight = scatterPDF>1e-5f?misWeight:0.0f;
misWeight = tmpPdf>1e-5f?misWeight:0.0f;

tmp = (1.0f / NSamples) * misWeight * inverseProb * light_attenuation / tmpPdf;
tmp = (1.0f / NSamples) * misWeight * inverseProb / tmpPdf;
} else {
tmp = (1.0f / NSamples) * inverseProb * light_attenuation / tmpPdf;
tmp = (1.0f / NSamples) * inverseProb / tmpPdf;
}

prd->radiance += (float3)(tmp) * bxdf_value;
radianceNoShadow += (float3)(tmp) * bxdf_value;
float3 radianceNoShadow = tmp * bxdf_value;

if constexpr (!detail::is_void<TypeAux>::value) {
if (taskAux != nullptr) {
(*taskAux)(tmp);
}
(*taskAux)(tmp * light_attenuation, radianceNoShadow);
}// TypeAux

prd->radiance += radianceNoShadow * light_attenuation; // with shadow
}
}
};