Skip to content

RoyCamera3D

在上层,我们已经介绍过RoyCameraComponent,而RoyCamera3D则是RoyCameraComponent的具体实现方式,在实现上RoyCameraComponent持有一个RoyCamera的实例,可以说RoyCameraComponent是表,而RoyCamera3D是里。

也就是说相机的能力并不是RoyCameraComponent的,而是RoyCamera3D的,封装为component的形式,那么就可以统一场景描述,赋予RoyCamera3D挂接到RoySceneNode的能力。

从另外一个角度讲,如果有一个功能集(无论是什么类,什么封装形式),他只要持有RoyCamera的实例,那么就拥有相机的能力。我们往往会遇到这种类型的功能集的封装,并不一定要依赖于RoyCameraComponent才能完成。这样使得操作更加的灵活。但在一般使用时,一般还是推荐使用RoyCameraComponent对象,如果你使用RoyCamera3D,那么你一定对你的行为非常清楚。

RoyCamera3D或者说RoyCameraComponent的具体行为如下:

  • 对相机矩阵(ViewMatrix)和投影矩阵(ProjectMatrix)的封装
  • 对后期处理效果的设置,所包含的后效有:
    • 辉光(bloom)
    • 屏幕空间反射(SSReflection)
    • 屏幕空间折射(SSRefraction)
    • 环境光阴影遮蔽(AO)
    • 景深(Dof)
    • 多重采样抗锯齿(Msaa)
    • 时序抗锯齿(Taa)
    • 雾效(Fog)(室内家具没有雾,这部分暂时没有完善支持)
    • 阴影相关(软阴影、协方差阴影算法策略等)
    • 颜色矫正(ColorGrading)
    • 描边显示
    • 光线追踪(RayTrace)(一个基于Webgl的光线追踪方式)
    • 物理相机参数(快门速度等,控制曝光模拟)
  • 对视口的设置,如:
    • 视口固定缩放
    • 动态分辨率设置
  • 渲染管线的选择,如线框模式,颜色线框模式等。

综上,可以看出RoyCamera3D封装的是相机和视口的概念,在一些引擎中,会将相机和视口的概念分开,但这里为了简化,避免太多的概念产生,将二者结合到一起。另外,如果你一下子搞不清楚这些效果的设置,也没有关系,使用默认的参数就好。这些概念的衍生主要是实时渲染引擎多年的技术演化而积累下来的,背后都有一个关联的技术,可以在后面逐步了解。

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

typescript
/**
 * Interface for the data of a RoyCameraComponent
 */
interface RoyCameraComponentData extends RoyComponentData {
    /** The name of scene node of the component */
    parentNodeName: string;
    /** Type of camera projection */
    projectType: string;
    /** Field of view */
    fov: number;
    /** Width of the viewport */
    pw: number;
    /** Height of the viewport */
    ph: number;
    /** Near clipping plane */
    near: number;
    /** Far clipping plane */
    far: number;
    /** Priority of the camera in rendering */
    renderPriority?: number;
    /** Options for physical camera */
    physicalCameraOptions?: PhysicalCameraOptions;
    /** Options for bloom effect */
    bloomOption?: View$BloomOptions;
    /** Options for screen space reflections */
    ssReflectionsOption?: View$ScreenSpaceReflectionsOptions;
    /** Whether screen space refraction is enabled */
    ssRefractionEnabled?: boolean;
    /** Whether depth blur is enabled */
    isGrabDepthBlur?: boolean;
    /** Options for ambient occlusion */
    ambientOcclusionOptions?: View$AmbientOcclusionOptions;
    /** Options for dynamic resolution */
    dynamicResolutionOptions?: View$DynamicResolutionOptions;
    /** Options for depth of field */
    depthOfFieldOptions?: View$DepthOfFieldOptions;
    /** Options for multisample anti-aliasing */
    multiSampleAntiAliasingOptions?: View$MultiSampleAntiAliasingOptions;
    /** Options for temporal anti-aliasing */
    temporalAntiAliasingOptions?: View$TemporalAntiAliasingOptions;
    /** Options for fog */
    fogOptions?: View$FogOptions;
    /** Options for vignette */
    vignetteOptions?: View$VignetteOptions;
    /** Options for guard band */
    guardBandOptions?: View$GuardBandOptions;
    /** Options for color grading */
    colorGradingOptions?: ColorGradingOptions;
    /** Options for ray tracing */
    rayTraceOptions?: RayTraceOptions;
    /** Type of shadows */
    shadowType?: string;
    /** Options for variance shadows */
    vsmShadowOptions?: View$VsmShadowOptions;
    /** Options for soft shadows */
    softShadowOptions?: View$SoftShadowOptions;
    /** Options for clipping planes */
    clippingPlanesOptions?: View$ClippingPlanesOptions;
    /** Clear color */
    clearColor: number[];
    /** Draft clear color */
    draftClearColor?: number[];
    /** Options for clearing the back buffer */
    clearBackBufferOptions?: Renderer$ClearOptions;
    /** Renderer level */
    renderLevel?: string;
    /** Whether front face winding is inverted */
    frontFaceWindingInverted?: boolean;
    /** Whether front face winding is automatically inverted */
    frontFaceWindingAutoInverted?: boolean;
    /** Whether to draw wireframe */
    drawWireframe?: boolean;
}