POV-Ray : Newsgroups : povray.programming : oddity in media.cpp : oddity in media.cpp Server Time
30 Jun 2024 12:04:40 EDT (-0400)
  oddity in media.cpp  
From: Daniel Hulme
Date: 11 Oct 2004 16:44:06
Message: <20041011214406.7c2ce779@dh286.pem.cam.ac.uk>
Looking through the code further, I see the following piece of fun in
media.cpp around line 580:
>>>
      if (sampleCount < 2)
        sampleCount = 2;

      /* set static sample count */
      sampCount_s = sampleCount - 1;

      if (sampleCount < 2)
      {
<<<

Note that the second sampleCount<2 test can never succeed. I assume this
second test and the associated block of code are optimised away by the
compiler, but does this not give a warning? Clearly one of the tests
should not be there: either the first because it stops the
three-samples-only special case code running, or the second because it
is superfluous. Can some explain a bit further please?

A bit lower down, line 635, I see:
>>>
/* do some attenuation, too, since we are doing samples in order */
Media_Interval[i].te[0]+=Result[0] *
	exp(-Media_Interval[i].od[0]/sampleCount);
	/* should this be sampleCount+1? */         
Media_Interval[i].te[1]+=Result[1] *
	exp(-Media_Interval[i].od[1]/sampleCount);         
Media_Interval[i].te[2]+=Result[2] *
	exp(-Media_Interval[i].od[2]/sampleCount);
<<<
Note particularly the comment. Though I haven't finished studying the
media code yet, I strongly suspect that it should not be sampleCount+1,
because although we are doing sampleCount+1 samples in the interval,
there are only sampleCount gaps. What I don't yet get, though, is that
Media_Interval[i].od[] holds the cumulative optical density - it is
added to on each sample by the ODResult variable coming from the
sample_media_rec call. If Media_Interval[i].od[] holds the entire
optical density so far along this interval, why are we dividing it by
the number of gaps? Surely that would just attenuate by the average
optical density? Would it not be better to not divide it and attenuate
by the whole optical density? If it needs to be a per-sample thing, why
not use the optical density from this sample, held in ODResult?

Perhaps my further exploration will help, but if anyone who knows about
this is out there perhaps they would consider tossing a hint my way.

Thanks,
Daniel

-- 
A most peculiar man    With the windows closed      And Mrs Reardon says
He died last Saturday  So he'd never wake up  He has a brother somewhere
He turned on the gas   To his silent world   Who should be notified soon
And he went to sleep   And his tiny room    .oO( http://sad.istic.org/ )


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.