In ChangeQueue > ApplySunChanges > wrong light status under Sun Study?

The plugin uses a customized Rhino.Render.ChangeQueue.ChangeQueue object to export the scene.

It reads the Sun values inside ApplySunChanges()

The sun light is ON

And if I run a Render command inside ApplySunChanges() the light is enabled

if (light.IsSunLight)
isEnabled = light.IsEnabled;

isEnabled is ON, which is good.

But in case I do a Sun-Study, when it exports the frames the value of light.IsEnabled is OFF.

Is it intentional?


Does this happen when doing _RecordAnimation for the sun study?

Yes, during RecordAnimation

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.

Here I receive no other light(s) only the Disabled sun light.

If I handle this sun light as if it was enabled, the result seems to be correct.

I’ll check the code again and compare against what I see in Raytraced. It should all be the same, but who knows, I may have introduced a bug there.

Logged as RH-68289 _RecordAnimation of a sun study gives incorrect sun state

@marton.parlagh I have double-checked the code:

When RecordAnimation is used for a Sun Study it does the following steps:

  1. before the first frame disable sun document if enabled
  2. on the very first frame add a directional light with the proper orientation
  3. on each subsequent frame delete the directional light added in the previous frame and add a new directional light with adjusted orientation
  4. 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.

I use Rhino 7.15

This is the scene - right?

But here on the Lights panel I can see that Sun is turned OFF. So I can not init the sun animation. Or maybe I misunderstand something?

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.

ooo, I get it now.

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.

Ok, thanks for the idea!

What I do now and seems to work:

I test the RhinoObject of the light if it was made before or after RecordAnimation has begun.

1 Like

That sounds like a great approach to :slight_smile: