Gradient vectors

Is it possible to query/calculate (irradiance)gradient vectors through any of the Radiance programs?

If you generate an ambient file (through the -af option) while running rpict or rtrace, then you can query the position and directional info about the gradients through lookamb. There is already a tool that creates visualization-friendly Radiance definitions for the ambient data (description). You might have to download this from the repository and call it through a compatible perl installation if you are on Windows.

I dont think irradiance gradients are relevant for pure monte-carlo simulations performed with rcontrib/rfluxmtx as there is no ambient cache.


There is a newer version of genambpos in the distribution that handles the more recent format and can show both direction and rotation gradients along with (elliplical) regions of influence and corral test directions. (See presentation slides 15-31 for details.)

Thanks for the answers.

I tried lookamb on an ambient file and found it very useful. It shows the gradients of the cached values. However I want to visualize the gradient vectors for desired locations(as input), is this achievable?

Basically I have a set of level curves and want to experiment that the gradient vectors are normal to the curve.

Yes, although it’s not properly documented. The “genambpos” Perl script should be installed as part of your distribution, and includes options for visualizing pretty much everything stored in the ambient file. The basic idea is that you run this program (with appropriate options discoverable from usage message or the script itself) on the ambient file to create additional geometry to render your scene with. So, if you have a scene “scene.oct” and have generated the ambient file “scene.amb”, you could run:

genambpos -p -d scene.amb | oconv -i scene.oct - > scene_amb.oct

The -p and -d options add position and gradient vectors, respectively. You then render the new octree from your desired view point(s).

If you want to just look at a subset of the vectors, you could try filtering the input by sending the output of lookamb -h -d to rcalc with an appropriate setting to the “cond” variable then running that into lookamb -r -h -d to create a subset ambient file:

lookamb -h -d scene.amb | rcalc -e ‘$1=$1;$2=$2;$3=$3;…$21=$21’ -e ‘cond=positive_if_desired(arguments)’ | lookamb -r -h -d > subscene.amb

It’s a bit tedious, but you need a $N=$N for every N from 1 to 21, because that’s the way rcalc works. The function positive_if_desired() should somehow return > 0 if the ambient value is one you want to visualize. You then run the earlier command on this subset of the ambient values.

Yes that will do. Thanks.

Although it would have been useful if there was a command similar to rtrace to calculate gradients for a given point. This way I wouldn’t have to look up the ambient file to find the desired value. Specifically it is useful when predicting the next point on the level curve using gradients, where I only need it for a point at a time.

Well, if you make a single query in rtrace starting with an empty ambient file, you will get a result for that point. It’s rather a lot to pay in start-up costs, but not so bad if you are working with a small scene, I suppose.

I am on Windows and so had to convert the genambpos perl script. However the output octree shows only the scene. I didn’t see the vectors.
Or is it possible to make the output to be an octree of the vectors only?

please let me know if I need to share other data.

genambpos -p -d assets\ambient.amb | oconv -i assets\content\proposed.oct > assets\content\scene_amb.oct

^ illegal variable name
^ illegal variable name
^ illegal variable name

You probably meant to have back-quotes, rather than single-quotes in your variable names. You should not have to convert the script – just get Perl for Windows or download the installer and use the precompiled binaries, which have Perl interpreters built in.