POV-Ray : Newsgroups : povray.binaries.images : A doodle and ramblings on pattern{} and iso perturbation : A doodle and ramblings on pattern{} and iso perturbation Server Time
7 Jun 2025 18:20:36 EDT (-0400)
  A doodle and ramblings on pattern{} and iso perturbation  
From: William F Pokorny
Date: 1 Jun 2025 09:44:03
Message: <683c5923@news.povray.org>
Got frustrated and took a break from my options parsing re-work. I used 
the time to implement an isosurface doodle related to a couple recent 
threads. Namely, the ones about perturbing isosurfaces and using 
pattern{} while defining functions.

Tips /thoughts
--------------

1) A subtle use of pattern{} is to wrap existing functions with it so 
you can use the inbuilt pattern modifiers as part of creating a derived 
function. For example, we can apply isosurface perturbations with 
warp{}s. In the posted image the rough texture comes from the 
application of a warp{} turbulence. A code excerpt is below.

As a bonus (especially in yuqk using its raw_wave modifier), the 
approach often leads to much lower isosurface gradients because the 
perturbation is done by the warp{}. The 'nested isosurface evaluation' 
space is smoother / cleaner as the solver sees it - despite the overall 
result.

(Long on my todo list has been trying this kind of pattern enabled 
perturbation with parametric surfaces too. Should work, but...)

2) Bald Eagle posted code using a pigment{} alternative to pattern{} 
wrap. Both wraps are useful depending on needs. However, if what you 
want is the inbuilt pattern's singular value and not a color vector, the 
pattern{} wrap is faster - and more accurate (color vectors internally 
are 32 bit floats).

3) I used yuqk's f_round() inbuilt function here as an alternative to 
mod() to get multiple torus shapes from each FnTorusWarp() use.

4) The large reduction in isosurface gradients due the use of yuqk's 
'raw_wave' pattern modifier hints at a general issue using pattern{} and 
inbuilt patterns with functions. One especially true in the current 
non-yuqk releases of POV-Ray.

The pattern mechanism (and very often the inbuilt pattern specific code 
in alternate ways) clamp and/or wrap values to a 0-1 range for use with 
*maps though it is often not necessary(*). There are several secondary 
issues too at the pattern <-> function interface in the official code. 
It, pretty much, all leads to choppy value fields (high gradients) for 
the isosurface solver.

(*) The *_map code in all recent versions of POV-Ray can handle 
arbitrary pattern return ranges.

Bill P.

// The yuqk fork required for the example code below
//...
#include "functions.inc"
#declare FnTorusWarp = function {
     pattern {
         function {
             f_torus(x,y,z,
                 max(1,min(5,f_round(f_hypot(x,z)))),
             0.04)
         }
         raw_wave // Drives iso gradient improvement of 1903 to 3
         warp {
             it_amount 0.15 it_octaves 3 it_omega 0.8 it_lambda 2.5
             it_scale 1/15
         }
     }
}

#declare FnTorusPlaced = function (x,y,z,X,Y,Z) {
     FnTorusWarp(x-X,y-Y,z-Z)
}

#declare FnTorusTotal = function (x,y,z) { // isosurface function
     min(
         FnTorusPlaced(x,y,z,+2.0,0.0,+2.0),
         FnTorusPlaced(x,y,z,-2.0,0.0,+2.0),
         FnTorusPlaced(x,y,z,+2.0,0.0,-2.0),
         FnTorusPlaced(x,y,z,-2.0,0.0,-2.0)
     )
}
//...
// The final isosurface is scaled by 1/2
//


Post a reply to this message


Attachments:
Download 'larsr_00.png' (293 KB)

Preview of image 'larsr_00.png'
larsr_00.png


 

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