POV-Ray : Newsgroups : povray.beta-test : Photons are broken with true inverse squared lighting Server Time
12 Dec 2024 18:49:10 EST (-0500)
  Photons are broken with true inverse squared lighting (Message 1 to 3 of 3)  
From: Cousin Ricky
Subject: Photons are broken with true inverse squared lighting
Date: 19 Jun 2024 15:14:18
Message: <66732e0a@news.povray.org>
https://news.povray.org/povray.binaries.images/thread/%3C65c7ec42%40news.povray.org%3E/

Well, I found out why my 30th anniversary tribute to POV-Ray went crazy
when I upgraded the lamp fixtures: photons are broken with POV-Ray 3.8's
inverse squared lighting.  I rendered my initial scene before I had
finished the DeskLamp module, and at that time, the scene used only
POV-Ray's legacy light fading; but the DeskLamp module automatically
uses true inverse squared if it detects #version 3.8 or later.

The 2 control images below were rendered without photons, just to verify
that the legacy light source and true inverse squared light source are
comparable.

---%<----%<----%<----%<--[BEGIN CODE]--%<----%<----%<----%<----%<---
// +KFF4 +W512 +H384
#version 3.8;

#declare Has_photons = (frame_number >= 3);
#declare True_invsq = 1 - mod (frame_number, 2);

#include "screen.inc"

global_settings
{ assumed_gamma 1
  max_trace_level 100
  #if (Has_photons)
    photons { spacing 0.005 autostop 0 }
  #end
}
#default { finish { ambient 0.1 diffuse 0.6 emission 0 } }
box
{ -<6, 0.001, 6>, <6, 8, 6>
  hollow
  pigment { rgb 1 }
}
Set_Camera (<2, 3, -5>, <0.25, 1, 0>, 60)

#declare v_Source = <-5, 7, -5>;
#declare v_Focus = <0, 1, 0>;
#declare Dist = vlength (v_Source - v_Focus);
#if (True_invsq)
  light_source
  { v_Source, rgb pow (Dist, 2)
    fade_distance 0
    fade_power 2
  }
#else
  #declare FD = 0.1;
  light_source
  { v_Source, rgb (1 + pow (Dist / FD, 2)) / 2
    fade_distance FD
    fade_power 2
  }
#end

intersection
{ box { -1, 1 }
  box { -1.1, 1.1 rotate 45 * x }
  box { -1.1, 1.1 rotate 45 * y }
  box { -1.1, 1.1 rotate 45 * z }
  translate y
  pigment { rgbf 1 }
  finish
  { fresnel 1
    reflection { 1 fresnel } conserve_energy
    specular 1 roughness 0.0003
  }
  interior { ior 1.8 dispersion 1.04 }
  photons { target collect off reflection on refraction on }
}

Screen_Object
( text
  { ttf "cyrvetic"
    concat
    ( #if (True_invsq) "True inverse squared",
      #else "Old fade formula",
      #end
      #if (Has_photons) " with photons"
      #else " control"
      #end
    )
    0.001, 0
    pigment { rgb 0 }
    scale 16 / image_height
  },
  <0, 0>, <0.02, 0.01>, yes, 1
)
--->%---->%---->%---->%---[END CODE]--->%---->%---->%---->%----%<---


Post a reply to this message


Attachments:
Download 'invsq_photons1.jpg' (19 KB) Download 'invsq_photons2.jpg' (19 KB) Download 'invsq_photons3.jpg' (26 KB) Download 'invsq_photons4.jpg' (37 KB)

Preview of image 'invsq_photons1.jpg'
invsq_photons1.jpg

Preview of image 'invsq_photons2.jpg'
invsq_photons2.jpg

Preview of image 'invsq_photons3.jpg'
invsq_photons3.jpg

Preview of image 'invsq_photons4.jpg'
invsq_photons4.jpg


 

From: William F Pokorny
Subject: Re: Photons are broken with true inverse squared lighting
Date: 19 Jun 2024 18:16:24
Message: <667358b8$1@news.povray.org>
On 6/19/24 15:14, Cousin Ricky wrote:
> Well, I found out why my 30th anniversary tribute to POV-Ray went crazy
> when I upgraded the lamp fixtures: photons are broken with POV-Ray 3.8's
> inverse squared lighting.

At the time the photons feature was added, a significant part of the 
tracing code was duplicated in the photons tracing code. When a trace 
related feature is updated, we have to remember to duplicate the feature 
update in that photons code.

I'd guess this didn't happen - at least not correctly.

I'll look at this tomorrow.

Bill P.


Post a reply to this message

From: William F Pokorny
Subject: Re: Photons are broken with true inverse squared lighting
Date: 20 Jun 2024 09:39:33
Message: <66743115$1@news.povray.org>
On 6/19/24 18:16, William F Pokorny wrote:
> I'll look at this tomorrow.

In source/core/lighting/photons.cpp there are two methods:

     void PhotonTrace::addSurfacePhoton()

     void PhotonMediaFunction::addMediaPhoton()

which have code like:

     if ((photonLight->Fade_Power > 0.0) &&
         (fabs(photonLight->Fade_Distance) > gkMinIsectDepthReturned))
     {
         Attenuation = 2.0 /
         (1.0 + pow(threadData->photonDepth /
             photonLight->Fade_Distance, photonLight->Fade_Power)
         );
     }
     else
         Attenuation = 1;

In both methods, the code needs to be something like:

     if (photonLight->Fade_Power > 0.0)
     {
         if (fabs(photonLight->Fade_Distance) >= gkMinIsectDepthReturned)
         {
             Attenuation = 2.0 /
                 (1.0 + powf(threadData->photonDepth /
                             photonLight->Fade_Distance,
                             photonLight->Fade_Power
                        )
                 );
         }
         else if (threadData->photonDepth >= gkMinIsectDepthReturned)
         {
             Attenuation =
                 powf(threadData->photonDepth,-photonLight->Fade_Power);
         }
         else
         {
             Attenuation = 0.0;
         }
     }
     else if (photonLight->Fade_Power == 0)
     {
         Attenuation = 1;
     }
     else
     {
         Attenuation = 0.0;
     }

Bill P.

Aside: I moved pow to powf as the latter often much faster and float 
accuracy is fine for attenuation. It might be official releases are 
already running 'pow()' with floats without code that forces it.


Post a reply to this message

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