Skip to content
This repository was archived by the owner on Jul 18, 2020. It is now read-only.

Commit 0451d94

Browse files
committed
IMPORTANT CHANGES to Volumetrics for proper raytracing of volumes
Problems with volumes and transparent objects have been reported in the bug tracker several times: http://yafaray.org/node/289 http://yafaray.org/node/666 After some investigation, I believe the rendering of volumes is incorrectly designed. Currently, volumes are rendering separatedly from the normal "surface" objects, and the volume rendered image just rudimentary added to the "surface" rendering in integrator.cc. This causes that volumes are not included in the normal recursive raytracing and therefore volumes are not properly integrated with the other objects. So, I've removed the volume rendering from integrator.cc and I've implemented it as part of the normal integrators raytracing. The tests I've made look good for now and now transparent objects are not causing problems. In fact, this should allow to create scenes mixing mirrors, transparency, etc, and volumes that were not possible before. However, this is a very important and structural change that could have deep repercusions in the rendering, so I would advise to test it thoroughly to make sure no new issues happen now.
1 parent d6f1c2c commit 0451d94

File tree

6 files changed

+63
-22
lines changed

6 files changed

+63
-22
lines changed

src/integrators/bidirpath.cc

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ class YAFRAYPLUGIN_EXPORT biDirIntegrator_t: public tiledIntegrator_t
149149
float fNumLights;
150150
std::map <const light_t*, CFLOAT> invLightPowerD;
151151
imageFilm_t *lightImage;
152+
bool transpBackground; //! Render background as transparent
153+
bool transpRefractedBackground; //! Render refractions of background as transparent
152154
};
153155

154156
biDirIntegrator_t::biDirIntegrator_t(bool transpShad, int shadowDepth): trShad(transpShad), sDepth(shadowDepth),
@@ -262,7 +264,11 @@ colorA_t biDirIntegrator_t::integrate(renderState_t &state, diffRay_t &ray) cons
262264
color_t col(0.f);
263265
surfacePoint_t sp;
264266
ray_t testray = ray;
265-
267+
float alpha;
268+
269+
if(transpBackground) alpha=0.0;
270+
else alpha=1.0;
271+
266272
if(scene->intersect(testray, sp))
267273
{
268274
static int dbg=0;
@@ -410,12 +416,20 @@ colorA_t biDirIntegrator_t::integrate(renderState_t &state, diffRay_t &ray) cons
410416
}
411417
else
412418
{
413-
if(background)
419+
if(background && !transpRefractedBackground)
414420
{
415421
col += (*background)(ray, state, false);
416422
}
417423
}
418-
return col;
424+
425+
color_t colVolTransmittance = scene->volIntegrator->transmittance(state, ray);
426+
color_t colVolIntegration = scene->volIntegrator->integrate(state, ray);
427+
428+
if(transpBackground) alpha = std::max(alpha, 1.f-colVolTransmittance.R);
429+
430+
col = (col * colVolTransmittance) + colVolIntegration;
431+
432+
return colorA_t(col, alpha);
419433
}
420434

