فهرست منبع

color slider for sharpness effect

Trevor Baron 7 سال پیش
والد
کامیت
d36265b9ae
2فایلهای تغییر یافته به همراه9 افزوده شده و 5 حذف شده
  1. 7 3
      src/PostProcess/babylon.sharpenPostProcess.ts
  2. 2 2
      src/Shaders/sharpen.fragment.fx

+ 7 - 3
src/PostProcess/babylon.sharpenPostProcess.ts

@@ -5,9 +5,13 @@ module BABYLON {
      */
     export class SharpenPostProcess extends PostProcess{
         /**
+         * How much of the original color should be applied. Setting this to 0 will display edge detection. (default: 1)
+         */
+        public colorAmount:number = 1.0;
+        /**
          * How much sharpness should be applied (default: 0.3)
          */
-        public amount:number = 0.3;
+        public edgeAmount:number = 0.3;
         /**
          * Creates a new instance of @see ConvolutionPostProcess
          * @param name The name of the effect.
@@ -19,11 +23,11 @@ module BABYLON {
          * @param textureType Type of textures used when performing the post process. (default: 0)
          */
         constructor(name: string, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, engine?: Engine, reusable?: boolean, textureType: number = Engine.TEXTURETYPE_UNSIGNED_INT) {
-            super(name, "sharpen", ["amount", "screenSize"], null, options, camera, samplingMode, engine, reusable, null, textureType);
+            super(name, "sharpen", ["sharpnessAmounts", "screenSize"], null, options, camera, samplingMode, engine, reusable, null, textureType);
 
             this.onApply = (effect: Effect) => {
                 effect.setFloat2("screenSize", this.width, this.height);
-                effect.setFloat("amount", this.amount);
+                effect.setFloat2("sharpnessAmounts", this.edgeAmount, this.colorAmount);
             };
         }
     }

+ 2 - 2
src/Shaders/sharpen.fragment.fx

@@ -2,7 +2,7 @@
 varying vec2 vUV;
 uniform sampler2D textureSampler;
 uniform vec2 screenSize;
-uniform float amount;
+uniform vec2 sharpnessAmounts;
 
 void main(void)
 {
@@ -14,5 +14,5 @@ void main(void)
 		texture2D(textureSampler, vUV + onePixel * vec2(0, 1)) -
         color * 4.0;
 	
-	gl_FragColor = max(color - (amount * vec4(edgeDetection.rgb, 0)), 0.);
+	gl_FragColor = max(vec4(color.rgb * sharpnessAmounts.y, color.a) - (sharpnessAmounts.x * vec4(edgeDetection.rgb, 0)), 0.);
 }