import { Laya } from "Laya" ; import { PostProcess } from "laya/d3/component/PostProcess" ; import { Camera } from "laya/d3/core/Camera" ; import { BloomEffect } from "laya/d3/core/render/BloomEffect" ; import { Scene3D } from "laya/d3/core/scene/Scene3D" ; import { Color } from "laya/d3/math/Color" ; import { Stage } from "laya/display/Stage" ; import { Event } from "laya/events/Event" ; import { Texture2D } from "laya/resource/Texture2D" ; import { Button } from "laya/ui/Button" ; import { Browser } from "laya/utils/Browser" ; import { Handler } from "laya/utils/Handler" ; import { Stat } from "laya/utils/Stat" ; import { Utils } from "laya/utils/Utils" ; import { Laya3D } from "Laya3D" ; import Client from "../../Client" ; import { CameraMoveScript } from "../common/CameraMoveScript" ; export class PostProcessBloom { camera : Camera = null ; /**实例类型*/ private btype : any = "PostProcessBloom" ; /**场景内按钮类型*/ private stype : any = 0 ; private button : Button ; private constructor ( ) { Laya3D . init ( 0 , 0 ) ; Stat . show ( ) ; Laya . stage . scaleMode = Stage . SCALE_FULL ; Laya . stage . screenMode = Stage . SCREEN_NONE ; Scene3D . load ( "res/threeDimen/scene/LayaScene_BloomScene/Conventional/BloomScene.ls" , Handler . create ( this , function ( scene ) : void { Laya . stage . addChild ( scene ) ; this . camera = < Camera > ( scene . getChildByName ( "Main Camera" ) as any ) ; this . camera . addComponent ( CameraMoveScript ) ; var postProcess = new PostProcess ( ) ; var bloom = new BloomEffect ( ) ; postProcess . addEffect ( bloom ) ; this . camera . postProcess = postProcess ; this . camera . enableHDR = true ; bloom . intensity = 5 ; bloom . threshold = 0.9 ; bloom . softKnee = 0.5 ; bloom . clamp = 65472 ; bloom . diffusion = 5 ; bloom . anamorphicRatio = 0.0 ; bloom . color = new Color ( 1 , 1 , 1 , 1 ) ; bloom . fastMode = true ; Texture2D . load ( "res/threeDimen/scene/LayaScene_BloomScene/Conventional/Assets/LensDirt01.png" , Handler . create ( null , function ( tex ) : void { bloom . dirtTexture = tex ; bloom . dirtIntensity = 2.0 ; } ) ) ; this . loadUI ( ) ; } ) ) ; } private loadUI ( ) { Laya . loader . load ( [ "res/threeDimen/ui/button.png" ] , Handler . create ( this , function ( ) : void { this . button = Laya . stage . addChild ( new Button ( "res/threeDimen/ui/button.png" , "关闭HDR" ) ) ; this . button . size ( 200 , 40 ) ; this . button . labelBold = true ; this . button . labelSize = 30 ; this . button . sizeGrid = "4,4,4,4" ; this . button . scale ( Browser . pixelRatio , Browser . pixelRatio ) ; this . button . pos ( Laya . stage . width / 2 - this . button . width * Browser . pixelRatio / 2 , Laya . stage . height - 60 * Browser . pixelRatio ) ; this . button . on ( Event . CLICK , this , this . stypeFun0 ) ; } ) ) ; } stypeFun0 ( label = "关闭HDR" ) { var enableHDR = this . camera . enableHDR ; if ( enableHDR ) { this . button . label = "开启HDR" ; } else { this . button . label = "关闭HDR" ; } this . camera . enableHDR = ! enableHDR ; label = this . button . label ; Client . instance . send ( { type : "next" , btype : this . btype , stype : 0 , value : label } ) ; } }