421435
/* ============================================================
@@ -927,7 +941,16 @@ color_t biDirIntegrator_t::evalPathE(renderState_t &state, int s, pathData_t &pd
927941

928942
integrator_t* biDirIntegrator_t::factory(paraMap_t &params, renderEnvironment_t &render)
929943
{
944+
bool bg_transp = true;
945+
bool bg_transp_refract = true;
946+
947+
params.getParam("bg_transp", bg_transp);
948+
params.getParam("bg_transp_refract", bg_transp_refract);
949+
930950
biDirIntegrator_t *inte = new biDirIntegrator_t();
951+
// Background settings
952+
inte->transpBackground = bg_transp;
953+
inte->transpRefractedBackground = bg_transp_refract;
931954
return inte;
932955
}
933956

src/integrators/directlight.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,19 @@ colorA_t directLighting_t::integrate(renderState_t &state, diffRay_t &ray) const
132132
}
133133
else // Nothing hit, return background if any
134134
{
135-
if(background) col += (*background)(ray, state, false);
135+
if(background && !transpRefractedBackground) col += (*background)(ray, state, false);
136136
}
137137

138138
state.userdata = o_udat;
139139
state.includeLights = oldIncludeLights;
140+
141+
color_t colVolTransmittance = scene->volIntegrator->transmittance(state, ray);
142+
color_t colVolIntegration = scene->volIntegrator->integrate(state, ray);
143+
144+
if(transpBackground) alpha = std::max(alpha, 1.f-colVolTransmittance.R);
145+
146+
col = (col * colVolTransmittance) + colVolIntegration;
147+
140148
return colorA_t(col, alpha);
141149
}
142150

src/integrators/pathtracer.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,21 @@ colorA_t pathIntegrator_t::integrate(renderState_t &state, diffRay_t &ray/*, sam
283283
}
284284
else //nothing hit, return background
285285
{
286-
if(background)
286+
if(background && !transpRefractedBackground)
287287
{
288288
col += (*background)(ray, state, false);
289289
}
290290
}
291291

292292
state.userdata = o_udat;
293+
294+
color_t colVolTransmittance = scene->volIntegrator->transmittance(state, ray);
295+
color_t colVolIntegration = scene->volIntegrator->integrate(state, ray);
296+
297+
if(transpBackground) alpha = std::max(alpha, 1.f-colVolTransmittance.R);
298+
299+
col = (col * colVolTransmittance) + colVolIntegration;
300+
293301
return colorA_t(col, alpha);
294302
}
295303

src/integrators/photonintegr.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,12 +873,19 @@ colorA_t photonIntegrator_t::integrate(renderState_t &state, diffRay_t &ray) con
873873
}
874874
else //nothing hit, return background
875875
{
876-
if(background) col += (*background)(ray, state, false);
876+
if(background && !transpRefractedBackground) col += (*background)(ray, state, false);
877877
}
878878

879879
state.userdata = o_udat;
880880
state.includeLights = oldIncludeLights;
881881

882+
color_t colVolTransmittance = scene->volIntegrator->transmittance(state, ray);
883+
color_t colVolIntegration = scene->volIntegrator->integrate(state, ray);
884+
885+
if(transpBackground) alpha = std::max(alpha, 1.f-colVolTransmittance.R);
886+
887+
col = (col * colVolTransmittance) + colVolIntegration;
888+
882889
return colorA_t(col, alpha);
883890
}
884891

src/integrators/sppm.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,6 @@ bool SPPM::renderTile(renderArea_t &a, int n_samples, int offset, bool adaptive,
159159
HitPoint &hp = hitPoints[index];
160160

161161
GatherInfo gInfo = traceGatherRay(rstate, c_ray, hp); // L_o
162-
gInfo.photonFlux *= scene->volIntegrator->transmittance(rstate, c_ray);
163-
//needed fix for a volumetric boundary alpha issue because
164-
// when col.A = T.A * L_o.A + L_v.A, col.A amount is > 1.0
165-
colorA_t volTransmitt = scene->volIntegrator->transmittance(rstate, c_ray);
166-
colorA_t volIntegrate = scene->volIntegrator->integrate(rstate, c_ray); // Now using it to simulate for volIntegrator not using PPM, need more tests
167-
volIntegrate.A = 1.f - volTransmitt.A;
168-
gInfo.constantRandiance *= volTransmitt; // T
169-
gInfo.constantRandiance += volIntegrate; // L_v
170162
hp.constantRandiance += gInfo.constantRandiance; // accumulate the constant radiance for later usage.
171163

172164
// progressive refinement
@@ -815,7 +807,7 @@ GatherInfo SPPM::traceGatherRay(yafaray::renderState_t &state, yafaray::diffRay_
815807

816808
else //nothing hit, return background
817809
{
818-
if(background)
810+
if(background && !transpRefractedBackground)
819811
{
820812
gInfo.constantRandiance += (*background)(ray, state, false);
821813
}
@@ -824,6 +816,13 @@ GatherInfo SPPM::traceGatherRay(yafaray::renderState_t &state, yafaray::diffRay_
824816
state.userdata = o_udat;
825817
state.includeLights = oldIncludeLights;
826818

819+
colorA_t colVolTransmittance = scene->volIntegrator->transmittance(state, ray);
820+
colorA_t colVolIntegration = scene->volIntegrator->integrate(state, ray);
821+
822+
if(transpBackground) alpha = std::max(alpha, 1.f-colVolTransmittance.R);
823+
824+
gInfo.constantRandiance = (gInfo.constantRandiance * colVolTransmittance) + colVolIntegration;
825+
827826
gInfo.constantRandiance.A = alpha; // a small trick for just hold the alpha value.
828827

829828
return gInfo;
@@ -886,7 +885,7 @@ integrator_t* SPPM::factory(paraMap_t &params, renderEnvironment_t &render)
886885
params.getParam("bg_transp", bg_transp);
887886
params.getParam("bg_transp_refract", bg_transp_refract);
888887

889-
SPPM* ite = new SPPM(numPhotons, _passNum,transpShad, shadowDepth);
888+
SPPM* ite = new SPPM(numPhotons, _passNum, transpShad, shadowDepth);
890889
ite->rDepth = raydepth;
891890
ite->maxBounces = bounces;
892891
ite->initialFactor = times;

src/yafraycore/integrator.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,8 @@ bool tiledIntegrator_t::renderTile(renderArea_t &a, int n_samples, int offset, b
293293
c_ray.ydir = d_ray.dir;
294294
c_ray.time = rstate.time;
295295
c_ray.hasDifferentials = true;
296-
// col = T * L_o + L_v
297-
colorA_t colIntegration = integrate(rstate, c_ray); // L_o
298-
colorA_t colVolTransmittance = scene->volIntegrator->transmittance(rstate, c_ray); // T
299-
colorA_t colVolIntegration = scene->volIntegrator->integrate(rstate, c_ray); // L_v
300-
colVolIntegration.A = 1.f-colVolTransmittance.A; //Fix for Volumetrics Alpha artifacts. For the Alpha of the volume itself, I will use the inverse of the Aplha calculated by the transmittance calculation. It seems to give good results for volumes rendered on top of other objects, volumes rendered on top of an opaque background and volumes rendered on top of transparent background (for later compositing).
301-
colorA_t col = (colIntegration*colVolTransmittance)+colVolIntegration;
296+
297+
colorA_t col = integrate(rstate, c_ray);
302298
imageFilm->addSample(wt * col, j, i, dx, dy, &a);
303299

304300
if(do_depth)

0 commit comments

Comments
 (0)