Have you checked that all lights you get are disabled?
I reimplemented _RecordAnimation recently in C# to cater better for Raytraced (and other realtime render engine integration) viewport capturing, but the sun handling has been directly taken from the old _RecordAnimation implementation: when a sun study is made the document sun is disabled, but another directional light is added to simulate the sun. Make sure that you also check the light changes - there should be a directional light that is enabled and has the sun positional data required for that frame.
When RecordAnimation is used for a Sun Study it does the following steps:
before the first frame disable sun document if enabled
on the very first frame add a directional light with the proper orientation
on each subsequent frame delete the directional light added in the previous frame and add a new directional light with adjusted orientation
after all frames have been recorded delete the directional light added for the last frame and re-enable document sun if it was enabled before starting the animation recording
The attached file RH-68289_SunAnimation.3dm (3.6 MB) contains a one-day sun animation using Raytraced that should result in a 13-frame animation.
On my M1 Rhino is sufficiently slow even when giving 5 samples for rendering to see that a directional light pops up in the lights panel while the recording session is ongoing. The model itself contains only a point light - skylight and sun are not enabled.
The Raytraced result leads me to believe this works as intended, since the directional light added by RecordAnimation is doing its thing in the animation.
Addendum: I am assuming we’re talking Rhino 7 here, I’m using Rhino 7.18 for testing. The _RecordAnimation rewrite is rather new, realized September 2021, so you need a recent enough for that, probably Rhino 7.11 or Rhino 7.12.
When you run _RecordAnimation and give 5 for the samples per frame it will do its thing. The frames rendered will then be written to the specified folder. If you check those you’ll see that the sun is there.
I made the scene specifically so that the sun is already disabled. The resulting animation will have a sun enabled. This sun is simulated with a directional light separate from the document sunn, it will be given to you through the change queue as a directional light in ApplyLightChanges.
Note: the current C# implementation is a translation of the original C++ implementation. I could see in the future if I can change the _RecordAnimation command to using the document sun instead without breaking old renderings. I think the current implementation was created so that the light color doesn’t change for the sun, but I can only guess as the design decision for the initial implementation isn’t document AFAICT.
So it will appear in ApplyLightChanges and not in ApplySunChanges… My mistake.
Ok, I can see the extra light. How can I know that this directional light is actually the replacement for the normal sun light?
I should separate directional lights from the sun light for our engine…
That is a good question. To be honest I am not sure. Directional light is always supposed to be a light simulating the sun, but if you already have several of them it’ll be a bit hard to determine which one is the sun.
The algorithm for setting the light locations is to use the camera location for that frame, so maybe you could check if the view location matches with the direct light location?
This is the code setting up that directional light:
Point3d cPt = animationProperties.CameraPoints[i];
Point3d tPt = animationProperties.TargetPoints[i];
if (sunStudy)
{
Light light = new Light
{
LightStyle = LightStyle.WorldDirectional,
Location = cPt,
Direction = tPt - cPt,
ShadowIntensity = 1
};
ReplaceLight(doc, animationProperties, light);
}
// etc.