Project

General

Profile

« Previous | Next » 

Revision 8e88389e

Added by Leszek Koltunski over 5 years ago

Translate the size of the Halo around postprocessed objects from 'number pixels around the object' (as held in the Effects themselves) to a float suitable for Inflating the underlying Mesh with the per-vertex Inflate vectors.

View differences:

src/main/java/org/distorted/library/main/EffectQueueMatrix.java
41 41
  private static int[] mMVPMatrixH = new int[Distorted.MAIN_VARIANTS];
42 42
  private static int[] mMVMatrixH  = new int[Distorted.MAIN_VARIANTS];
43 43

  
44
  private static float[] mTmpMatrix = new float[16];
45
  private static float[] mTmpResult = new float[4];
46
  private static float[] mTmpPoint  = new float[4];
47
  private static float mMinX,mMaxX,mMinY,mMaxY;
48

  
44 49
///////////////////////////////////////////////////////////////////////////////////////////////////
45 50
   
46 51
  EffectQueueMatrix(long id)
......
57 62
    mMVMatrixH[variant] = GLES31.glGetUniformLocation(mProgramH, "u_MVMatrix");
58 63
    }
59 64

  
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

  
67
  private void magnifyDir()
68
    {
69
    Matrix.multiplyMV(mTmpResult,0,mTmpMatrix,0,mTmpPoint,0);
70
    float nx = mTmpResult[0]/mTmpResult[3];
71
    float ny = mTmpResult[1]/mTmpResult[3];
72

  
73
    if( nx<mMinX ) mMinX = nx;
74
    if( nx>mMaxX ) mMaxX = nx;
75
    if( ny<mMinY ) mMinY = ny;
76
    if( ny>mMaxY ) mMaxY = ny;
77
    }
78

  
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80
// return a float which describes how much larger an object must be so that it appears to be (about)
81
// 'marginInPixels' pixels larger in each direction. Used in Postprocessing.
82

  
83
  float magnify(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels)
84
    {
85
    mMinX = Integer.MAX_VALUE;
86
    mMaxX = Integer.MIN_VALUE;
87
    mMinY = Integer.MAX_VALUE;
88
    mMaxY = Integer.MIN_VALUE;
89

  
90
    mTmpPoint[3] = 1.0f;
91

  
92
    Matrix.multiplyMM(mTmpMatrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0);
93

  
94
    mTmpPoint[0] = +halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = +halfZ; magnifyDir();
95
    mTmpPoint[0] = +halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = -halfZ; magnifyDir();
96
    mTmpPoint[0] = +halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = +halfZ; magnifyDir();
97
    mTmpPoint[0] = +halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = -halfZ; magnifyDir();
98
    mTmpPoint[0] = -halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = +halfZ; magnifyDir();
99
    mTmpPoint[0] = -halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = -halfZ; magnifyDir();
100
    mTmpPoint[0] = -halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = +halfZ; magnifyDir();
101
    mTmpPoint[0] = -halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = -halfZ; magnifyDir();
102

  
103
    float xLenInPixels = projection.mWidth *(mMaxX-mMinX)/2;
104
    float yLenInPixels = projection.mHeight*(mMaxY-mMinY)/2;
105

  
106
    // already margin / min(xLen,yLen) is the size of the halo.
107
    // Here we need a bit more because we are marking not only the halo, but a little bit around
108
    // it as well so that the (blur for example) will be smooth on the edges. Thus the 2.0f.
109
    //
110
    // mMipmap ( 1.0 , 0.5, 0.25, 0.125 ) - we need to make the size of the halo independent
111
    // of postprocessing effect quality.
112

  
113
    return projection.mMipmap*2.0f*marginInPixels/( xLenInPixels>yLenInPixels ? yLenInPixels:xLenInPixels );
114
    }
115

  
60 116
///////////////////////////////////////////////////////////////////////////////////////////////////
61 117

  
62 118
  void compute(long currTime)

Also available in: Unified diff