Project

General

Profile

« Previous | Next » 

Revision 638b5b5c

Added by Leszek Koltunski over 7 years ago

More MIPMAP work.

View differences:

src/main/java/org/distorted/library/DistortedEffects.java
293 293
    mF.compute(currTime);
294 294

  
295 295
    float halfZ = halfW*mesh.zFactor;
296
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight);
296

  
297
    float mipmap = 1.0f;//surface.mMipmap;
298
    GLES30.glViewport(0, 0, (int)(mipmap*surface.mWidth), (int)(mipmap*surface.mHeight) );
299
    //GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight);
297 300

  
298 301
    mMainProgram.useProgram();
299 302
    GLES30.glUniform1i(mMainTextureH, 0);
300 303
    surface.setAsOutput(currTime);
301 304
    mM.send(surface,halfW,halfH,halfZ);
305
    mM.send(surface,halfW,halfH,halfZ);
302 306
    mV.send(halfW,halfH,halfZ);
303 307
    mF.send(halfW,halfH);
304 308
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
......
317 321
    {
318 322
    mBlitProgram.useProgram();
319 323

  
320
    GLES30.glViewport(0, 0, projection.mWidth, projection.mHeight);
324
    float mipmap = 1.0f;//projection.mMipmap;
325
    GLES30.glViewport(0, 0, (int)(mipmap*projection.mWidth), (int)(mipmap*projection.mHeight) );
321 326
    GLES30.glUniform1i(mBlitTextureH, 0);
322 327
    GLES30.glUniform1f( mBlitDepthH , 1.0f-projection.mNear);
323 328
    GLES30.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
src/main/java/org/distorted/library/DistortedFramebuffer.java
225 225
    {
226 226
    return mColorH[0];
227 227
    }
228

  
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230
/**
231
 * Set mipmap level.
232
 * <p>
233
 * Trick for speeding up your renders - one can create a pyramid of DistortedFramebuffer objects,
234
 * each next one some constant FACTOR smaller than the previous (0.5 is the common value), then set
235
 * the Mipmap Level of the i-th object to be FACTOR^i (we start counting from 0). When rendering any
236
 * scene into such prepared Framebuffer, the library will make sure to scale any Effects used so that
237
 * the end scene will end up looking identical no matter which object we render to. Identical, that
238
 * is, except for the loss of quality and gain in speed associated with rendering to a smaller surface.
239
 *
240
 * @param mipmap The mipmap level. Acceptable range: 0&lt;mipmap&lt;infinity, although mipmap&gt;1
241
 *               does not make any sense (that would result in loss of speed and no gain in quality)
242
 */
243
  public void setMipmap(float mipmap)
244
    {
245
    mMipmap = mipmap;
246
    }
247 228
  }
src/main/java/org/distorted/library/DistortedOutputSurface.java
28 28
abstract class DistortedOutputSurface extends DistortedSurface implements DistortedSlave
29 29
{
30 30
  private static final int NUM_MIPMAP = 4;
31
          static final int CUR_MIPMAP = 0;
31
          static final int CUR_MIPMAP = 1;
32 32

  
33 33
  private static final int ATTACH = 0;
34 34
  private static final int DETACH = 1;
......
101 101

  
102 102
    mBuffer1 = new DistortedFramebuffer[NUM_MIPMAP];
103 103
    mBuffer2 = new DistortedFramebuffer[NUM_MIPMAP];
104
    mMipmap = 1.0f;
104

  
105
    mMipmap = (this instanceof DistortedScreen ? 0.5f : 1.0f);
105 106

  
106 107
    createProjection();
107 108
    }
......
112 113
    {
113 114
    if( mWidth>0 && mHeight>1 )
114 115
      {
116
      float mw = mWidth;//mMipmap*mWidth;
117
      float mh = mHeight;//mMipmap*mHeight;
118

  
115 119
      if( mFOV>0.0f )  // perspective projection
116 120
        {
117 121
        float a = 2.0f*(float)Math.tan(mFOV*Math.PI/360);
118
        float q = mWidth*mNear;
119
        float c = mHeight*mNear;
122
        float q = mw*mNear;
123
        float c = mh*mNear;
120 124

  
121 125
        float left   = -q/2;
122 126
        float right  = +q/2;
......
124 128
        float top    = +c/2;
125 129
        float near   =  c/a;
126 130

  
127
        mDistance    = mHeight/a;
131
        mDistance    = mh/a;
128 132
        float far    = 2*mDistance-near;
129 133

  
130 134
        Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
131 135
        }
132 136
      else             // parallel projection
133 137
        {
134
        float left   = -mWidth /2.0f;
135
        float right  = +mWidth /2.0f;
136
        float bottom = -mHeight/2.0f;
137
        float top    = +mHeight/2.0f;
138
        float near   = mWidth+mHeight-mHeight*(1.0f-mNear);
139
        mDistance    = mWidth+mHeight;
140
        float far    = mWidth+mHeight+mHeight*(1.0f-mNear);
138
        float left   = -mw/2.0f;
139
        float right  = +mw/2.0f;
140
        float bottom = -mh/2.0f;
141
        float top    = +mh/2.0f;
142
        float near   = mw+mh-mh*(1.0f-mNear);
143
        mDistance    = mw+mh;
144
        float far    = mw+mh+mh*(1.0f-mNear);
141 145

  
142 146
        Matrix.orthoM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
143 147
        }
......
302 306
      }
303 307
    }
