Преглед изворни кода

Merge pull request #3358 from PixelsCommander/master

#3277 Implements threshold for HighlightLayer introducing threshold p…
sebavan пре 7 година
родитељ
комит
d6c6cfdb07
2 измењених фајлова са 14 додато и 2 уклоњено
  1. 8 2
      src/Layer/babylon.highlightlayer.ts
  2. 6 0
      src/Shaders/glowMapMerge.fragment.fx

+ 8 - 2
src/Layer/babylon.highlightlayer.ts

@@ -6,7 +6,7 @@
     class GlowBlurPostProcess extends PostProcess {
     class GlowBlurPostProcess extends PostProcess {
         constructor(name: string, public direction: Vector2, public kernel: number, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean) {
         constructor(name: string, public direction: Vector2, public kernel: number, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode: number = Texture.BILINEAR_SAMPLINGMODE, engine?: Engine, reusable?: boolean) {
             super(name, "glowBlurPostProcess", ["screenSize", "direction", "blurWidth"], null, options, camera, samplingMode, engine, reusable);
             super(name, "glowBlurPostProcess", ["screenSize", "direction", "blurWidth"], null, options, camera, samplingMode, engine, reusable);
-
+            
             this.onApplyObservable.add((effect: Effect) => {
             this.onApplyObservable.add((effect: Effect) => {
                 effect.setFloat2("screenSize", this.width, this.height);
                 effect.setFloat2("screenSize", this.width, this.height);
                 effect.setVector2("direction", this.direction);
                 effect.setVector2("direction", this.direction);
@@ -56,6 +56,11 @@
          * The camera attached to the layer.
          * The camera attached to the layer.
          */
          */
         camera: Nullable<Camera>;
         camera: Nullable<Camera>;
+
+        /**
+         * Should we display highlight as a solid stroke?
+         */
+        isStroke?: boolean;
     }
     }
 
 
     /**
     /**
@@ -289,7 +294,8 @@
             this._glowMapMergeEffect = engine.createEffect("glowMapMerge",
             this._glowMapMergeEffect = engine.createEffect("glowMapMerge",
                 [VertexBuffer.PositionKind],
                 [VertexBuffer.PositionKind],
                 ["offset"],
                 ["offset"],
-                ["textureSampler"], "");
+                ["textureSampler"],
+                this._options.isStroke ? "#define STROKE \n" : undefined);
 
 
             // Render target
             // Render target
             this.setMainTextureSize();
             this.setMainTextureSize();

+ 6 - 0
src/Shaders/glowMapMerge.fragment.fx

@@ -10,5 +10,11 @@ void main(void) {
 
 
 	baseColor.a = abs(offset - baseColor.a);
 	baseColor.a = abs(offset - baseColor.a);
 
 
+	#ifdef STROKE
+        float alpha = smoothstep(.0, .1, baseColor.a);
+        baseColor.a = alpha;
+        baseColor.rgb = baseColor.rgb * alpha;
+    #endif
+
 	gl_FragColor = baseColor;
 	gl_FragColor = baseColor;
 }
 }