Skip to content

RoyLight3D

RoyLight3D是引擎的内部对象,但是在上层并不使用这个对象,而是使用挂接到RoySceneNode 的RoyLightComponent及其派生类,RoyLightComponent的派生类有:

  • RoyOmniLightComponent:点光
  • RoySpotLightComponent: 聚光灯
  • RoyRectLightComponent:面光
  • RoyDirectionLightComponent: 方向光
  • RoySunLightComponent: 太阳光

无论是上面哪一种光的类型,都会持有一个RoyLight3D的实例,RoyLight3D和上面的LightComponent也是互为表里的关系,方便引擎做除了Object-Component以外的其他形式的封装,如果你直接使用RoyLight3D,那么一定要对自己的行为清楚。

这里还有必要解释一下方向光和太阳光,一般的引擎并不会对二者进行区分,认为太阳光就是方向光。而在这里表达的是,方向光和太阳光在光照的公式上并没有差异,但太阳光还会在天空盒上对太阳进行模拟以及对光晕产生影响;方向光则仅有对物体的照亮。那么什么时候会有多个方向光呢,天空中出现9个太阳的时候吗? 额,不是,一些物体在展示的时候,也会增加一些补光,使其看上去更加有立体感,比如人物展示界面,往往一盏主的方向光,一盏辅助的方向光。当然这种和团队的技术美术(Technology Artist)很有关系,并不是所有的都这样。

基本属性描述,

  • RoyLightComponent:
    • 灯光颜色
    • 灯光强度
    • 是否产生阴影
    • lightmask(用于与物体之间的屏蔽)
  • RoyOmniLightComponent:
    • 衰减距离
    • 光域网文件的url
  • RoySpotLightComponent:
    • 衰减距离
    • 内径
    • 外径
    • 光域网文件的url
  • RoyRectLightComponent:
    • 宽度
    • 高度
    • 是否双面
  • RoyDirectionLightComponent:
    • (同基类,无额外扩展属性)
  • RoySunLightComponent:
    • sunAngularRadius
    • sunHaloSize
    • sunHaloFalloff

对于RoyLight3D的属性,其在RoyProtocal中的结构体对应,摘要如下:

typescript
/**
 * Data interface for RoyDirectionLightComponent
 */
interface RoyDirectionLightComponentData extends RoyComponentData {
    /** Type of light */
    lightType: string;
    /** Color of the light */
    color: number[];
    /** Intensity of the light */
    intensity: number;
    /** Light mask */
    lightMask?: number;
    /** Whether the light casts shadows */
    shadowCaster?: boolean;
}

/**
 * Interface for data of the RoyOmniLightComponent
 */
interface RoyOmniLightComponentData extends RoyComponentData {
    /** The type of light */
    lightType: string;
    /** The color of the light */
    color: number[];
    /** The intensity of the light */
    intensity: number;
    /** The light mask of the light */
    lightMask: number;
    /** The falloff of the light */
    fallOff: number;
    /** The IES data of the light */
    iesData?: string;
}

/**
 * Data structure for rectangular light component
 */
interface RoyRectLightComponentData extends RoyComponentData {
    /** Type of light */
    lightType: string;
    /** Color of the light */
    color: number[];
    /** Intensity of the light */
    intensity: number;
    /** Light mask */
    lightMask: number;
    /** Width of the light */
    width: number;
    /** Height of the light */
    height: number;
    /** Whether the light is double-sided */
    doubleSide: boolean;
}

/**
 * Interface for data of a spot light component.
 */
interface RoySpotLightComponentData extends RoyComponentData {
    /** The type of light. */
    lightType: string;
    /** The color of the light. */
    color: number[];
    /** The intensity of the light. */
    intensity: number;
    /** The light mask. */
    lightMask: number;
    /** The falloff of the light. */
    fallOff: number;
    /** The inner cone of the light. */
    innerCone: number;
    /** The outer cone of the light. */
    outerCone: number;
    /** The IES data of the light. */
    iesData?: string;
}

/**
 * Data structure for RoySunLightComponent
 */
interface RoySunLightComponentData extends RoyComponentData {
    /** Type of light */
    lightType: string;
    /** Color of the light */
    color: number[];
    /** Intensity of the light */
    intensity: number;
    /** Light mask */
    lightMask: number;
    /** Whether the light casts shadows */
    shadowCaster: boolean;
    /** Angular radius of the sun */
    sunAngularRadius: number;
    /** Size of the sun halo */
    sunHaloSize: number;
    /** Falloff of the sun halo */
    sunHaloFalloff: number;
}