POV-Ray : Newsgroups : povray.advanced-users : Speeding up (or faking) scattering media Server Time
15 Oct 2024 08:10:41 EDT (-0400)
  Speeding up (or faking) scattering media (Message 1 to 10 of 10)  
From: Juergen
Subject: Speeding up (or faking) scattering media
Date: 19 Jun 2023 17:40:00
Message: <web.6490ca4b9e00c62a74554476df9b2273@news.povray.org>
HelloI would like to extend my scene with the fake caustic to see the light rays
under water. With a scattered media this works, but the computation time
increases indisputably from 0.5 to almost 70s per frame (should become an
animation later).
In the concrete scene the samples have to be at least 50,100 for this to look
usable - so I can't turn the screw anymore.
What possibilities are there to speed up the process (I think that the
calculation time/image should not be more than double or triple, but not by a
factor of 100)?
Is there a way to fake this (similar to what I did with the caustics), but for
the scattering media I have no idea at the moment.


---------------------the scene----------------
// Testscene mit einer gefakten Caustik,
// indem eine helle light_source mit einer Kugel und entspr teiltransparenten
Textur umgeben wird
// Renderzeit: 1sek
#version 3.7;
global_settings {
  assumed_gamma 1.0
}

#declare InclMedia = 1;

#declare CausAdd    = 0.0;
#declare ScatterCol = 0.0004;

#include "colors.inc"
#include "textures.inc"

#declare PSize = 300;

//////// Caustics-Texture START /////////
#declare TxtS4b =
texture {  // "DunkelTextur"
  pigment { rgbf <1.0, 1.0, 1.0, 1*CausAdd> }
}
#declare TxtS4a1 =
texture { // "Helltextur"
  pigment { color rgbf <1.0, 1.0, 1.0, 1.0> }
  finish { diffuse 0.5 ambient 1 }
}
#declare TxtS4a2 =
texture {
  pigment { color rgbf <1.0, 1.0, 1.0, 0.2+0.8*CausAdd> }
}
#declare TxtS4c =

  bozo
  scale 1.5
  translate <752,74,62343>
  texture_map {
    [ 0.25 pigment { rgbf <1.0,1.0,1.0,0.0+CausAdd> } ]
    [ 0.5  pigment { rgbf <1.0,1.0,1.0,0.1+0.9*CausAdd> } ]
    [ 0.75 pigment { rgbf <1.0,1.0,1.0,0.0+CausAdd> } ]
  }
  //pigment { color rgbf <0.6, 0.6, 1.0, 1.0> }
}
#declare TxtS4a =
texture {  // 1. Layer mit Bozo (Hell-Dunke-Effekte innerbalb der Textur)
  bozo
  scale 0.5
  translate <1223,455,121>
  texture_map {
    [ 0.15 TxtS4b ]
    [ 0.4  TxtS4a2 ]
    [ 0.5  TxtS4a1 ]
    [ 0.6  TxtS4a2 ]
    [ 0.85 TxtS4b ]
  }
}
#declare CausticsTxt =
texture { // die eigentliche Caustic-Textur
  crackle
  turbulence 0.25
  omega 0
  scale 5
  texture_map {
    [ 0.0 TxtS4a ]
    [ 0.12 TxtS4c ]
    [ 0.5 TxtS4b ]
  }
  scale 0.075
}
//////// Caustics-Texture ENDE /////////


// Boden
difference {
  plane { y,0 }
  box { <-PSize,-250,-PSize><PSize,1,PSize> } // Pool

  pigment { Gray50 }
  //pigment { bozo scale 30}
}


//#declare adsasdas =
#ifdef(InclMedia)
  box { <-PSize,-250,-PSize><PSize,-50,PSize>
    pigment { rgbt 1 } // clear
    hollow
    interior{
      media{
        scattering{ 1, ScatterCol extinction 0.01 }
        //scattering{ 1, 0.17 extinction 0.01}
        samples 50, 100 // min, max
      } // end media
    } // end interior
  }
#end


// #declare adadas =
cylinder {
  <-25,0,0><25,0,0> 10
  pigment { Red }
  translate <100,-200,-50>
}
cylinder {
  <0,-300,0><0,100,0> 50
  pigment { Blue }
  translate <120,-200,70>
}
sphere {
  0,20
  pigment { Yellow }
  translate <120,-200,-150>
}


