Revision 8426bd6a
Added by Leszek Koltunski about 7 years ago
src/main/java/org/distorted/library/DistortedOutputSurface.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
abstract class DistortedOutputSurface extends DistortedSurface implements DistortedSlave |
29 | 29 |
{ |
30 |
private static final int NUM_MIPMAP = 4; |
|
31 |
static final int CUR_MIPMAP = 1; |
|
32 |
|
|
33 | 30 |
private static final int ATTACH = 0; |
34 | 31 |
private static final int DETACH = 1; |
35 | 32 |
private static final int DETALL = 2; |
... | ... | |
99 | 96 |
|
100 | 97 |
mClearDepth = 1.0f; |
101 | 98 |
|
102 |
mBuffer1 = new DistortedFramebuffer[NUM_MIPMAP];
|
|
103 |
mBuffer2 = new DistortedFramebuffer[NUM_MIPMAP];
|
|
99 |
mBuffer1 = new DistortedFramebuffer[EffectQuality.LENGTH];
|
|
100 |
mBuffer2 = new DistortedFramebuffer[EffectQuality.LENGTH];
|
|
104 | 101 |
|
105 |
mMipmap = (this instanceof DistortedScreen ? 0.5f : 1.0f);
|
|
102 |
mMipmap = 1.0f;
|
|
106 | 103 |
|
107 | 104 |
createProjection(); |
108 | 105 |
} |
... | ... | |
113 | 110 |
{ |
114 | 111 |
if( mWidth>0 && mHeight>1 ) |
115 | 112 |
{ |
116 |
float mw = mWidth;//mMipmap*mWidth; |
|
117 |
float mh = mHeight;//mMipmap*mHeight; |
|
118 |
|
|
119 | 113 |
if( mFOV>0.0f ) // perspective projection |
120 | 114 |
{ |
121 | 115 |
float a = 2.0f*(float)Math.tan(mFOV*Math.PI/360); |
122 |
float q = mw*mNear;
|
|
123 |
float c = mh*mNear;
|
|
116 |
float q = mWidth*mNear;
|
|
117 |
float c = mHeight*mNear;
|
|
124 | 118 |
|
125 | 119 |
float left = -q/2; |
126 | 120 |
float right = +q/2; |
... | ... | |
128 | 122 |
float top = +c/2; |
129 | 123 |
float near = c/a; |
130 | 124 |
|
131 |
mDistance = mh/a;
|
|
125 |
mDistance = mHeight/a;
|
|
132 | 126 |
float far = 2*mDistance-near; |
133 | 127 |
|
134 | 128 |
Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far); |
135 | 129 |
} |
136 | 130 |
else // parallel projection |
137 | 131 |
{ |
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);
|
|
132 |
float left = -mWidth/2.0f;
|
|
133 |
float right = +mWidth/2.0f;
|
|
134 |
float bottom = -mHeight/2.0f;
|
|
135 |
float top = +mHeight/2.0f;
|
|
136 |
float near = mWidth+mHeight-mHeight*(1.0f-mNear);
|
|
137 |
mDistance = mWidth+mHeight;
|
|
138 |
float far = mWidth+mHeight+mHeight*(1.0f-mNear);
|
|
145 | 139 |
|
146 | 140 |
Matrix.orthoM(mProjectionMatrix, 0, left, right, bottom, top, near, far); |
147 | 141 |
} |
... | ... | |
185 | 179 |
{ |
186 | 180 |
float mipmap=1.0f; |
187 | 181 |
|
188 |
for(int j=0; j<NUM_MIPMAP; j++)
|
|
182 |
for(int j=0; j<EffectQuality.LENGTH; j++)
|
|
189 | 183 |
{ |
190 | 184 |
mBuffer1[j] = new DistortedFramebuffer( mDepthCreated!=DONT_CREATE, DistortedSurface.TYPE_SYST, |
191 | 185 |
(int)(mWidth*mipmap), (int)(mHeight*mipmap) ); |
... | ... | |
197 | 191 |
DistortedSurface.toDo(); // create immediately |
198 | 192 |
} |
199 | 193 |
|
200 |
numRenders += child.draw(time,mBuffer1[CUR_MIPMAP]); |
|
194 |
numRenders += child.draw(time,mBuffer1[currP.getQuality()]); |
|
195 |
|
|
201 | 196 |
if( i==num-1 ) |
202 | 197 |
{ |
203 | 198 |
numRenders += currP.postprocess(time,this); |
... | ... | |
316 | 311 |
* such prepared OutputSurface, the library will make sure to scale any Effects used so that the end |
317 | 312 |
* scene will end up looking identical no matter which object we render to. Identical, that is, except |
318 | 313 |
* for the loss of quality and gain in speed associated with rendering to a smaller Surface. |
314 |
* <p> |
|
315 |
* Example: if you create two FBOs, one 1000x1000 and another 500x500 in size, and set the second one |
|
316 |
* mipmap to 0.5 (the first one's is 1.0 by default), define Effects to be a single move by (100,100), |
|
317 |
* and render a skinned Mesh into both FBO, the end result will look proportionally the same, because |
|
318 |
* in the second case the move vector (100,100) will be auto-scaled to (50,50). |
|
319 | 319 |
* |
320 | 320 |
* @param mipmap The mipmap level. Acceptable range: 0<mipmap<infinity, although mipmap>1 |
321 | 321 |
* does not make any sense (that would result in loss of speed and no gain in quality) |
Also available in: Unified diff
Mipmap levels!