目录

Adding a Filter Effect

Different filter effects can be added to the rendered image of the 3DGS model, including four stylized filters: retro effect, comic effect, black-and-white bit effect, and color editing effect.

API Description

The following lists only some of the main APIs called in the sample code in this guide.

API Description
RETRO_EFFECT_ID ID of the retro effect.
COMIC_EFFECT_ID ID of the comic effect.
OBRA_DINN_EFFECT_ID ID of the black-and-white bit effect.
COLOR_EDITING_EFFECT_ID ID of the color editing effect.

Development Procedure

  1. In the project root directory, open /src/main/ets/entryability/EntryAbility.ets and import the spatial modeling module.

    import { Scene, RenderContext } from '@kit.ArkGraphics3D';
    import { spatialRender } from '@kit.SpatialReconKit';
    import { RenderingPipelineType } from '@ohos.graphics.scene'
  2. Load the context of the current scene.

    let renderContext: RenderContext | null = Scene.getDefaultRenderContext();
  3. Call the filter API.

    if (renderContext != null) {
      renderContext.loadPlugin(spatialRender.GSPlugin.PLUGIN_ID);
      Scene.load().then(async (scene: Scene) => {
        let rf = scene.getResourceFactory();
        let effect : spatialRender.RetroEffect =
          await rf.createEffect({ effectId: spatialRender.GSPlugin.RETRO_EFFECT_ID }) as spatialRender.RetroEffect;
        let camera = await rf.createCamera({ name: "gsCam", path: "//gsCam" }, { renderingPipeline: RenderingPipelineType.FORWARD });
        camera.effects.append(effect)
      });
    }