# Lights

HOOPS Visualize Desktop treats lights as geometry. A light illuminates all geometry in the same scene, irrespective of its location in the segment tree. The only exception is with standard subwindows - lights do not affect geometry in a standard subwindow. Multiple lights can be added to a scene, each with different attributes. Light color defaults to white, though color can be controlled using the `HPS::MaterialMappingControl`. HOOPS Visualize Desktop also offers a few different lighting interpolation algorithms.

        // changing light color to purple
        mySegmentKey.GetMaterialMappingControl().SetLightColor(HPS::RGBColor(1, 0, 1));

    mySegmentKey.GetMaterialMappingControl().SetLightColor(new HPS.RGBAColor(1, 0, 1)); // changing light color to purple

HOOPS Visualize Desktop supports two types of lights: spotlights and distant lights. If a scene contains any lights, then HOOPS Visualize Desktop performs lighting calculations for all the objects in the scene. The color of each object will then depend not only on that object’s color, but also on the amount and color of the light falling on it. Thus, inserting the first light into a scene can sometimes make the scene look darker, because the sides of objects facing away from the light source will be darker than before. In HOOPS Visualize Desktop, light intensity does not attenuate over distance. Additionally, there is no shadowing by default - the lighting for each triangle is independent of other triangles.

The top image has no lights, the bottom image is lit

## Distant Lights

If all you want to do is provide diffuse light to a scene, so that HOOPS Visualize Desktop draws objects brighter on one side than on the other to convey a sense of depth, then you probably want a distant light. Distant lights are recommended as a general purpose light source because they are fully supported by 3D graphics hardware. To insert a distant light, simply use:

        mySegmentKey.InsertDistantLight(Vector(x, y, z));

    mySegmentKey.InsertDistantLight(new HPS.Vector(x, y, z));

In the case of a distant light, the arguments x, y, and z are not a location in space - they are a direction vector from the origin toward the light source. The light source acts as though it were infinitely far away: the light rays are all parallel to one another, and the light intensity does not drop off with distance.

The model on the left is lit with a distant light, the right is lit by a light positioned near the model

If you notice that lights cause your scene to appear in a way that you did not expect, check to see that your normals are set up correctly. HOOPS Visualize Desktop can generate normals automatically, although it depends on the polygon handedness setting to do so. Polygon handedness is described in the culling optimizations section.

## Spotlights

Spotlights are a directional light source emitted from a single point in space. The light position and target points define a primary direction in which a spotlight shines. Expanding in this direction from the light position is an infinite cone of illumination inside which surfaces are illuminated.

A scene lit by a spotlight positioned above the table

        HPS::SpotlightKit spotlightKit;
        spotlightKit.SetCameraRelative(false)
            .SetPosition(Point(20, 40, 0))
            .SetTarget(Point(0, 0, 0))
            .SetInnerCone(20, HPS::Spotlight::InnerConeUnits::Degrees)
            .SetOuterCone(30, HPS::Spotlight::OuterConeUnits::Degrees);

        HPS::SpotlightKey spotlightKey = mySegmentKey.InsertSpotlight(spotlightKit);

    HPS.SpotlightKit spotlightKit = new HPS.SpotlightKit();
    spotlightKit.SetCameraRelative(false)
                .SetPosition(new HPS.Point(20, 40, 0))
                .SetTarget(new HPS.Point(0, 0, 0))
                .SetInnerCone(20, HPS.Spotlight.InnerConeUnits.Degrees)
                .SetOuterCone(30, HPS.Spotlight.OuterConeUnits.Degrees);

    HPS.SpotlightKey spotlightKey = mySegmentKey.InsertSpotlight(spotlightKit);

In the image below, you can see the effect of the spotlight cone. The dark grey area is unlit by the light. The fuzzy blended area is lit by the spotlight’s outer cone. The white area is lit by the inner cone. The diagram below demonstrates this:

Spotlight diagram

## Camera-Relative Lights

When the camera changes, lights behave like any other piece of geometry. Their insertion point and direction are based on object-space coordinates, and those coordinates do not change when the camera changes. This means that if a light happens to be shining down the direction of the camera target vector, a highlight will be present on the ‘front’ of all visible geometry, and the highlight will appear to move with the geometry as the camera moves. Therefore, if the camera moves to the other side of the object, the object will be dark, since the camera is now viewing the dark side of the object.

It is frequently desirable to have the highlights remain visible on objects relative to the camera position so that when orbiting the camera, the object does not become shadowed. Of course, this can be controlled directly by the developer by moving the lights as the camera changes. However, this requires having special code that gets executed every time the camera is adjusted. Instead, you can use a feature called ‘camera-relative lights’. This is an option applied to lights which locks their relative position to the camera. The end result is the position of the light will automatically get updated as the current camera changes. This setting is available for spotlights as well as distant lights. You can make a light into a camera-relative light by calling:

        spotlightKey.SetCameraRelative(true);

        distantLightKey.SetCameraRelative(true);

    spotlightKey.SetCameraRelative(true);

    distantLightKey.SetCameraRelative(true);

Conversation saved
HOOPSY BETA

### Hello! I'm HOOPSY

Your Docs generative AI assistant. Ask me anything about HOOPS Visualize Desktop or choose a sample question below to start a conversation:

What is HOOPS Visualize Desktop?
What are the latest release notes for HOOPS Visualize Desktop?
How do I start evaluating HOOPS Visualize Desktop?
How do I write my first sample application?
How can I get assistance?

HOOPSY may store conversations according to OpenAI's policy. Responses may not always be accurate.

HOOPSY is thinking...