Project

General

Profile

« Previous | Next » 

Revision bb4755e2

Added by Leszek Koltunski almost 4 years ago

Change the Postprocessing effects: separate the radius and the halo.
Reason: we needed a way to specify the size of the halo around a postprocessed object; before it was automatically (and not very correctly) computed from the radius - before we knew the size of the object's bounding box, so this automatic computation was possible. Now we're removing the MashBase.getBounding(0 API, so the size of the halo has to be explicitly given by the user. This way is more correct anyway and gives the user more control (as the Multiblur app proves!)

Warning: here for the first time I can see that the 2 Examples (PostprocessingTree and MovingGlow) sometimes would not appear (black screen). Maybe this commit introduces such a bug - investigate.

View differences:

src/main/java/org/distorted/library/effect/PostprocessEffectBlur.java
24 24
import org.distorted.library.main.DistortedFramebuffer;
25 25
import org.distorted.library.main.InternalRenderState;
26 26
import org.distorted.library.program.DistortedProgram;
27
import org.distorted.library.type.Data1D;
27
import org.distorted.library.type.Data2D;
28 28

  
29 29
///////////////////////////////////////////////////////////////////////////////////////////////////
30 30
/**
......
32 32
 */
33 33
public class PostprocessEffectBlur extends PostprocessEffect
34 34
  {
35
  private static final int MAX_HALO = 50;
35
  private static final int MAX_RADIUS = 50;
36 36

  
37
  private Data1D mBlurRadius;
37
  private Data2D mBlurHaloAndRadius;
38 38

  
39 39
  private static final float[] GAUSSIAN =   // G(0.00), G(0.03), G(0.06), ..., G(3.00), 0
40 40
    {                                       // where G(x)= (1/(sqrt(2*PI))) * e^(-(x^2)/2). The last 0 terminates.
......
56 56
  // i.e. k(i)=floor((i+3)/2).  (the 'i' in k(i) means 'blur taking into account the present pixel and 'i' pixels
57 57
  // in all 4 directions)
58 58
  // We need room for MAX_BLUR of them, and sum(i=0...N, floor((i+3)/2)) = N + floor(N*N/4)
59
  private static float[] weightsCache = new float[MAX_HALO + MAX_HALO*MAX_HALO/4];
60
  private static float[] offsetsCache = new float[MAX_HALO + MAX_HALO*MAX_HALO/4];
61
  private static float[] mWeights = new float[MAX_HALO];
62
  private static float[] mOffsets = new float[MAX_HALO];
59
  private static float[] weightsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
60
  private static float[] offsetsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
61
  private static float[] mWeights = new float[MAX_RADIUS];
62
  private static float[] mOffsets = new float[MAX_RADIUS];
63 63

  
64 64
  private static DistortedProgram mProgram1, mProgram2;
65 65
  private static int mIndex1, mIndex2;
......
133 133
 */
134 134
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
135 135
    {
136
    return mBlurRadius.get(uniforms,index,currentDuration,step);
136
    return mBlurHaloAndRadius.get(uniforms,index,currentDuration,step);
137 137
    }
138 138

  
139 139
///////////////////////////////////////////////////////////////////////////////////////////////////
......
181 181
    float offsetCorrW = corrW/w;
182 182
    float offsetCorrH = corrH/h;
183 183

  
184
    int radius = (int)(uniforms[index]*mQualityScale);
185
    if( radius>=MAX_HALO ) radius = MAX_HALO-1;
184
    int radius = (int)(uniforms[index+1]*mQualityScale);
185
    if( radius>=MAX_RADIUS ) radius = MAX_RADIUS-1;
186 186
    computeGaussianKernel(radius);
187 187

  
188 188
    int offset = radius + radius*radius/4;
......
259 259

  
260 260
    final String blurFragment1 =
261 261

  
262
      "#define MAX_BLUR "+MAX_HALO+      "\n"+
262
      "#define MAX_BLUR "+MAX_RADIUS+    "\n"+
263 263
      "precision lowp float;              \n"+
264 264
      "in vec2 v_TexCoord;                \n"+
265 265
      "out vec4 fragColor;                \n"+
......
281 281

  
282 282
    final String blurFragment2 =
283 283

  
284
      "#define MAX_BLUR "+MAX_HALO+      "\n"+
284
      "#define MAX_BLUR "+MAX_RADIUS+    "\n"+
285 285
      "precision lowp float;              \n"+
286 286
      "in vec2 v_TexCoord;                \n"+
287 287
      "out vec4 fragColor;                \n"+
......
309 309
/**
310 310
 * Blur the Framebuffer.
311 311
 *
312
 * @param blurRadius The 'strength' of the effect, in pixels. 0 = no blur, 10 = when blurring a given pixel,
313
 *                   take into account 10 pixels in each direction.
312
 * @param blurHaloAndRadius First float: the halo.
313
 *                          How far beyond the object does the effect stretch to? Unit: Percentage
314
 *                          of the size of the original object, i.e. Halo=0 --> no halo around, this
315
 *                          would mean sharp edges around the object; Halo=100 --> halo of the size
316
 *                          of the object itself around (in case of blur, this would be - in vast
317
 *                          majority of cases except an object rendered very closely to the near plane-
318
 *                          an overkill).
319
 *                          Second float: the radius.
320
 *                          The 'strength' if the blur of the edges, in pixels. 0 = no blur, 10 =
321
 *                          blur of roughly 10 pixels around the whole halo.
322

  
314 323
 */
315
  public PostprocessEffectBlur(Data1D blurRadius)
324
  public PostprocessEffectBlur(Data2D blurHaloAndRadius)
316 325
    {
317 326
    super(EffectName.BLUR);
318
    mBlurRadius = blurRadius;
327
    mBlurHaloAndRadius = blurHaloAndRadius;
319 328
    }
320 329
  }

Also available in: Unified diff