This is the documentation for Enlighten.

module Customer Lights

There are 3 steps to adding a custom light type.

  1. Before creating a light class here, add the light ID to enum eLightType defined in EnlightenLights.h.

  2. Create a light class with any name but adhering to the following template:

    class CustomerLightType : public InputLightBase // <== Must inherit from InputLightBase
    {
    public:
        CustomerLightType()
            : InputLightBase(LIGHT_TYPE_CUSTOMER_LIGHT_TYPE) //Init InputLightBase with the customers enum value added to enum eLightType in EnlightenLight.h
            //..init appropriate members
        {
        };
    
        //Add destructor
        ~CustomerLightType() {}
    
        //..add light members
    
        //..add a class called CachedData here. This is the main object which does all the work. 
        // The input lighting framework will automatically generate this CachedData object from the light 
        // pointers passed into the DoDirectInputLighting() function parameter.
        struct CachedData : public InputLightBase // <== Must inherit from InputLightBase
        {
            //Add a constructor which takes the main light type as its only parameter
            CachedData(PointLight& pointLight, void* visibilityPointer) 
                : InputLightBase(LIGHT_TYPE_POINT_LIGHT) //Init InputLightBase again
                // init members
            {
    
            }
            
            //add members here which contain optimized data for best performance. 
    
            //===================================================
            // Add member functions with the following signatures
            //===================================================
    
            //Function to shade four point with 4 normals. The quad idx and cluster idx can be used for looking up visibility in the visibility buffer.
            //The return values are the intensities of the four samples in each channel of the v128
            GEO_CONTROLLED_INLINE Geo::v128 ShadeQuadIntensities(const Geo::v128& positionsX, 
                                                            const Geo::v128& positionsY, 
                                                            const Geo::v128& positionsZ, 
                                                            const Geo::v128& normalsX,
                                                            const Geo::v128& normalsY,
                                                            const Geo::v128& normalsZ,
                                                            Geo::u32 clusterIdx,
                                                            Geo::u32 quadIdx) const
            {
            }
    
            //Shade the four samples and return the average as a single colour
            GEO_CONTROLLED_INLINE Geo::v128 ShadeQuad(  const Geo::v128& positionsX, 
                                                    const Geo::v128& positionsY, 
                                                    const Geo::v128& positionsZ, 
                                                    const Geo::v128& normalsX,
                                                    const Geo::v128& normalsY,
                                                    const Geo::v128& normalsZ,
                                                    Geo::u32 clusterIdx,
                                                    Geo::u32 quadIdx) const
            {
            }
    
            //Shade the four samples and return the individual colours 
            GEO_CONTROLLED_INLINE void ShadeFourSamples(    const Geo::v128& positionsX, 
                                                    const Geo::v128& positionsY, 
                                                    const Geo::v128& positionsZ, 
                                                    const Geo::v128& normalsX,
                                                    const Geo::v128& normalsY,
                                                    const Geo::v128& normalsZ,
                                                    Geo::u32 sampleIdx,
                                                    Geo::v128& colourOut0,
                                                    Geo::v128& colourOut1,
                                                    Geo::v128& colourOut2,
                                                    Geo::v128& colourOut3) const
            {
            }
    
            //Test if the light intersects the systems bounding box 
            GEO_CONTROLLED_INLINE bool  IsIntersectingSystem(const Geo::v128& bbMin, const Geo::v128& bbMax) const
            {
                return true;
            }
    
            //Test if the lights intersects a group of clusters bounding box. Additional normal vectors enable culling against direction.
            GEO_CONTROLLED_INLINE bool  IsIntersectingClusterGroup(const Geo::v128& bbMin, const Geo::v128& bbMax, const Geo::v128& minNormalFlipped, const Geo::v128& maxNormalFlipped) const
            {
                return true;
            }
    
            //Test if the lights intersects a single cluster. Additional normal vectors enable culling against direction.
            GEO_CONTROLLED_INLINE bool  IsIntersectingCluster(const Geo::v128& bbMin, const Geo::v128& bbMax, const Geo::v128& minNormalFlipped, const Geo::v128& maxNormalFlipped) const
            {
                return true;
            }
    
            //hash the light data
            void Hash(Helpers::Hasher &hash, Geo::u32 clusterVisSize, Geo::u32 quadVisSize)
            {
            }
        };
    };  //Note: For additional examples see PointLight.h, Spotlight.h and DirectionalLight.h for.
    

  3. Finally, add a conversion specialization of template TypeIdToType defined in EnlightenLightTypes.h

    // Specialization to convert Light type enumeration to concrete type
    template<>
    struct TypeIdToType<LIGHT_TYPE_CUSTOMER_LIGHT_TYPE>
    {
    typedef CustomerLightType Type;
    };
    

  4. Optionally, add a specialization of template CanQuickShade defined in EnlightenLightCommon.h if the light supports quick shade. If no specialization is provided, the framework assumes the light does not support quick shade. Quick shade can be used when a shading result will be the same for all samples in a cluster. For example, a directional light which is being used to shade a flat cluster.

    // Specialization to enable QuickShade on this light type.
    template<>
    struct CanQuickShade<LIGHT_TYPE_CUSTOMER_LIGHT_TYPE>
    {
    static const bool Value = true;
    };