Revision 97020807
Added by Leszek Koltunski over 7 years ago
| src/main/java/org/distorted/library/main/DistortedEffects.java | ||
|---|---|---|
| 63 | 63 |
mQuadPositions.put(positionData).position(0); |
| 64 | 64 |
} |
| 65 | 65 |
|
| 66 |
/// BLIT DEPTH PROGRAM /// |
|
| 67 |
private static DistortedProgram mBlitDepthProgram; |
|
| 68 |
private static int mBlitDepthTextureH; |
|
| 69 |
private static int mBlitDepthDepthTextureH; |
|
| 70 |
private static int mBlitDepthDepthH; |
|
| 71 |
private static int mBlitDepthTexCorrH; |
|
| 72 |
|
|
| 66 | 73 |
/// OIT SSBO BUFFER /// |
| 67 | 74 |
private static int[] mLinkedListSSBO = new int[1]; |
| 68 | 75 |
private static int[] mAtomicCounter = new int[1]; |
| ... | ... | |
| 179 | 186 |
mBlitTextureH = GLES31.glGetUniformLocation( blitProgramH, "u_Texture"); |
| 180 | 187 |
mBlitDepthH = GLES31.glGetUniformLocation( blitProgramH, "u_Depth"); |
| 181 | 188 |
|
| 189 |
// BLIT DEPTH PROGRAM //////////////////////////////////// |
|
| 190 |
final InputStream blitDepthVertStream = resources.openRawResource(R.raw.blit_depth_vertex_shader); |
|
| 191 |
final InputStream blitDepthFragStream = resources.openRawResource(R.raw.blit_depth_fragment_shader); |
|
| 192 |
|
|
| 193 |
try |
|
| 194 |
{
|
|
| 195 |
mBlitDepthProgram = new DistortedProgram(blitDepthVertStream,blitDepthFragStream,Distorted.GLSL_VERSION,Distorted.GLSL_VERSION, Distorted.GLSL); |
|
| 196 |
} |
|
| 197 |
catch(Exception e) |
|
| 198 |
{
|
|
| 199 |
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile BLIT DEPTH program: "+e.getMessage());
|
|
| 200 |
throw new RuntimeException(e.getMessage()); |
|
| 201 |
} |
|
| 202 |
|
|
| 203 |
int blitDepthProgramH = mBlitDepthProgram.getProgramHandle(); |
|
| 204 |
mBlitDepthTextureH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_Texture"); |
|
| 205 |
mBlitDepthDepthTextureH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_DepthTexture"); |
|
| 206 |
mBlitDepthDepthH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_Depth"); |
|
| 207 |
mBlitDepthTexCorrH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_TexCorr"); |
|
| 208 |
|
|
| 182 | 209 |
// OIT CLEAR PROGRAM //////////////////////////////////// |
| 183 | 210 |
final InputStream oitClearVertStream = resources.openRawResource(R.raw.oit_vertex_shader); |
| 184 | 211 |
final InputStream oitClearFragStream = resources.openRawResource(R.raw.oit_clear_fragment_shader); |
| ... | ... | |
| 430 | 457 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4); |
| 431 | 458 |
} |
| 432 | 459 |
|
| 460 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 461 |
|
|
| 462 |
static void blitDepthPriv(DistortedOutputSurface surface, float corrW, float corrH) |
|
| 463 |
{
|
|
| 464 |
mBlitDepthProgram.useProgram(); |
|
| 465 |
|
|
| 466 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
|
| 467 |
GLES31.glUniform1i(mBlitDepthTextureH, 0); |
|
| 468 |
GLES31.glUniform1i(mBlitDepthDepthTextureH, 1); |
|
| 469 |
GLES31.glUniform2f(mBlitDepthTexCorrH, corrW, corrH ); |
|
| 470 |
GLES31.glUniform1f( mBlitDepthDepthH , 1.0f-surface.mNear); |
|
| 471 |
GLES31.glVertexAttribPointer(mBlitDepthProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions); |
|
| 472 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4); |
|
| 473 |
} |
|
| 474 |
|
|
| 433 | 475 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 434 | 476 |
// reset atomic counter to 0 |
| 435 | 477 |
|
| src/main/java/org/distorted/library/main/DistortedOutputSurface.java | ||
|---|---|---|
| 261 | 261 |
} |
| 262 | 262 |
} |
| 263 | 263 |
|
| 264 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 265 |
|
|
| 266 |
private int blitWithDepth(long currTime, DistortedOutputSurface buffer,int fbo) |
|
| 267 |
{
|
|
| 268 |
GLES31.glViewport(0, 0, mWidth, mHeight); |
|
| 269 |
setAsOutputFBO(currTime,fbo); |
|
| 270 |
GLES31.glActiveTexture(GLES31.GL_TEXTURE0); |
|
| 271 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, buffer.mColorH[2*fbo]); |
|
| 272 |
GLES31.glActiveTexture(GLES31.GL_TEXTURE1); |
|
| 273 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, buffer.mDepthStencilH[fbo]); |
|
| 274 |
|
|
| 275 |
GLES31.glDisable(GLES31.GL_STENCIL_TEST); |
|
| 276 |
GLES31.glStencilMask(0x00); |
|
| 277 |
|
|
| 278 |
DistortedEffects.blitDepthPriv(this, buffer.getWidthCorrection(), buffer.getHeightCorrection() ); |
|
| 279 |
GLES31.glActiveTexture(GLES31.GL_TEXTURE0); |
|
| 280 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0); |
|
| 281 |
GLES31.glActiveTexture(GLES31.GL_TEXTURE1); |
|
| 282 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0); |
|
| 283 |
|
|
| 284 |
// clear buffers |
|
| 285 |
GLES31.glStencilMask(0xff); |
|
| 286 |
GLES31.glDepthMask(true); |
|
| 287 |
GLES31.glColorMask(true,true,true,true); |
|
| 288 |
GLES31.glClearColor(0.0f,0.0f,0.0f,0.0f); |
|
| 289 |
GLES31.glClearDepthf(1.0f); |
|
| 290 |
GLES31.glClearStencil(0); |
|
| 291 |
|
|
| 292 |
buffer.setAsOutputFBO(fbo); |
|
| 293 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[2*fbo+1], 0); |
|
| 294 |
GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT|GLES31.GL_DEPTH_BUFFER_BIT|GLES31.GL_STENCIL_BUFFER_BIT); |
|
| 295 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, buffer.mColorH[2*fbo ], 0); |
|
| 296 |
GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT); |
|
| 297 |
|
|
| 298 |
return 1; |
|
| 299 |
} |
|
| 300 |
|
|
| 264 | 301 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 265 | 302 |
|
| 266 | 303 |
private static void oitClear(DistortedOutputSurface buffer) |
| src/main/res/raw/blit_depth_fragment_shader.glsl | ||
|---|---|---|
| 1 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2016 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Distorted is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
precision highp float; |
|
| 21 |
|
|
| 22 |
out vec4 fragColor; // The output color |
|
| 23 |
in vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment. |
|
| 24 |
|
|
| 25 |
uniform sampler2D u_Texture; |
|
| 26 |
uniform sampler2D u_DepthTexture; |
|
| 27 |
|
|
| 28 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 29 |
|
|
| 30 |
void main() |
|
| 31 |
{
|
|
| 32 |
gl_FragDepth = texture(u_DepthTexture,v_TexCoordinate).r; |
|
| 33 |
fragColor = texture(u_Texture ,v_TexCoordinate); |
|
| 34 |
} |
|
| src/main/res/raw/blit_depth_vertex_shader.glsl | ||
|---|---|---|
| 1 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2016 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
| 7 |
// it under the terms of the GNU General Public License as published by // |
|
| 8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
| 9 |
// (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// Distorted is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
| 14 |
// GNU General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU General Public License // |
|
| 17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
precision highp float; |
|
| 21 |
|
|
| 22 |
in vec2 a_Position; // Per-vertex position. |
|
| 23 |
out vec2 v_TexCoordinate; // |
|
| 24 |
|
|
| 25 |
uniform float u_Depth; // distance from the near plane to render plane, in clip coords |
|
| 26 |
uniform vec2 u_TexCorr; // when we blit from postprocessing buffers, the buffers can be |
|
| 27 |
// larger than necessary (there is just one static set being |
|
| 28 |
// reused!) so we need to compensate here by adjusting the texture |
|
| 29 |
// coords. |
|
| 30 |
|
|
| 31 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 32 |
|
|
| 33 |
void main() |
|
| 34 |
{
|
|
| 35 |
v_TexCoordinate = (a_Position + 0.5) * u_TexCorr; |
|
| 36 |
gl_Position = vec4(2.0*a_Position,u_Depth,1.0); |
|
| 37 |
} |
|
Also available in: Unified diff
Start merging master and OIT.