Trevor Baron 7 years ago
parent
commit
93bdd23a55

+ 6 - 0
src/PostProcess/RenderPipeline/Pipelines/babylon.defaultRenderingPipeline.ts

@@ -17,6 +17,9 @@
         public blurX: BlurPostProcess;
         public blurY: BlurPostProcess;
         public copyBack: PassPostProcess;
+        /**
+         * Depth of field effect, applies a blur based on how far away objects are from the focus distance.
+         */
         public depthOfField: DepthOfFieldEffect;
         public fxaa: FxaaPostProcess;
         public imageProcessing: ImageProcessingPostProcess;
@@ -94,6 +97,9 @@
             return this._bloomEnabled;
         }
 
+        /**
+         * If the depth of field is enabled.
+         */
         @serialize()
         public get depthOfFieldEnabled(): boolean {
             return this._depthOfFieldEnabled;

+ 30 - 4
src/PostProcess/babylon.circleOfConfusionPostProcess.ts

@@ -1,10 +1,36 @@
 module BABYLON {
+    /**
+     * The CircleOfConfusionPostProcess computes the circle of confusion value for each pixel given required lens parameters. See https://en.wikipedia.org/wiki/Circle_of_confusion
+     */
     export class CircleOfConfusionPostProcess extends PostProcess {
-        lensSize = 50 // in scene units/1000 (eg. millimeter)
-        fStop = 1.4; // Aperture = lensSize/fStop
-        focusDistance = 2000; // in scene units/1000 (eg. millimeter)
-        focalLength = 50; // in scene units/1000 (eg. millimeter)
+        /**
+         * Max lens size in scene units/1000 (eg. millimeter). Standard cameras are 50mm. (default: 50) The diamater of the resulting aperture can be computed by lensSize/fStop.
+         */
+        lensSize = 50
+        /**
+         * F-Stop of the effect's camera. The diamater of the resulting aperture can be computed by lensSize/fStop. (default: 1.4)
+         */
+        fStop = 1.4;
+        /**
+         * Distance away from the camera to focus on in scene units/1000 (eg. millimeter). (default: 2000)
+         */
+        focusDistance = 2000;
+        /**
+         * Focal length of the effect's camera in scene units/1000 (eg. millimeter). (default: 50)
+         */
+        focalLength = 50;
         
+        /**
+         * Creates a new instance of @see CircleOfConfusionPostProcess
+         * @param name The name of the effect.
+         * @param depthTexture The depth texture of the scene to compute the circle of confusion.
+         * @param options The required width/height ratio to downsize to before computing the render pass.
+         * @param camera The camera to apply the render pass to.
+         * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
+         * @param engine The engine which the post process will be applied. (default: current engine)
+         * @param reusable If the post process can be reused on the same frame. (default: false)
+         * @param textureType Type of textures used when performing the post process. (default: 0)
+         */
         constructor(name: string, depthTexture: RenderTargetTexture, options: number | PostProcessOptions, camera: Camera, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
             super(name, "circleOfConfusion", ["cameraMinMaxZ", "focusDistance", "cocPrecalculation"], ["depthSampler"], options, camera, samplingMode, engine, reusable, null, textureType);
             this.onApplyObservable.add((effect: Effect) => {

+ 20 - 0
src/PostProcess/babylon.depthOfFieldBlurPostProcess.ts

@@ -1,5 +1,25 @@
 module BABYLON {    
+    /**
+     * The DepthOfFieldBlurPostProcess applied a blur in a give direction.
+     * This blur differs from the standard BlurPostProcess as it attempts to avoid blurring pixels 
+     * based on samples that have a large difference in distance than the center pixel.
+     * See section 2.6.2 http://fileadmin.cs.lth.se/cs/education/edan35/lectures/12dof.pdf
+     */
     export class DepthOfFieldBlurPostProcess extends BlurPostProcess {
+        /**
+         * Creates a new instance of @see CircleOfConfusionPostProcess
+         * @param name The name of the effect.
+         * @param direction The direction the blur should be applied.
+         * @param kernel The size of the kernel used to blur.
+         * @param options The required width/height ratio to downsize to before computing the render pass.
+         * @param camera The camera to apply the render pass to.
+         * @param depthMap The depth map to be used to avoid blurring accross edges
+         * @param imageToBlur The image to apply the blur to (default: Current rendered frame)
+         * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
+         * @param engine The engine which the post process will be applied. (default: current engine)
+         * @param reusable If the post process can be reused on the same frame. (default: false)
+         * @param textureType Type of textures used when performing the post process. (default: 0)
+         */
         constructor(name: string, public direction: Vector2, kernel: number, options: number | PostProcessOptions, camera: Camera, depthMap:RenderTargetTexture, imageToBlur:Nullable<PostProcess> = null, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
             // TODO: passing in camera here unexpectedly causes the 1 frame behind issue and forces me to make the calling of this reusable.
             super(name, direction, kernel, options, null, samplingMode = Texture.BILINEAR_SAMPLINGMODE, engine, reusable, textureType = Engine.TEXTURETYPE_UNSIGNED_INT)

+ 30 - 0
src/PostProcess/babylon.depthOfFieldEffect.ts

@@ -1,5 +1,9 @@
 module BABYLON {
+    
     //TODO is there something this class should extend?. I dont think this fits as a postprocess or pipeline.
+    /**
+     * The depth of field effect applies a blur to objects that are closer or further from where the camera is focusing.
+     */
     export class DepthOfFieldEffect {
         private readonly DepthOfFieldPassPostProcessId: string = "DepthOfFieldPassPostProcessId";
         private readonly CircleOfConfusionPostProcessId: string = "CircleOfConfusionPostProcessEffect"; 
@@ -13,6 +17,9 @@ module BABYLON {
         private depthOfFieldBlurY: DepthOfFieldBlurPostProcess;
         private depthOfFieldMerge: DepthOfFieldMergePostProcess;
 
+        /**
+         * The size of the kernel to be used for the blur
+         */
         public set kernelSize(value: number){
             this.depthOfFieldBlurX.kernel = value;
             this.depthOfFieldBlurY.kernel = value;
@@ -20,24 +27,36 @@ module BABYLON {
         public get kernelSize(){
             return this.depthOfFieldBlurX.kernel;
         }
+        /**
+         * The focal the length of the camera used in the effect
+         */
         public set focalLength(value: number){
             this.circleOfConfusion.focalLength = value;
         }
         public get focalLength(){
             return this.circleOfConfusion.focalLength;
         }
+        /**
+         * F-Stop of the effect's camera. The diamater of the resulting aperture can be computed by lensSize/fStop. (default: 1.4)
+         */
         public set fStop(value: number){
             this.circleOfConfusion.fStop = value;
         }
         public get fStop(){
             return this.circleOfConfusion.fStop;
         }
+        /**
+         * Distance away from the camera to focus on in scene units/1000 (eg. millimeter). (default: 2000)
+         */
         public set focusDistance(value: number){
             this.circleOfConfusion.focusDistance = value;
         }
         public get focusDistance(){
             return this.circleOfConfusion.focusDistance;
         }
+        /**
+         * Max lens size in scene units/1000 (eg. millimeter). Standard cameras are 50mm. (default: 50) The diamater of the resulting aperture can be computed by lensSize/fStop.
+         */
         public set lensSize(value: number){
             this.circleOfConfusion.lensSize = value;
         }
@@ -45,6 +64,13 @@ module BABYLON {
             return this.circleOfConfusion.lensSize;
         }
 
+        /**
+         * Creates a new instance of @see DepthOfFieldEffect
+         * @param pipeline The pipeline to add the depth of field effect to.
+         * @param scene The scene the effect belongs to.
+         * @param camera The camera to apply the depth of field on.
+         * @param pipelineTextureType The type of texture to be used when performing the post processing.
+         */
         constructor(pipeline: PostProcessRenderPipeline, scene: Scene, camera:Camera, pipelineTextureType = 0) {
             // Enable and get current depth map
             var depthMap = scene.enableDepthRenderer().getDepthMap();
@@ -68,6 +94,10 @@ module BABYLON {
             pipeline.addEffect(new PostProcessRenderEffect(scene.getEngine(), this.DepthOfFieldMergePostProcessId, () => { return this.depthOfFieldMerge; }, true));
         }
 
+        /**
+         * Disposes each of the internal effects for a given camera.
+         * @param camera The camera to dispose the effect on.
+         */
         public disposeEffects(camera:Camera){
             this.depthOfFieldPass.dispose(camera);
             this.circleOfConfusion.dispose(camera);

+ 15 - 0
src/PostProcess/babylon.depthOfFieldMergePostProcess.ts

@@ -1,5 +1,20 @@
 module BABYLON {
+    /**
+     * The DepthOfFieldMergePostProcess merges blurred images with the original based on the values of the circle of confusion.
+     */
     export class DepthOfFieldMergePostProcess extends PostProcess {
+        /**
+         * Creates a new instance of @see CircleOfConfusionPostProcess
+         * @param name The name of the effect.
+         * @param original The non-blurred image to be modified
+         * @param circleOfConfusion The circle of confusion post process that will determine how blurred each pixel should become.
+         * @param options The required width/height ratio to downsize to before computing the render pass.
+         * @param camera The camera to apply the render pass to.
+         * @param samplingMode The sampling mode to be used when computing the pass. (default: 0)
+         * @param engine The engine which the post process will be applied. (default: current engine)
+         * @param reusable If the post process can be reused on the same frame. (default: false)
+         * @param textureType Type of textures used when performing the post process. (default: 0)
+         */
         constructor(name: string, original: PostProcess, circleOfConfusion: PostProcess, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
             super(name, "depthOfFieldMerge", [], ["circleOfConfusionSampler", "originalSampler"], options, camera, samplingMode, engine, reusable, null, textureType);
             this.onApplyObservable.add((effect: Effect) => {