Project

General

Profile

« Previous | Next » 

Revision faa3ff56

Added by Leszek Koltunski almost 7 years ago

Javadoc.

View differences:

src/main/java/org/distorted/library/effect/PostprocessEffectGlow.java
64 64
  private static int mIndex1, mIndex2;
65 65

  
66 66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
// This implements the 'Better separable implementation using GPU fixed function sampling' from
68
// https://software.intel.com/en-us/blogs/2014/07/15/an-investigation-of-fast-real-time-gpu-based-image-blur-algorithms
67 69

  
68
/**
69
 * Make the object glow with a specific color and a halo of specific radius.
70
 *
71
 * @param glowRadius The 'strength' if the effect, in pixels. 0 = no halo, 10 = halo of roughly 10 pixels
72
 *                   around the whole object.
73
 * @param color      RGBA of the color with which to draw the glow.
74
 */
75
  public PostprocessEffectGlow(Data1D glowRadius, Data4D color)
70
  private void computeGaussianKernel(int radius)
76 71
    {
77
    super(EffectName.GLOW);
78
    mGlowRadius = glowRadius;
79
    mColor      = color;
72
    int offset = radius + radius*radius/4;
73

  
74
    if( weightsCache[offset]==0.0f )
75
      {
76
      float z, x= 0.0f, P= (float)NUM_GAUSSIAN / (radius>3 ? radius:3);
77
      mWeights[0] = GAUSSIAN[0];
78
      float sum   = GAUSSIAN[0];
79
      int j;
80

  
81
      for(int i=1; i<=radius; i++)
82
        {
83
        x += P;
84
        j = (int)x;
85
        z = x-j;
86

  
87
        mWeights[i] = (1-z)*GAUSSIAN[j] + z*GAUSSIAN[j+1];
88
        sum += 2*mWeights[i];
89
        }
90

  
91
      for(int i=0; i<=radius; i++) mWeights[i] /= sum;
92

  
93
      int numloops = radius/2;
94
      weightsCache[offset] = mWeights[0];
95
      offsetsCache[offset] = 0.0f;
96

  
97
      for(int i=0; i<numloops; i++)
98
        {
99
        offsetsCache[offset+i+1] = mWeights[2*i+1]*(2*i+1) + mWeights[2*i+2]*(2*i+2);
100
        weightsCache[offset+i+1] = mWeights[2*i+1] + mWeights[2*i+2];
101
        offsetsCache[offset+i+1]/= weightsCache[offset+i+1];
102
        }
103

  
104
      if( radius%2 == 1 )
105
        {
106
        int index = offset + radius/2 +1;
107
        offsetsCache[index]=radius;
108
        weightsCache[index]=mWeights[radius];
109
        }
110
      }
80 111
    }
81 112

  
82 113
///////////////////////////////////////////////////////////////////////////////////////////////////
83

  
114
/**
115
 * Only for use by the library itself.
116
 *
117
 * @y.exclude
118
 */
84 119
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
85 120
    {
86 121
    mColor.get(uniforms,index+1,currentDuration,step);
......
88 123
    }
89 124

  
90 125
///////////////////////////////////////////////////////////////////////////////////////////////////
91

  
126
/**
127
 * Only for use by the library itself.
128
 *
129
 * @y.exclude
130
 */
92 131
  public int apply(float[] uniforms, int index, float qualityScale, DistortedFramebuffer buffer)
93 132
    {
94 133
    if( mProgram1 ==null)
......
151 190
    }
152 191

  
153 192
///////////////////////////////////////////////////////////////////////////////////////////////////
154

  
193
// PUBLIC API
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195
/**
196
 * Have to call this before the shaders get compiled (i.e before Distorted.onCreate()) for the Effect to work.
197
 */
155 198
  public static void enable()
156 199
    {
157 200
    final String glowVertex =
......
220 263
    }
221 264

  
222 265
///////////////////////////////////////////////////////////////////////////////////////////////////
223
// This implements the 'Better separable implementation using GPU fixed function sampling' from
224
// https://software.intel.com/en-us/blogs/2014/07/15/an-investigation-of-fast-real-time-gpu-based-image-blur-algorithms
225 266

  
226
  private void computeGaussianKernel(int radius)
267
/**
268
 * Make the object glow with a specific color and a halo of specific radius.
269
 *
270
 * @param glowRadius The 'strength' if the effect, in pixels. 0 = no halo, 10 = halo of roughly 10 pixels
271
 *                   around the whole object.
272
 * @param color      RGBA of the color with which to draw the glow.
273
 */
274
  public PostprocessEffectGlow(Data1D glowRadius, Data4D color)
227 275
    {
228
    int offset = radius + radius*radius/4;
229

  
230
    if( weightsCache[offset]==0.0f )
231
      {
232
      float z, x= 0.0f, P= (float)NUM_GAUSSIAN / (radius>3 ? radius:3);
233
      mWeights[0] = GAUSSIAN[0];
234
      float sum   = GAUSSIAN[0];
235
      int j;
236

  
237
      for(int i=1; i<=radius; i++)
238
        {
239
        x += P;
240
        j = (int)x;
241
        z = x-j;
242

  
243
        mWeights[i] = (1-z)*GAUSSIAN[j] + z*GAUSSIAN[j+1];
244
        sum += 2*mWeights[i];
245
        }
246

  
247
      for(int i=0; i<=radius; i++) mWeights[i] /= sum;
248

  
249
      int numloops = radius/2;
250
      weightsCache[offset] = mWeights[0];
251
      offsetsCache[offset] = 0.0f;
252

  
253
      for(int i=0; i<numloops; i++)
254
        {
255
        offsetsCache[offset+i+1] = mWeights[2*i+1]*(2*i+1) + mWeights[2*i+2]*(2*i+2);
256
        weightsCache[offset+i+1] = mWeights[2*i+1] + mWeights[2*i+2];
257
        offsetsCache[offset+i+1]/= weightsCache[offset+i+1];
258
        }
259

  
260
      if( radius%2 == 1 )
261
        {
262
        int index = offset + radius/2 +1;
263
        offsetsCache[index]=radius;
264
        weightsCache[index]=mWeights[radius];
265
        }
266
      }
276
    super(EffectName.GLOW);
277
    mGlowRadius = glowRadius;
278
    mColor      = color;
267 279
    }
268 280
  }

Also available in: Unified diff