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/PostprocessEffectGlow.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
import org.distorted.library.type.Data4D;
29 29

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

  
38
  private Data1D mGlowRadius;
38
  private Data2D mGlowHaloAndRadius;
39 39
  private Data4D mColor;
40 40

  
41 41
  private static final float[] GAUSSIAN =   // G(0.00), G(0.03), G(0.06), ..., G(3.00), 0
......
58 58
  // i.e. k(i)=floor((i+3)/2).  (the 'i' in k(i) means 'blur taking into account the present pixel and 'i' pixels
59 59
  // in all 4 directions)
60 60
  // We need room for MAX_BLUR of them, and sum(i=0...N, floor((i+3)/2)) = N + floor(N*N/4)
61
  private static float[] weightsCache = new float[MAX_HALO + MAX_HALO*MAX_HALO/4];
62
  private static float[] offsetsCache = new float[MAX_HALO + MAX_HALO*MAX_HALO/4];
63
  private static float[] mWeights = new float[MAX_HALO];
64
  private static float[] mOffsets = new float[MAX_HALO];
61
  private static float[] weightsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
62
  private static float[] offsetsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
63
  private static float[] mWeights = new float[MAX_RADIUS];
64
  private static float[] mOffsets = new float[MAX_RADIUS];
65 65

  
66 66
  private static DistortedProgram mProgram1, mProgram2;
67 67
  private static int mIndex1, mIndex2;
......
135 135
 */
136 136
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
137 137
    {
138
    mColor.get(uniforms,index+1,currentDuration,step);
139
    return mGlowRadius.get(uniforms,index,currentDuration,step);
138
    mColor.get(uniforms,index+2,currentDuration,step);
139
    return mGlowHaloAndRadius.get(uniforms,index,currentDuration,step);
140 140
    }
141 141

  
142 142
///////////////////////////////////////////////////////////////////////////////////////////////////
......
184 184
    float offsetCorrW = corrW/w;
185 185
    float offsetCorrH = corrH/h;
186 186

  
187
    int radius = (int)(uniforms[index]*mQualityScale);
188
    if( radius>=MAX_HALO ) radius = MAX_HALO-1;
187
    int radius = (int)(uniforms[index+1]*mQualityScale);
188
    if( radius>=MAX_RADIUS ) radius = MAX_RADIUS-1;
189 189
    computeGaussianKernel(radius);
190 190

  
191 191
    int offset = radius + radius*radius/4;
......
262 262

  
263 263
    final String glowFragment1 =
264 264

  
265
            "#define MAX_BLUR "+MAX_HALO+      "\n"+
265
            "#define MAX_BLUR "+MAX_RADIUS+    "\n"+
266 266
            "precision lowp float;              \n"+
267 267
            "in vec2 v_TexCoord;                \n"+
268 268
            "out vec4 fragColor;                \n"+
......
284 284

  
285 285
    final String glowFragment2 =
286 286

  
287
            "#define MAX_BLUR "+MAX_HALO+      "\n"+
287
            "#define MAX_BLUR "+MAX_RADIUS+    "\n"+
288 288
            "precision lowp float;              \n"+
289 289
            "in vec2 v_TexCoord;                \n"+
290 290
            "out vec4 fragColor;                \n"+
......
309 309
    }
310 310

  
311 311
///////////////////////////////////////////////////////////////////////////////////////////////////
312

  
313 312
/**
314 313
 * Make the object glow with a specific color and a halo of specific radius.
315 314
 *
316
 * @param glowRadius The 'strength' if the effect, in pixels. 0 = no halo, 10 = halo of roughly 10 pixels
317
 *                   around the whole object.
318
 * @param color      RGBA of the color with which to draw the glow; example: (1.0f,0.0f,0.0f,0.5f) - half transparent red.
315
 * @param glowHaloAndRadius First float: the halo.
316
 *                          How far beyond the object does the effect stretch to? Unit: Percentage
317
 *                          of the size of the original object, i.e. Halo=0 --> no halo around, this
318
 *                          would mean sharp edges around the object; Halo=100 --> halo of the size
319
 *                          of the object itself around.
320
 *                          Second float: the radius.
321
 *                          The 'strength' if the blur of the edges, in pixels. 0 = no blur, 10 =
322
 *                          blur of roughly 10 pixels around the whole halo.
323
 * @param color             RGBA of the color with which to draw the glow; example: (1.0f,0.0f,0.0f,0.5f) -
324
 *                          half transparent red.
319 325
 */
320
  public PostprocessEffectGlow(Data1D glowRadius, Data4D color)
326
  public PostprocessEffectGlow(Data2D glowHaloAndRadius, Data4D color)
321 327
    {
322 328
    super(EffectName.GLOW);
323
    mGlowRadius = glowRadius;
324
    mColor      = color;
329

  
330
    mGlowHaloAndRadius = glowHaloAndRadius;
331
    mColor             = color;
325 332
    }
326 333
  }

Also available in: Unified diff