POV-Ray : Newsgroups : povray.text.scene-files : Lightning macro Server Time
1 Nov 2024 05:22:33 EDT (-0400)
  Lightning macro (Message 1 to 3 of 3)  
From: Gail Shaw
Subject: Lightning macro
Date: 30 Apr 2001 07:53:53
Message: <3aed5251@news.povray.org>
As requested my Mr Art and Nekar. Please note that
this macro has problems, it's been on my 'to finish' list
for several months. If anyone makes any imrovements,
please let me know.

Gail
*************************************************************************
* gsh### [at] monotixcoza                *   Step into the abyss,           *
* http://www.rucus.ru.ac.za/~gail/   *   and let go.        Babylon 5   *
*************************************************************************
* The difficult we do immediately, the impossible takes a little longer *
*************************************************************************


// Persistence of Vision Ray Tracer Scene Description File
// File: lightning.inc
// Vers: 3.1
// Desc: Lightning macro
// Date: 3 Sept 2000
// Auth: Gail Shaw

// #version unofficial MegaPov 0.5;

// #include "macros.inc"

/*
Notes:
 BranchFreq, Eccentricity and WidthReduct are all percentages.
 BranchFreq controls the chance that the lightning bolt will fork at the end
of
 each segment. Keep below 20%
 The higher the Eccentricity, the larger the angle between bolts.
 WidthReduct defines how much narrower each segment should be. It should be
kept
 fairly large (>80)
 LightningTex is the texture applied to each segment of the lightning bolt.
It is applied before the
 segment is translated (Applied to a cylinder lying along the y axis) unless
TextureBefore=0
*/

#macro
Lightning(Start,Length,StartWidth,BranchFreq,Eccentricity,WidthReduct,Lightn
ingTex)
 #ifndef (rndLightning)
  #local rndLightning=seed(0)
 #end
 #ifndef (TextureBefore)
  #local TextureBefore=1;
 #end
 #ifndef (Shadow)
  #local Shadow=0;
 #end
 union {
  #local UnitLength=Length/50;
  #if (abs(UnitLength)<0.00001)
   #local UnitLength=0.00001;
  #end
  // WriteNumber("UnitLength",UnitLength)
  #local CurrWidth=StartWidth;
  #local CurrLength=0;
  #local ZRot=0;
  #local XRot=0;
  #local CurrEndPos=<0,0,0>;
  #while (CurrLength<Length)
   #local CurrSegLength= -UnitLength*((rand(rndLightning)/2)+0.5);
   #local SegEndPos=<0,CurrSegLength,0>;
   cylinder {
    <0,0,0>,<0,CurrSegLength,0>,CurrWidth
    #if (TextureBefore=1)
     texture {LightningTex}
    #end
    #local ZRot=ZRot/4+(50+Eccentricity/2)*(rand(rndLightning)-0.5);
    #local XRot=XRot/4+(50+Eccentricity/2)*(rand(rndLightning)-0.5);
    rotate z*ZRot
    // WriteNumber ("ZRotation",ZRot)
    rotate x*XRot
    // WriteNumber ("YRotation",YRot)
    // WriteVector("Segment End Pos Before Rot",SegEndPos)
    #local SegEndPos=vrotate(SegEndPos,<0,0,ZRot>);
    // WriteVector("Segment End Pos afterRotZ",SegEndPos)
    #local SegEndPos=vrotate(SegEndPos,<XRot,0,0>);
    // WriteVector("Segment End Pos afterRotY",SegEndPos)
    translate CurrEndPos
    // WriteVector("Current End Pos Before addition",CurrEndPos)
    #local CurrEndPos=CurrEndPos+SegEndPos;
    // WriteVector("Current End Pos after addition",CurrEndPos)
   }
   #local Branch=rand(rndLightning)*100;
   #if (Branch<BranchFreq)
    // WriteNumber("Branching No",Branch)
    object {

Lightning(<0,0,0>,Length/2,CurrWidth,BranchFreq/2,Eccentricity,WidthReduct,L
ightningTex)
     rotate z*(80+Eccentricity/2)*(rand(rndLightning)-0.5)
     rotate x*360*rand(rndLightning)
     translate CurrEndPos
    }
   #end
   #local CurrLength= vlength(CurrEndPos);
   // WriteNumber("Current Length",CurrLength)
   #local CurrWidth=CurrWidth*WidthReduct/100;
  #end
  sphere {
   CurrEndPos,CurrWidth*100/WidthReduct
   #if (TextureBefore=1)
    texture {LightningTex}
   #end
  }
  #if (TextureBefore=0)
   texture {LightningTex}
  #end
  #if (Shadow=0)
   no_shadow
  #end
  hollow
  translate Start
 }
#end

camera {
 location <0,1,-10>
 look_at <0,1,0>
}

light_source {
 <0,5,-10>
 rgb 1
}

plane {
 z,10
 hollow
 pigment {rgb 0.5}
}

plane {
 y,0
 hollow
 pigment {rgb 0.5}
}

#declare LightTex=
 texture {
  pigment {rgb 1}
  finish {ambient 1}
 }

#declare colLeaf_1=rgb <0.7,1,0.2>*0.8; // greenish
#declare colLeaf_2=rgb <1,0.7,0.2>*0.8; // yellow
#declare txtLeaf=texture{pigment{agate color_map{[0.0 color colLeaf_1][0.3
color colLeaf_2] [0.7 color colLeaf_2][1.0 color colLeaf_1] }}
        finish{ambient 0.1 specular 0.3 roughness 0.01} scale 0.1}


#declare rndLightning=seed(24);
//
Lightning(Start,Length,StartWidth,BranchFreq,Eccentricity,WidthReduct,Lightn
ingTex)

#declare TextureBefore=0;
#declare Shadow=0;

object {
 Lightning(<0,2,0>,2,0.02,3,90,99,LightTex)
 scale 2
}


Post a reply to this message

From: Nekar Xenos
Subject: Re: Lightning macro
Date: 30 Apr 2001 08:50:43
Message: <3aed5fa3@news.povray.org>
Thanks

Nekar


Post a reply to this message

From: Mr  Art
Subject: Re: Lightning macro
Date: 2 May 2001 08:18:34
Message: <3AF0338A.F0FE3621@chesapeake.net>
Thanks Gail.

Gail Shaw wrote:
> 
> As requested my Mr Art and Nekar. Please note that
> this macro has problems, it's been on my 'to finish' list
> for several months. If anyone makes any imrovements,
> please let me know.
>


Post a reply to this message

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