diff --git a/src/GraphicsSystem/FXAAPass.ts b/src/GraphicsSystem/FXAAPass.ts new file mode 100644 index 000000000..706c14897 --- /dev/null +++ b/src/GraphicsSystem/FXAAPass.ts @@ -0,0 +1,17 @@ +import { FXAAShader, ShaderPass } from "three"; +require("three-EffectComposer"); +require("three-ShaderPass"); +require("three-FXAAShader"); + +export class FXAAPass extends ShaderPass +{ + constructor() + { + super(FXAAShader); + } + + setSize(width: number, height: number) + { + this.uniforms['resolution'].value.set(1 / width, 1 / height); + } +} diff --git a/src/GraphicsSystem/Viewer.ts b/src/GraphicsSystem/Viewer.ts index 96480a4b6..3ba89fe07 100644 --- a/src/GraphicsSystem/Viewer.ts +++ b/src/GraphicsSystem/Viewer.ts @@ -1,14 +1,16 @@ import { EffectComposer, Matrix4, Object3D, OutlinePass, RenderPass, Scene, SMAAPass, Vector2, Vector3, WebGLRenderer } from 'three'; import { begin, end } from 'xaop'; import { app } from '../ApplicationServices/Application'; +import { arrayRemoveOnce } from '../Common/ArrayExt'; import { GetEntity } from '../Common/Utils'; import { Database } from '../DatabaseServices/Database'; import { Entity } from '../DatabaseServices/Entity/Entity'; import { GenerateRaycaster } from '../Editor/PointPick'; import { userConfig } from '../Editor/UserConfig'; -import { ZeroVec, GetBox, GetBoxArr, isPerpendicularityTo } from '../Geometry/GeUtils'; +import { GetBox, GetBoxArr, isPerpendicularityTo, ZeroVec } from '../Geometry/GeUtils'; import { PlaneExt } from '../Geometry/Plane'; import { CameraUpdate } from './CameraUpdate'; +import { FXAAPass } from './FXAAPass'; import { GripScene } from './GripScene'; import { PreViewer } from './PreViewer'; @@ -19,12 +21,17 @@ require("three-SMAAShader"); require("three-EffectComposer"); require("three-RenderPass"); -require("three-ShaderPass"); require("three-SMAAPass"); require("three-OutlinePass"); +enum AAType +{ + FXAA = 0,//快速近似抗锯齿(性能更好) + SMAA = 1,//多重采样抗锯齿(质量更好) +} + export class Viewer { protected NeedUpdate: boolean = true; @@ -39,9 +46,12 @@ export class Viewer PreViewer: PreViewer; UsePass = false; + private _AAType: AAType = AAType.FXAA; RenderPass: RenderPass; OutlinePass: OutlinePass; Composer: EffectComposer; + private _EffectFXAAPass: FXAAPass; + private _SMAAPass: SMAAPass; private _Scene: Scene = new Scene; @@ -102,6 +112,26 @@ export class Viewer { return this._Height; } + + set AAType(type: AAType) + { + if (type !== this._AAType) + { + if (this._AAType === AAType.FXAA) + { + arrayRemoveOnce(this.Composer.passes, this._EffectFXAAPass); + this.Composer.passes.push(this._SMAAPass); + } + else + { + arrayRemoveOnce(this.Composer.passes, this._SMAAPass); + this.Composer.passes.push(this._EffectFXAAPass); + } + this._AAType = type; + this.UpdateRender(); + } + } + //初始化render InitRender(canvasContainer: HTMLElement) { @@ -144,9 +174,11 @@ export class Viewer this.Composer.addPass(this.OutlinePass); - let smaa = new SMAAPass(this.Width, this.Height); - smaa.renderToScreen = true; - this.Composer.addPass(smaa); + this._SMAAPass = new SMAAPass(this.Width, this.Height); + this._SMAAPass.renderToScreen = true; + this._EffectFXAAPass = new FXAAPass(); + + this.Composer.addPass(this._EffectFXAAPass); this.OnSize(); }