// Sonne
light_source {
  <-50,200, 0>
  color 5
}

// Caustics-sphere
#declare CausticsSpr =
sphere {
  0,10
  texture {
    CausticsTxt
    translate <clock*0.02  ,clock*0.1,  -clock*0.005>
  }
}

object {
  CausticsSpr
  translate <-50,200,0>
}


#declare Cam =
camera {
  location 0
  direction <0.0, 0.0, 1>
  up <0.0, 1.0, 0.0>
  right <4/3, 0.0, 0.0>
  look_at <0,0,1>
}
camera {
  Cam
  rotate 30*x
  rotate 30*y
  translate -70*y
  translate -PSize*z+10
}


Post a reply to this message


Attachments:
Download 'lightsource2m1.jpg' (113 KB)

Preview of image 'lightsource2m1.jpg'
lightsource2m1.jpg


 

From: Bald Eagle
Subject: Re: Speeding up (or faking) scattering media
Date: 19 Jun 2023 18:20:00
Message: <web.6490d3a43f9195661f9dae3025979125@news.povray.org>
Have you tried just using a loop to make a bunch of thin cylinders radiating
from a distant point and having an rgbf pigment?

Maybe there's a way to use your caustics method and have that control the
placement of the cylinders?

Or use an isosurface, or bezier surface with a pattern simulating streaks
(gradient).

- BW


Post a reply to this message

From: jr
Subject: Re: Speeding up (or faking) scattering media
Date: 20 Jun 2023 09:40:00
Message: <web.6491ac203f919566b49d80446cde94f1@news.povray.org>
hi,

"Juergen" <nomail@nomail> wrote:
> ...
> Is there a way to fake this (similar to what I did with the caustics), but for
> the scattering media I have no idea at the moment.

wondering, could you use a density pattern, suitably rotated etc, to 'fake' the
shafts of light ?  (just a thought, no idea if it would "buy" you time)


regards, jr.


Post a reply to this message

From: Bald Eagle
Subject: Re: Speeding up (or faking) scattering media
Date: 20 Jun 2023 15:20:00
Message: <web.6491fbc33f9195661f9dae3025979125@news.povray.org>
I found this:
https://www.shadertoy.com/view/lljGDt

which seems to be the best of a 10-15 min search.

Other stuff I found (and there's tons):




https://lesterbanks.com/2016/11/underwater-light-rays-volumetrics-c4d/

Also, here's an article with some background on caustics, which may or may not
help trigger some ideas for faking/approximating a faster way.
https://developer.nvidia.com/gpugems/gpugems/part-i-natural-effects/chapter-2-rendering-water-caustics

It also provides search keywords "crepuscular rays" and "God's rays".

https://www.shadertoy.com/view/llXfRs

https://www.shadertoy.com/view/Xtcfzj

https://www.shadertoy.com/view/lldcDf

https://github.com/miloyip/light2d

http://web.archive.org/web/20221207134737/https://www.genericgamedev.com/effects/localised-crepuscular-rays/

https://developer.nvidia.com/gpugems/gpugems3/part-ii-light-and-shadows/chapter-13-volumetric-light-scattering-post-pro
cess

https://github.com/Erkaman/glsl-godrays

https://fabiensanglard.net/lightScattering/

https://www.ventuz.com/support/help/V4_05/HowTo/HowToCreateGodRayShader.html

The following seems to imply (to me) that a simple convolution kernel might be
able to achieve the effect:
https://web.archive.org/web/20210503152629/https://anderskruger.com/opengl-god-rays/


- BW


Post a reply to this message

From: Bald Eagle
Subject: Re: Speeding up (or faking) scattering media
Date: 20 Jun 2023 19:20:00
Message: <web.649233fa3f9195661f9dae3025979125@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> I found this:
> https://www.shadertoy.com/view/lljGDt
>
> which seems to be the best of a 10-15 min search.

Since it's a shader, it all needs to be converted into functions, and then
rendered as a pigment pattern that controls an average texture.

That took a little bit to make a little 200-line scene, and winnow out all the
stupid trivial mistakes.

I suppose I ought to animate it to see what that looks like....


Post a reply to this message


Attachments:
Download 'lightraytest.png' (282 KB)

Preview of image 'lightraytest.png'
lightraytest.png


 

From: jr
Subject: Re: Speeding up (or faking) scattering media
Date: 21 Jun 2023 03:20:00
Message: <web.6492a4103f919566b49d80446cde94f1@news.povray.org>
hi,

"Bald Eagle" <cre### [at] netscapenet> wrote:
> ...
> I suppose I ought to animate it to see what that looks like....

yes :-)


