POV-Ray : Newsgroups : povray.binaries.images : Granites Intermezzo : Re: Granites Intermezzo Server Time
26 Apr 2024 07:04:07 EDT (-0400)
  Re: Granites Intermezzo  
From: Thomas de Groot
Date: 11 May 2021 08:05:03
Message: <609a72ef@news.povray.org>
Op 11-5-2021 om 13:27 schreef Dave Blandston:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
>> Mmm, yes.  I suppose that anything that could be released upon exit from the
>> include file ought to be declared locally, if for no other reason that to
>> practice good form going forward from this point.
> 
> Yep, that would be good - keep everything local that can possibly be kept local.
> There is at least one other single-letter function designator ("N") so the
> chance of a conflict with other variables in a scene definitely exists. The
> reason I had a collision with "K" is because I use the letter "I" to control
> loops (short for "Index") then for nested loops I just keep going with "J," then
> "K," et cetera. "N" is probably popular because it's the first letter of
> "Number." There is no downside to using "#local" wherever possible, but there is
> a benefit.
> 
I am presently looking at Bald Eagle's code with the intention to 
implement it inside the granite macro. In that case, all declares will 
become locals obviously and stop giving problems like you encountered.

Another consequence will be that I shall need to define at least three 
additional parameters for the granite macro: Start, End, Turbulence.

@Bald Eagle: in your original code you also defined a parameter "Scale" 
which subsequently was not used. Where did you want to place it? It 
might be an interesting fourth addition.

My reworking of the code would look like this:

//---start code---
#ifndef (SN_Start) #local SN_Start = 0.2; #end
#ifndef (SN_End)   #local SN_End   = 0.8; #end
#ifndef (SN_Turb)  #local SN_Turb  = 0.325; #end
#ifndef (SN_Scale) #local SN_Scale = 0.25; #end

// smoothstep function
#local K = function (t1, t2, T) {max (0, min(1, (T-t1)/(t2-t1) ) )}
#local Smoothstep = function (t1, t2, T) {pow (K(t1, t2, T), 2) * 
(3-2*K(t1, t2, T))}

// mod function that plays nice when crossing 0
#local Mod = function (T) {select (T,  1-mod (abs(T), 1),  mod (abs(T), 
1) )}

// smooth step function
//#local N = function (NN) {floor (NN-0.5) + Smoothstep (SN_Start, 
SN_End, abs(Mod(NN-0.5)-0.5) )}
#local N = function (NN) {floor (NN) + Smoothstep (SN_Start, SN_End, 
Mod(NN) )}

/* usage
#declare StepNoise =
pigment {
   function {f_noise3d (N(x), N(y), N(z))}
   turbulence SN_Turb
}
*/
//---end code---


-- 
Thomas


Post a reply to this message

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