These examples cover the basic FRED scripting commands involving importance sampling: "Add" - adds curve, entity and specular importance sampling, "Delete" - deletes importance sampling entry, "Get" - retrieves importance sampling parameters from an existing entry, "Is" - queries importance sampling entry, "Set" - sets importance sampling parameters for an existing entry.
The structure listed below contains parameters required to define importance sampling:
Importance sampling enhances the efficiency of raytracing. This feature forces rays to be traced only where desired. Selecting the proper type of importance sampling depends strongly upon the application. The types of importance sampling in FRED are listed below: •towards a closed Curve, •towards an Entity, •towards a point, •towards a volume defined by an ellipsoid, •into a solid angle about the specular direction, •into a solid angle about a given direction vector.
Note: Several other parameters are required to fully describe an importance sampling entry. These parameters, listed below, are set to their default values when an importance sampling entry is added. "Set/Get" commands allow the user to retrieve and change these defaults. •Active (default=True) •Number of scattered rays per incident ray (default=10) •Reverse direction (default=False) •Solid angle scale factor (default =1) •Fractional hole in solid angle (default=0)
"Add" an importance sampling entry Each of the above listed importance sampling types can be added to a FRED document. Only the volume ellipsoid requires a structure. All others can be added using a single script command.
The following example adds an "about specular" importance sampling entry named "Towards mirror specular" with a half angle of 30 deg to "Mirror1". The function returns its importance sampling entry index associated with "Mirror1".
mid = FindName("Mirror1") impSamp = ImpSampAddSpecular ( mid, "Towards mirror specular", 30 )
In this example, "Prism Surface 1" is given an "about direction vector" importance sampling. Rays are scattered into a 2 deg half angle about the direction vector (1,1,0) defined in the prism surface coordinate system.
psid= FindName("Prism Surface 1") impSamp = ImpSampAddDir ( psid, "directional", 2, 1, 1, 0, psid )
This example adds an importance sampling ellipsoid to the surface "diffuser back". The ellipsoid center is located at (0,0,8). The ellipse 1st axis is (1,0,0) and its second axis is (0,1,0). Semi-aperture lengths are 2 for the 1st axis, 4 for the second axis, and 1 for the implicit 3rd axis. The center and these direction vectors are defined in the global coordinate system.
Dim ell As T_IMPSAMPELLIPSOID difid = FindName("diffuser back") ell.x=0:ell.y=0:ell.z=8 'xyz coordinates of ellipse center in "entity" coordinate system ell.a1=1:ell.b1=0:ell.c1=0 'direction vector of ellipse 1st axis ell.a2=0:ell.b2=1:ell.c2=0 'direction vector of ellipse 2nd axis ell.semiApe1=2 'ellipse 1st semiaperture length ell.semiApe2=4 'ellipse 2nd semiaperture length ell.semiApe3=1 'ellipse 3rd semiaperture length ell.entity=-1 'global coordinate system impSamp = ImpSampAddEllipsoid ( difid, "towards a volume", ell )
Note: The presence of general direction vectors for this importance sampling allows the user to arbitrarily orient the ellipsoidal volume. The 1st semi-aperture length is measured along the 1st ellipse axis direction vector (a1,b1,c1). The 2nd semi-aperture length is measured along the 2nd ellipse axis vector (a2,b2,c2). Note that this 2nd vector direction need not be orthogonal to the 1st vector direction. In any case, however, the vectors (a1,b1,c1) and (a2,b2,c2) define a plane. Thus, the 3rd semi-aperture is measured along a direction (a3,b3,c3)=(a1,b1,c1)x(a2,b2,c2). FRED will then internally reorient the second vector such that (a2,b2,c2) Ž (a2',b2',c2')=(a3,b3,c3)x(a1,b1,c1).
"Delete" an importance sampling entry In some cases, rather than altering an importance sampling, it may be desirable to delete it. A single line performs this operation. In this example, node 25 has its 3rd importance sampling specification deleted. Note that the specifications are zero-indexed.
ImpSampDelete 25,2
"Get" importance sampling entry information The "Get" commands retrieve any setting for an importance sampling entry. The possibilities are Angle Hole - fractional hole value Angle Scale - hole scale value Count - number of importance sampling entries Curve - curve node number Description - user-defined description Dir - given direction vector, cone angle Ellipsoid - populates T_IMPSAMPELLIPSOID Entity - entity node number Name - importance sampling entry name Position - point xyz, cone angle RayCount - scattered rays per incident ray Specular - cone angle Type - "Curve", "Entity", "Position", "Direction", "Specular", "Ellipsoid", or "Unknown".
In this example, the type of a specific importance sampling entry is retrieved. For the case of the ellipsoidal volume above,
ImpSampType = ImpSampGetType ( difid, 0 )
would return ImpSampType="Ellipsoid".
One might also be interested in retrieving the node number of the entity towards which rays are scattered for a specific importance sampling entry. Here, impsampent will contain the entity node number towards which the second importance sampling entry associated with node m1id is scattering.
ImpSampGetEntity m1id, 1, impsampent
"Is" queries an importance sampling entry The "Is" queries ask FRED whether a specific importance sampling entry is Active or if the rays are Reversed. FRED returns True or False.
For example, is the 2nd importance sampling entry on "Mirror1" active?
active = ImpSampIsActive ( GetName("Mirror1"), 1 )
or, are the rays reversed on the 1st importance sampling entry on mode 16?
reversed = ImpSampIsReversed ( 16, 0 )
"Set" importance entry parameters The "Set" commands for importance sampling need not be used in conjunction with their corresponding "Get" commands with the exception of the Ellipsoid. Recall that the Ellipsoid uses the T_IMPSAMPELLIPSOID structure.
For example from the prism example above, the number of scattered rays per incident ray is set to 1000 and the ray directions reversed:
psid= FindName("Prism Surface 1") impSamp = ImpSampAddDir ( psid, "directional", 2, 1, 1, 0, psid ) ImpSampSetRayCount psid, impSamp, 1000 ImpSampSetReversed psid, impSamp, True See Also….
|