regards, jr.


Post a reply to this message

From: Bald Eagle
Subject: Re: Speeding up (or faking) scattering media
Date: 21 Jun 2023 14:50:00
Message: <web.649345363f9195661f9dae3025979125@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:

> yes :-)

tl;dr


Short 5 second animation attached.   500 frames at 10 frames/sec.

I guess it looks ok.  No idea why it looks so different from the beautiful
Shadertoy result.


Post a reply to this message


Attachments:
Download 'lightrays.mp4.dat' (2177 KB)

From: jr
Subject: Re: Speeding up (or faking) scattering media
Date: 22 Jun 2023 02:05:00
Message: <web.6493e3693f919566b49d80446cde94f1@news.povray.org>
hi,

"Bald Eagle" <cre### [at] netscapenet> wrote:
> Short 5 second animation attached.   500 frames at 10 frames/sec.
>
> I guess it looks ok.

agree, better than "ok" even, fwiw :-).  reminds me (a little) of "Art Nouveau"
style.  cheers.


regards, jr.


Post a reply to this message

From: Juergen
Subject: Re: Speeding up (or faking) scattering media
Date: 25 Jun 2023 18:00:00
Message: <web.6498b8273f91956674554476df9b2273@news.povray.org>
Hi,

I made a few attempts over the weekend. I followed the variant "transparent
cylinder". The result looks quite usable, but there are a few restrictions and
things to consider.

In the core I use a (vertical) cylinder. On this cylinder is a gradient texture
to avoid sharp edges. Finally, the cylinder is rotated so that it is parallel to
the light rays.

The constraints are:
1. there must be no visible intersection of a cylinder with another object in
the scene, here you would have sharp, unnatural edges.
2. the gradient texture must be aligned with the camera, otherwise the advantage
of having no sharp edges is lost,
3. not too many of these cylinders should be used (about 150), otherwise the
render time will increase again to the point where you can use the right media.



Post a reply to this message


Attachments:
Download 'lightsource2m1b.jpg' (118 KB)

Preview of image 'lightsource2m1b.jpg'
lightsource2m1b.jpg


 

From: William F Pokorny
Subject: Re: Speeding up (or faking) scattering media
Date: 29 Jun 2023 18:58:06
Message: <649e0c7e$1@news.povray.org>
On 6/25/23 17:56, Juergen wrote:
> Hi,
> 
> I made a few attempts over the weekend. I followed the variant "transparent
> cylinder". The result looks quite usable, but there are a few restrictions and
> things to consider.
> 
> In the core I use a (vertical) cylinder. On this cylinder is a gradient texture
> to avoid sharp edges. Finally, the cylinder is rotated so that it is parallel to
> the light rays.
> 
> The constraints are:
> 1. there must be no visible intersection of a cylinder with another object in
> the scene, here you would have sharp, unnatural edges.
> 2. the gradient texture must be aligned with the camera, otherwise the advantage
> of having no sharp edges is lost,
> 3. not too many of these cylinders should be used (about 150), otherwise the
> render time will increase again to the point where you can use the right media.
> 
> Jürgen

Hi. It does look like a workable solution.

Real life has me busy these days, but I'll mention a couple additional 
things.

Norbert Kern, perhaps a couple years ago (and IIRC), worked out a scheme 
where he created a high field containing media (emitting?) in front of 
his actual scene for light rays through media effects.

Second and FWIW, when I reworked the fog feature in the povr fork, I 
added an 'inverse' feature which creates the densest fog closer to the 
camera rather than at greatest depth. The idea is to make it easier to 
fake media effects with fog{} using special near-camera, otherwise 
invisible/null for ray depth only, shapes. The sad bit is aside from a 
few quick experiments, I've never gotten to really playing with the new 
feature myself...

Bill P.


Post a reply to this message

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