Revision f89f791a
Added by Leszek Koltunski over 8 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 |
|
|
| 30 | 33 |
private static final int ATTACH = 0; |
| 31 | 34 |
private static final int DETACH = 1; |
| 32 | 35 |
private static final int DETALL = 2; |
| ... | ... | |
| 51 | 54 |
|
| 52 | 55 |
private ArrayList<Job> mJobs = new ArrayList<>(); |
| 53 | 56 |
|
| 54 |
DistortedFramebuffer mBuffer1, mBuffer2; |
|
| 57 |
DistortedFramebuffer[] mBuffer1, mBuffer2;
|
|
| 55 | 58 |
|
| 56 | 59 |
private long mTime; |
| 57 | 60 |
private float mFOV; |
| ... | ... | |
| 95 | 98 |
|
| 96 | 99 |
mClearDepth = 1.0f; |
| 97 | 100 |
|
| 101 |
mBuffer1 = new DistortedFramebuffer[NUM_MIPMAP]; |
|
| 102 |
mBuffer2 = new DistortedFramebuffer[NUM_MIPMAP]; |
|
| 103 |
|
|
| 98 | 104 |
createProjection(); |
| 99 | 105 |
} |
| 100 | 106 |
|
| ... | ... | |
| 171 | 177 |
} |
| 172 | 178 |
else |
| 173 | 179 |
{
|
| 174 |
if( mBuffer1==null ) |
|
| 180 |
if( mBuffer1[0]==null )
|
|
| 175 | 181 |
{
|
| 176 |
mBuffer1 = new DistortedFramebuffer(mDepthCreated!=DONT_CREATE, DistortedSurface.TYPE_SYST, mWidth, mHeight); |
|
| 177 |
mBuffer2 = new DistortedFramebuffer(false , DistortedSurface.TYPE_SYST, mWidth, mHeight); |
|
| 182 |
int sizeX = mWidth; |
|
| 183 |
int sizeY = mHeight; |
|
| 184 |
|
|
| 185 |
for(int j=0; j<NUM_MIPMAP; j++) |
|
| 186 |
{
|
|
| 187 |
mBuffer1[j] = new DistortedFramebuffer(mDepthCreated!=DONT_CREATE, DistortedSurface.TYPE_SYST, sizeX, sizeY); |
|
| 188 |
mBuffer2[j] = new DistortedFramebuffer(false , DistortedSurface.TYPE_SYST, sizeX, sizeY); |
|
| 189 |
|
|
| 190 |
sizeX *= 0.9f; |
|
| 191 |
sizeY *= 0.9f; |
|
| 192 |
} |
|
| 178 | 193 |
} |
| 179 | 194 |
|
| 180 |
numRenders += child.draw(time,mBuffer1); |
|
| 195 |
numRenders += child.draw(time,mBuffer1[CUR_MIPMAP]);
|
|
| 181 | 196 |
if( i==num-1 ) |
| 182 | 197 |
{
|
| 183 | 198 |
numRenders += currP.postprocess(time,this); |
| src/main/java/org/distorted/library/EffectQueuePostprocess.java | ||
|---|---|---|
| 93 | 93 |
private static float[] offsetsCache = new float[MAX_BLUR + MAX_BLUR*MAX_BLUR/4]; |
| 94 | 94 |
|
| 95 | 95 |
private static DistortedProgram mBlur1Program, mBlur2Program; |
| 96 |
private static int mRadius1H,mOffsets1H,mWeights1H,mDepth1H, mColorTexture1H; |
|
| 97 |
private static int mRadius2H,mOffsets2H,mWeights2H,mDepth2H, mColorTexture2H, mDepthTexture2H; |
|
| 96 |
private static int mRadius1H,mOffsets1H,mWeights1H,mDepth1H, mScale1H, mColorTexture1H;
|
|
| 97 |
private static int mRadius2H,mOffsets2H,mWeights2H,mDepth2H, mScale2H, mColorTexture2H, mDepthTexture2H;
|
|
| 98 | 98 |
private static float[] mWeights = new float[MAX_BLUR]; |
| 99 | 99 |
private static float[] mOffsets = new float[MAX_BLUR]; |
| 100 | 100 |
// another effect .... |
| ... | ... | |
| 131 | 131 |
mOffsets1H = GLES30.glGetUniformLocation( blur1ProgramH, "u_Offsets"); |
| 132 | 132 |
mWeights1H = GLES30.glGetUniformLocation( blur1ProgramH, "u_Weights"); |
| 133 | 133 |
mDepth1H = GLES30.glGetUniformLocation( blur1ProgramH, "u_Depth"); |
| 134 |
mScale1H = GLES30.glGetUniformLocation( blur1ProgramH, "u_Scale"); |
|
| 134 | 135 |
mColorTexture1H = GLES30.glGetUniformLocation( blur1ProgramH, "u_ColorTexture"); |
| 135 | 136 |
|
| 136 | 137 |
final InputStream blur2VertexStream = resources.openRawResource(R.raw.blur_vertex_shader); |
| ... | ... | |
| 154 | 155 |
mOffsets2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_Offsets"); |
| 155 | 156 |
mWeights2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_Weights"); |
| 156 | 157 |
mDepth2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_Depth"); |
| 158 |
mScale2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_Scale"); |
|
| 157 | 159 |
mColorTexture2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_ColorTexture"); |
| 158 | 160 |
mDepthTexture2H = GLES30.glGetUniformLocation( blur2ProgramH, "u_DepthTexture"); |
| 159 | 161 |
} |
| ... | ... | |
| 259 | 261 |
{
|
| 260 | 262 |
compute(time); |
| 261 | 263 |
|
| 262 |
surface.mBuffer1.setAsInput(); |
|
| 263 |
float w = surface.mWidth; |
|
| 264 |
float h = surface.mHeight; |
|
| 264 |
surface.mBuffer1[DistortedOutputSurface.CUR_MIPMAP].setAsInput();
|
|
| 265 |
float w = surface.mBuffer1[DistortedOutputSurface.CUR_MIPMAP].mWidth;
|
|
| 266 |
float h = surface.mBuffer1[DistortedOutputSurface.CUR_MIPMAP].mHeight;
|
|
| 265 | 267 |
|
| 266 | 268 |
int radius = (int)mUniforms[0]; |
| 267 | 269 |
if( radius>=MAX_BLUR ) radius = MAX_BLUR-1; |
| ... | ... | |
| 274 | 276 |
|
| 275 | 277 |
// horizontal blur |
| 276 | 278 |
mBlur1Program.useProgram(); |
| 277 |
surface.mBuffer2.setAsOutput(time); |
|
| 279 |
surface.mBuffer2[DistortedOutputSurface.CUR_MIPMAP].setAsOutput(time);
|
|
| 278 | 280 |
|
| 279 | 281 |
GLES30.glUniform1fv( mWeights1H, radius+1, weightsCache,offset); |
| 280 | 282 |
GLES30.glUniform1i( mRadius1H, radius); |
| 281 | 283 |
GLES30.glUniform1f( mDepth1H , 1.0f-surface.mNear); |
| 284 |
GLES30.glUniform1f( mScale1H , 1.0f); |
|
| 282 | 285 |
GLES30.glUniform1i( mColorTexture1H , 0 ); |
| 283 | 286 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/h; |
| 284 | 287 |
GLES30.glUniform1fv( mOffsets1H ,radius+1, mOffsets,0); |
| ... | ... | |
| 288 | 291 |
|
| 289 | 292 |
// vertical blur |
| 290 | 293 |
mBlur2Program.useProgram(); |
| 291 |
surface.mBuffer2.setAsInput(); |
|
| 292 |
surface.mBuffer1.setAsDepth(); |
|
| 294 |
surface.mBuffer2[DistortedOutputSurface.CUR_MIPMAP].setAsInput();
|
|
| 295 |
surface.mBuffer1[DistortedOutputSurface.CUR_MIPMAP].setAsDepth();
|
|
| 293 | 296 |
surface.setAsOutput(time); |
| 294 | 297 |
|
| 295 | 298 |
GLES30.glUniform1fv( mWeights2H, radius+1, weightsCache,offset); |
| 296 | 299 |
GLES30.glUniform1i( mRadius2H, radius); |
| 297 | 300 |
GLES30.glUniform1f( mDepth2H , 1.0f-surface.mNear); |
| 301 |
GLES30.glUniform1f( mScale2H , 0.9f); |
|
| 298 | 302 |
GLES30.glUniform1i( mColorTexture2H , 0 ); |
| 299 | 303 |
GLES30.glUniform1i( mDepthTexture2H , 1 ); |
| 300 | 304 |
for(int i=0; i<=radius; i++) mOffsets[i] = offsetsCache[offset+i]/w; |
| src/main/res/raw/blur_vertex_shader.glsl | ||
|---|---|---|
| 30 | 30 |
#endif |
| 31 | 31 |
|
| 32 | 32 |
uniform float u_Depth; // distance from the near plane to render plane, in clip coords |
| 33 |
uniform float u_Scale; |
|
| 33 | 34 |
|
| 34 | 35 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 35 | 36 |
|
| 36 | 37 |
void main() |
| 37 | 38 |
{
|
| 38 |
v_TexCoordinate = a_TexCoordinate; |
|
| 39 |
v_TexCoordinate = u_Scale*a_TexCoordinate;
|
|
| 39 | 40 |
gl_Position = vec4(2.0*a_Position,u_Depth,1.0); |
| 40 | 41 |
} |
Also available in: Unified diff
Preliminary support for MIPMAP levels of the postprocessing buffers. (doesn't work yet)