304 308

  
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310
/**
311
 * Set mipmap level.
312
 * <p>
313
 * Trick for speeding up your renders - one can create a pyramid of OutputSurface objects, each next
314
 * one some constant FACTOR smaller than the previous (0.5 is the common value), then set the Mipmap
315
 * Level of the i-th object to be FACTOR^i (we start counting from 0). When rendering any scene into
316
 * such prepared OutputSurface, the library will make sure to scale any Effects used so that the end
317
 * scene will end up looking identical no matter which object we render to. Identical, that is, except
318
 * for the loss of quality and gain in speed associated with rendering to a smaller Surface.
319
 *
320
 * @param mipmap The mipmap level. Acceptable range: 0&lt;mipmap&lt;infinity, although mipmap&gt;1
321
 *               does not make any sense (that would result in loss of speed and no gain in quality)
322
 */
323
  public void setMipmap(float mipmap)
324
    {
325
    mMipmap = mipmap;
326
    createProjection();
327
    }
328

  
305 329
///////////////////////////////////////////////////////////////////////////////////////////////////
306 330
/**
307 331
 * Set the (R,G,B,A) values of GLES30.glClearColor() to set up color with which to clear
src/main/java/org/distorted/library/EffectQueueMatrix.java
114 114
    float x,y,z, sx,sy,sz;
115 115
    float mipmap = projection.mMipmap;
116 116

  
117
    if( mipmap!=1 ) Matrix.scaleM(mViewMatrix, 0, mipmap, mipmap, mipmap);
118

  
117 119
    for(int i=0; i<mNumEffects; i++)
118 120
      {
119 121
      if (mName[i] == EffectNames.ROTATE.ordinal() )
120 122
        {
121
        x = mUniforms[NUM_UNIFORMS*i+4]*mipmap;
122
        y = mUniforms[NUM_UNIFORMS*i+5]*mipmap;
123
        z = mUniforms[NUM_UNIFORMS*i+6]*mipmap;
123
        x = mUniforms[NUM_UNIFORMS*i+4];
124
        y = mUniforms[NUM_UNIFORMS*i+5];
125
        z = mUniforms[NUM_UNIFORMS*i+6];
124 126

  
125 127
        Matrix.translateM(mViewMatrix, 0, x,-y, z);
126 128
        Matrix.rotateM( mViewMatrix, 0, mUniforms[NUM_UNIFORMS*i], mUniforms[NUM_UNIFORMS*i+1], mUniforms[NUM_UNIFORMS*i+2], mUniforms[NUM_UNIFORMS*i+3]);
......
128 130
        }
129 131
      else if(mName[i] == EffectNames.QUATERNION.ordinal() )
130 132
        {
131
        x = mUniforms[NUM_UNIFORMS*i+4]*mipmap;
132
        y = mUniforms[NUM_UNIFORMS*i+5]*mipmap;
133
        z = mUniforms[NUM_UNIFORMS*i+6]*mipmap;
133
        x = mUniforms[NUM_UNIFORMS*i+4];
134
        y = mUniforms[NUM_UNIFORMS*i+5];
135
        z = mUniforms[NUM_UNIFORMS*i+6];
134 136

  
135 137
        Matrix.translateM(mViewMatrix, 0, x,-y, z);
136 138
        multiplyByQuat(mViewMatrix, mUniforms[NUM_UNIFORMS*i], mUniforms[NUM_UNIFORMS*i+1], mUniforms[NUM_UNIFORMS*i+2], mUniforms[NUM_UNIFORMS*i+3]);
......
138 140
        }
139 141
      else if(mName[i] == EffectNames.MOVE.ordinal() )
140 142
        {
141
        sx = mUniforms[NUM_UNIFORMS*i  ]*mipmap;
142
        sy = mUniforms[NUM_UNIFORMS*i+1]*mipmap;
143
        sz = mUniforms[NUM_UNIFORMS*i+2]*mipmap;
143
        sx = mUniforms[NUM_UNIFORMS*i  ];
144
        sy = mUniforms[NUM_UNIFORMS*i+1];
145
        sz = mUniforms[NUM_UNIFORMS*i+2];
144 146

  
145 147
        Matrix.translateM(mViewMatrix, 0, sx,-sy, sz);
146 148
        }
147 149
      else if(mName[i] == EffectNames.SCALE.ordinal() )
148 150
        {
149
        sx = mUniforms[NUM_UNIFORMS*i  ]*mipmap;
150
        sy = mUniforms[NUM_UNIFORMS*i+1]*mipmap;
151
        sz = mUniforms[NUM_UNIFORMS*i+2]*mipmap;
151
        sx = mUniforms[NUM_UNIFORMS*i  ];
152
        sy = mUniforms[NUM_UNIFORMS*i+1];
153
        sz = mUniforms[NUM_UNIFORMS*i+2];
152 154

  
153 155
        Matrix.scaleM(mViewMatrix, 0, sx, sy, sz);
154 156
        }
......
158 160
        sy = mUniforms[NUM_UNIFORMS*i+1];
159 161
        sz = mUniforms[NUM_UNIFORMS*i+2];
160 162

  
161
        x  = mUniforms[NUM_UNIFORMS*i+4]*mipmap;
162
        y  = mUniforms[NUM_UNIFORMS*i+5]*mipmap;
163
        z  = mUniforms[NUM_UNIFORMS*i+6]*mipmap;
163
        x  = mUniforms[NUM_UNIFORMS*i+4];
164
        y  = mUniforms[NUM_UNIFORMS*i+5];
165
        z  = mUniforms[NUM_UNIFORMS*i+6];
164 166

  
165 167
        Matrix.translateM(mViewMatrix, 0, x,-y, z);
166 168

  

Also available in: Unified diff