Revision c1a38ba3
Added by Leszek Koltunski over 7 years ago
| src/main/java/org/distorted/library/main/Distorted.java | ||
|---|---|---|
| 120 | 120 |
{
|
| 121 | 121 |
if( version.contains("r12") )
|
| 122 | 122 |
{
|
| 123 |
android.util.Log.e("DISTORTED", "You are running this on a ARM Mali driver r12. This is a buggy driver, please update to r22. Problems with flashing expected.");
|
|
| 123 |
android.util.Log.e("DISTORTED", "You are running this on a ARM Mali driver r12.\nThis is a buggy driver, please update to r22. Problems with flashing expected.");
|
|
| 124 | 124 |
} |
| 125 | 125 |
} |
| 126 | 126 |
else if( vendor.contains("Imagination") )
|
| 127 | 127 |
{
|
| 128 | 128 |
if( renderer.contains("GE8") )
|
| 129 | 129 |
{
|
| 130 |
android.util.Log.e("DISTORTED", "You are running this on a PowerVR GE8XXX. Due to a buggy compiler OIT rendering will not work");
|
|
| 130 |
android.util.Log.e("DISTORTED", "You are running this on a PowerVR GE8XXX.\nDue to a buggy compiler OIT rendering will not work");
|
|
| 131 | 131 |
} |
| 132 | 132 |
} |
| 133 | 133 |
} |
| src/main/java/org/distorted/library/main/DistortedEffects.java | ||
|---|---|---|
| 70 | 70 |
private static int mBlitDepthDepthH; |
| 71 | 71 |
private static int mBlitDepthTexCorrH; |
| 72 | 72 |
|
| 73 |
/// NORMAL PROGRAM ///// |
|
| 74 |
private static DistortedProgram mNormalProgram; |
|
| 75 |
private static int mNormalMVPMatrixH; |
|
| 76 |
|
|
| 73 | 77 |
/// OIT SSBO BUFFER /// |
| 74 | 78 |
private static int[] mLinkedListSSBO = new int[1]; |
| 75 | 79 |
private static int[] mAtomicCounter = new int[1]; |
| ... | ... | |
| 113 | 117 |
private static int mOITRenderTexCorrH; |
| 114 | 118 |
private static int mOITRenderSizeH; |
| 115 | 119 |
|
| 116 |
/// NORMAL PROGRAM ///// |
|
| 117 |
private static DistortedProgram mNormalProgram; |
|
| 118 |
private static int mNormalMVPMatrixH; |
|
| 120 |
/// MAIN OIT PROGRAM /// |
|
| 121 |
private static DistortedProgram mMainOITProgram; |
|
| 122 |
private static int mMainOITTextureH; |
|
| 123 |
private static int mMainOITSizeH; |
|
| 124 |
private static int mMainOITNumRecordsH; |
|
| 119 | 125 |
/// END PROGRAMS ////// |
| 120 | 126 |
|
| 121 | 127 |
private static long mNextID =0; |
| ... | ... | |
| 228 | 234 |
|
| 229 | 235 |
static void createProgramsOIT(Resources resources) |
| 230 | 236 |
{
|
| 237 |
// MAIN OIT PROGRAM //////////////////////////////// |
|
| 238 |
final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader); |
|
| 239 |
final InputStream mainFragStream = resources.openRawResource(R.raw.main_fragment_shader); |
|
| 240 |
|
|
| 241 |
int numF = FragmentEffect.getNumEnabled(); |
|
| 242 |
int numV = VertexEffect.getNumEnabled(); |
|
| 243 |
|
|
| 244 |
String mainVertHeader= Distorted.GLSL_VERSION + |
|
| 245 |
("#define NUM_VERTEX " + ( numV>0 ? getMax(EffectType.VERTEX ) : 0 ) + "\n") +
|
|
| 246 |
("#define OIT\n");
|
|
| 247 |
String mainFragHeader= Distorted.GLSL_VERSION + |
|
| 248 |
("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n") +
|
|
| 249 |
("#define OIT\n");
|
|
| 250 |
|
|
| 251 |
String enabledEffectV= VertexEffect.getGLSL(); |
|
| 252 |
String enabledEffectF= FragmentEffect.getGLSL(); |
|
| 253 |
|
|
| 254 |
try |
|
| 255 |
{
|
|
| 256 |
mMainOITProgram = new DistortedProgram(mainVertStream, mainFragStream, mainVertHeader, mainFragHeader, |
|
| 257 |
enabledEffectV, enabledEffectF, Distorted.GLSL, null); |
|
| 258 |
} |
|
| 259 |
catch(Exception e) |
|
| 260 |
{
|
|
| 261 |
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile MAIN OIT program: "+e.getMessage());
|
|
| 262 |
throw new RuntimeException(e.getMessage()); |
|
| 263 |
} |
|
| 264 |
|
|
| 265 |
int mainOITProgramH = mMainOITProgram.getProgramHandle(); |
|
| 266 |
EffectQueueFragment.getUniformsOIT(mainOITProgramH); |
|
| 267 |
EffectQueueVertex.getUniformsOIT(mainOITProgramH); |
|
| 268 |
EffectQueueMatrix.getUniformsOIT(mainOITProgramH); |
|
| 269 |
mMainOITTextureH = GLES31.glGetUniformLocation( mainOITProgramH, "u_Texture"); |
|
| 270 |
mMainOITSizeH = GLES31.glGetUniformLocation( mainOITProgramH, "u_Size"); |
|
| 271 |
mMainOITNumRecordsH = GLES31.glGetUniformLocation( mainOITProgramH, "u_numRecords"); |
|
| 272 |
|
|
| 231 | 273 |
// OIT CLEAR PROGRAM //////////////////////////////////// |
| 232 | 274 |
final InputStream oitClearVertStream = resources.openRawResource(R.raw.oit_vertex_shader); |
| 233 | 275 |
final InputStream oitClearFragStream = resources.openRawResource(R.raw.oit_clear_fragment_shader); |
| ... | ... | |
| 414 | 456 |
GLES31.glDrawArrays(GLES31.GL_LINES, 0, 2*mesh.numVertices); |
| 415 | 457 |
} |
| 416 | 458 |
|
| 459 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 460 |
|
|
| 461 |
void drawPrivOIT(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime, float marginInPixels) |
|
| 462 |
{
|
|
| 463 |
float halfZ = halfW*mesh.zFactor; |
|
| 464 |
|
|
| 465 |
mM.compute(currTime); |
|
| 466 |
mV.compute(currTime,halfW,halfH,halfZ); |
|
| 467 |
mF.compute(currTime,halfW,halfH); |
|
| 468 |
mP.compute(currTime); |
|
| 469 |
|
|
| 470 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
|
| 471 |
|
|
| 472 |
mMainOITProgram.useProgram(); |
|
| 473 |
GLES31.glUniform1i(mMainOITTextureH, 0); |
|
| 474 |
GLES31.glUniform2ui(mMainOITSizeH, surface.mWidth, surface.mHeight); |
|
| 475 |
GLES31.glUniform1ui(mMainOITNumRecordsH, (mBufferSize-surface.mWidth*surface.mHeight)/3 ); // see the fragment shader |
|
| 476 |
|
|
| 477 |
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mesh.mAttVBO[0]); |
|
| 478 |
GLES31.glVertexAttribPointer(mMainOITProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET0); |
|
| 479 |
GLES31.glVertexAttribPointer(mMainOITProgram.mAttribute[1], MeshObject.NOR_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET1); |
|
| 480 |
GLES31.glVertexAttribPointer(mMainOITProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET2); |
|
| 481 |
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0); |
|
| 482 |
|
|
| 483 |
mM.sendOIT(surface,halfW,halfH,halfZ,marginInPixels); |
|
| 484 |
mV.sendOIT(); |
|
| 485 |
mF.sendOIT(); |
|
| 486 |
|
|
| 487 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.numVertices); |
|
| 488 |
|
|
| 489 |
if( mesh.mShowNormals ) displayNormals(mesh); |
|
| 490 |
} |
|
| 491 |
|
|
| 417 | 492 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 418 | 493 |
|
| 419 | 494 |
void drawPriv(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime, float marginInPixels) |
| src/main/java/org/distorted/library/main/DistortedNode.java | ||
|---|---|---|
| 293 | 293 |
return 0; |
| 294 | 294 |
} |
| 295 | 295 |
|
| 296 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 297 |
// Use the Order Independent Transparency method to draw a non-postprocessed child. |
|
| 298 |
|
|
| 299 |
int drawOIT(long currTime, DistortedOutputSurface surface) |
|
| 300 |
{
|
|
| 301 |
DistortedInputSurface input = mNumChildren[0]==0 ? mSurface : mData.mFBO; |
|
| 302 |
|
|
| 303 |
if( input.setAsInput() ) |
|
| 304 |
{
|
|
| 305 |
mState.apply(); |
|
| 306 |
mEffects.drawPrivOIT(mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime, 0); |
|
| 307 |
return 1; |
|
| 308 |
} |
|
| 309 |
|
|
| 310 |
return 0; |
|
| 311 |
} |
|
| 312 |
|
|
| 296 | 313 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 297 | 314 |
// return the total number of render calls issued |
| 298 | 315 |
|
| src/main/java/org/distorted/library/main/DistortedOutputSurface.java | ||
|---|---|---|
| 395 | 395 |
EffectQueuePostprocess lastQueue=null, currQueue; |
| 396 | 396 |
long lastBucket=0, currBucket; |
| 397 | 397 |
|
| 398 |
if( oit && numChildren>0 ) |
|
| 399 |
{
|
|
| 400 |
oitClear(this); |
|
| 401 |
} |
|
| 402 |
|
|
| 398 | 403 |
for(int i=0; i<numChildren; i++) |
| 399 | 404 |
{
|
| 400 | 405 |
child1 = children.get(i); |
| ... | ... | |
| 404 | 409 |
if( currBucket==0 ) |
| 405 | 410 |
{
|
| 406 | 411 |
setAsOutputFBO(time,fbo); |
| 407 |
numRenders += child1.draw(time,this); |
|
| 412 |
|
|
| 413 |
if( oit ) |
|
| 414 |
{
|
|
| 415 |
numRenders += child1.drawOIT(time, this); |
|
| 416 |
GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT | GLES31.GL_ATOMIC_COUNTER_BARRIER_BIT); |
|
| 417 |
} |
|
| 418 |
else |
|
| 419 |
{
|
|
| 420 |
numRenders += child1.draw(time, this); |
|
| 421 |
} |
|
| 408 | 422 |
} |
| 409 | 423 |
else |
| 410 | 424 |
{
|
| ... | ... | |
| 415 | 429 |
if( lastBucket==0 ) |
| 416 | 430 |
{
|
| 417 | 431 |
clonePostprocessingViewport(this); |
| 418 |
|
|
| 419 |
if( oit ) |
|
| 420 |
{
|
|
| 421 |
oitClear(this); |
|
| 422 |
} |
|
| 423 | 432 |
} |
| 424 | 433 |
else |
| 425 | 434 |
{
|
| ... | ... | |
| 467 | 476 |
{
|
| 468 | 477 |
numRenders += oitBuild(time, mBuffer[quality], fbo); |
| 469 | 478 |
GLES31.glMemoryBarrier(GLES31.GL_SHADER_STORAGE_BARRIER_BIT | GLES31.GL_ATOMIC_COUNTER_BARRIER_BIT); |
| 470 |
numRenders += oitRender(time, fbo); // merge the OIT linked list |
|
| 471 | 479 |
mBuffer[quality].clearBuffer(fbo); |
| 472 | 480 |
} |
| 473 | 481 |
else |
| ... | ... | |
| 481 | 489 |
lastBucket= currBucket; |
| 482 | 490 |
} // end main for loop |
| 483 | 491 |
|
| 492 |
if( oit && numChildren>0 ) |
|
| 493 |
{
|
|
| 494 |
numRenders += oitRender(time, fbo); // merge the OIT linked list |
|
| 495 |
} |
|
| 496 |
|
|
| 484 | 497 |
return numRenders; |
| 485 | 498 |
} |
| 486 | 499 |
|
| src/main/java/org/distorted/library/main/EffectQueueFragment.java | ||
|---|---|---|
| 31 | 31 |
{
|
| 32 | 32 |
private static final int NUM_UNIFORMS = FragmentEffect.NUM_UNIFORMS; |
| 33 | 33 |
private static final int INDEX = EffectType.FRAGMENT.ordinal(); |
| 34 |
|
|
| 34 | 35 |
private static int mNumEffectsH; |
| 35 | 36 |
private static int mNameH; |
| 36 | 37 |
private static int mUniformsH; |
| 37 |
|
|
| 38 |
|
|
| 39 |
private static int mNumEffectsOITH; |
|
| 40 |
private static int mNameOITH; |
|
| 41 |
private static int mUniformsOITH; |
|
| 42 |
|
|
| 38 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 39 | 44 |
|
| 40 | 45 |
EffectQueueFragment(long id) |
| ... | ... | |
| 51 | 56 |
mUniformsH = GLES31.glGetUniformLocation( mProgramH, "fUniforms"); |
| 52 | 57 |
} |
| 53 | 58 |
|
| 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 60 |
|
|
| 61 |
static void getUniformsOIT(int mProgramH) |
|
| 62 |
{
|
|
| 63 |
mNumEffectsOITH= GLES31.glGetUniformLocation( mProgramH, "fNumEffects"); |
|
| 64 |
mNameOITH = GLES31.glGetUniformLocation( mProgramH, "fName"); |
|
| 65 |
mUniformsOITH = GLES31.glGetUniformLocation( mProgramH, "fUniforms"); |
|
| 66 |
} |
|
| 67 |
|
|
| 54 | 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 55 | 69 |
|
| 56 | 70 |
void compute(long currTime,float halfX, float halfY) |
| ... | ... | |
| 95 | 109 |
GLES31.glUniform4fv( mUniformsH,(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0); |
| 96 | 110 |
} |
| 97 | 111 |
} |
| 112 |
|
|
| 113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 114 |
|
|
| 115 |
void sendOIT() |
|
| 116 |
{
|
|
| 117 |
GLES31.glUniform1i( mNumEffectsOITH, mNumEffects); |
|
| 118 |
|
|
| 119 |
if( mNumEffects>0 ) |
|
| 120 |
{
|
|
| 121 |
GLES31.glUniform1iv( mNameOITH , mNumEffects, mName ,0); |
|
| 122 |
GLES31.glUniform4fv( mUniformsOITH,(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0); |
|
| 123 |
} |
|
| 124 |
} |
|
| 98 | 125 |
} |
| src/main/java/org/distorted/library/main/EffectQueueMatrix.java | ||
|---|---|---|
| 43 | 43 |
private static float mMiny; |
| 44 | 44 |
private static float mMaxy; |
| 45 | 45 |
|
| 46 |
private static int mObjDH; // This is a handle to half a Object dimensions |
|
| 47 |
private static int mMVPMatrixH; // the transformation matrix |
|
| 48 |
private static int mMVMatrixH; // the modelview matrix. |
|
| 46 |
private static int mObjDH; // This is a handle to half a Object dimensions |
|
| 47 |
private static int mMVPMatrixH; // the transformation matrix |
|
| 48 |
private static int mMVMatrixH; // the modelview matrix. |
|
| 49 |
|
|
| 50 |
private static int mObjDOITH; // |
|
| 51 |
private static int mMVPMatrixOITH; // Same like above, but in main OIT program. |
|
| 52 |
private static int mMVMatrixOITH; // |
|
| 49 | 53 |
|
| 50 | 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 51 | 55 |
|
| ... | ... | |
| 108 | 112 |
mMVMatrixH = GLES31.glGetUniformLocation(mProgramH, "u_MVMatrix"); |
| 109 | 113 |
} |
| 110 | 114 |
|
| 115 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 116 |
|
|
| 117 |
static void getUniformsOIT(int mProgramH) |
|
| 118 |
{
|
|
| 119 |
mObjDOITH = GLES31.glGetUniformLocation(mProgramH, "u_objD"); |
|
| 120 |
mMVPMatrixOITH= GLES31.glGetUniformLocation(mProgramH, "u_MVPMatrix"); |
|
| 121 |
mMVMatrixOITH = GLES31.glGetUniformLocation(mProgramH, "u_MVMatrix"); |
|
| 122 |
} |
|
| 123 |
|
|
| 111 | 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 112 | 125 |
|
| 113 | 126 |
void compute(long currTime) |
| ... | ... | |
| 162 | 175 |
GLES31.glUniformMatrix4fv(mMVMatrixH , 1, false, mViewMatrix, 0); |
| 163 | 176 |
GLES31.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0); |
| 164 | 177 |
} |
| 178 |
|
|
| 179 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 180 |
|
|
| 181 |
void sendOIT(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels) |
|
| 182 |
{
|
|
| 183 |
Matrix.setIdentityM(mViewMatrix, 0); |
|
| 184 |
Matrix.translateM(mViewMatrix, 0, -projection.mWidth/2, projection.mHeight/2, -projection.mDistance); |
|
| 185 |
float mipmap = projection.mMipmap; |
|
| 186 |
if( mipmap!=1 ) Matrix.scaleM(mViewMatrix, 0, mipmap, mipmap, mipmap); |
|
| 187 |
|
|
| 188 |
for(int i=0; i<mNumEffects; i++) ((MatrixEffect)mEffects[i]).apply(mViewMatrix,mUniforms,i); |
|
| 189 |
|
|
| 190 |
Matrix.translateM(mViewMatrix, 0, halfX,-halfY,-halfZ); |
|
| 191 |
if( marginInPixels!=0 ) magnify(projection,halfX,halfY,halfZ, marginInPixels); |
|
| 192 |
Matrix.multiplyMM(mMVPMatrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0); |
|
| 193 |
|
|
| 194 |
GLES31.glUniform3f( mObjDOITH , halfX, halfY, halfZ); |
|
| 195 |
GLES31.glUniformMatrix4fv(mMVMatrixOITH , 1, false, mViewMatrix, 0); |
|
| 196 |
GLES31.glUniformMatrix4fv(mMVPMatrixOITH, 1, false, mMVPMatrix , 0); |
|
| 197 |
} |
|
| 165 | 198 |
} |
| src/main/java/org/distorted/library/main/EffectQueueVertex.java | ||
|---|---|---|
| 31 | 31 |
{
|
| 32 | 32 |
private static final int NUM_UNIFORMS = VertexEffect.NUM_UNIFORMS; |
| 33 | 33 |
private static final int INDEX = EffectType.VERTEX.ordinal(); |
| 34 |
|
|
| 34 | 35 |
private static int mNumEffectsH; |
| 35 | 36 |
private static int mNameH; |
| 36 | 37 |
private static int mUniformsH; |
| 37 |
|
|
| 38 |
|
|
| 39 |
private static int mNumEffectsOITH; |
|
| 40 |
private static int mNameOITH; |
|
| 41 |
private static int mUniformsOITH; |
|
| 42 |
|
|
| 38 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 39 | 44 |
|
| 40 | 45 |
EffectQueueVertex(long id) |
| ... | ... | |
| 51 | 56 |
mUniformsH = GLES31.glGetUniformLocation( mProgramH, "vUniforms"); |
| 52 | 57 |
} |
| 53 | 58 |
|
| 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 60 |
|
|
| 61 |
static void getUniformsOIT(int mProgramH) |
|
| 62 |
{
|
|
| 63 |
mNumEffectsOITH= GLES31.glGetUniformLocation( mProgramH, "vNumEffects"); |
|
| 64 |
mNameOITH = GLES31.glGetUniformLocation( mProgramH, "vName"); |
|
| 65 |
mUniformsOITH = GLES31.glGetUniformLocation( mProgramH, "vUniforms"); |
|
| 66 |
} |
|
| 67 |
|
|
| 54 | 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 55 | 69 |
|
| 56 | 70 |
void compute(long currTime,float halfX, float halfY, float halfZ) |
| ... | ... | |
| 96 | 110 |
GLES31.glUniform4fv( mUniformsH,(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0); |
| 97 | 111 |
} |
| 98 | 112 |
} |
| 113 |
|
|
| 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 115 |
|
|
| 116 |
void sendOIT() |
|
| 117 |
{
|
|
| 118 |
GLES31.glUniform1i( mNumEffectsOITH, mNumEffects); |
|
| 119 |
|
|
| 120 |
if( mNumEffects>0 ) |
|
| 121 |
{
|
|
| 122 |
GLES31.glUniform1iv( mNameOITH , mNumEffects, mName ,0); |
|
| 123 |
GLES31.glUniform4fv( mUniformsOITH,(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0); |
|
| 124 |
} |
|
| 125 |
} |
|
| 99 | 126 |
} |
| src/main/res/raw/main_fragment_shader.glsl | ||
|---|---|---|
| 18 | 18 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 19 | 19 |
|
| 20 | 20 |
precision highp float; |
| 21 |
precision highp int; |
|
| 21 | 22 |
|
| 22 | 23 |
in vec3 v_Position; // Interpolated position for this fragment. |
| 23 | 24 |
in vec3 v_Normal; // Interpolated normal for this fragment. |
| ... | ... | |
| 93 | 94 |
} |
| 94 | 95 |
} |
| 95 | 96 |
} |
| 97 |
|
|
| 98 |
////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 99 |
|
|
| 100 |
uint convert(vec4 c) |
|
| 101 |
{
|
|
| 102 |
return ((uint(255.0*c.r))<<24u) + ((uint(255.0*c.g))<<16u) + ((uint(255.0*c.b))<<8u) + uint(255.0*c.a); |
|
| 103 |
} |
|
| 104 |
|
|
| 96 | 105 |
#endif // OIT |
| 97 | 106 |
|
| 98 | 107 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 118 | 127 |
#endif |
| 119 | 128 |
|
| 120 | 129 |
#ifdef OIT |
| 121 |
if( frag.a > 0.95 )
|
|
| 130 |
if( color.a > 0.95 )
|
|
| 122 | 131 |
{
|
| 123 | 132 |
fragColor= vec4(color.rgb * (1.0 + 7.0*v_Normal.z) * 0.125, color.a); |
| 124 | 133 |
} |
| 125 | 134 |
else |
| 126 | 135 |
{
|
| 127 |
if( frag.a > 0.0 )
|
|
| 136 |
if( color.a > 0.0 )
|
|
| 128 | 137 |
{
|
| 129 | 138 |
const float S= 2147483647.0; // max signed int. Could probably be max unsigned int but this is enough. |
| 130 |
insert(v_Pixel, uint(S*(1.0-depth)/2.0), convert(frag) );
|
|
| 139 |
insert(v_Pixel, uint(S*(1.0-gl_FragCoord.z)/2.0), convert(color) );
|
|
| 131 | 140 |
} |
| 132 | 141 |
discard; |
| 133 | 142 |
} |
| src/main/res/raw/main_vertex_shader.glsl | ||
|---|---|---|
| 18 | 18 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 19 | 19 |
|
| 20 | 20 |
precision highp float; |
| 21 |
precision highp int; |
|
| 21 | 22 |
|
| 22 | 23 |
in vec3 a_Position; // Per-vertex position. |
| 23 | 24 |
in vec3 a_Normal; // Per-vertex normal vector. |
| src/main/res/raw/oit_build_fragment_shader.glsl | ||
|---|---|---|
| 95 | 95 |
|
| 96 | 96 |
void main() |
| 97 | 97 |
{
|
| 98 |
vec4 frag = texture(u_Texture , v_TexCoordinate);
|
|
| 98 |
vec4 color= texture(u_Texture , v_TexCoordinate);
|
|
| 99 | 99 |
float depth= texture(u_DepthTexture, v_TexCoordinate).r; |
| 100 | 100 |
|
| 101 |
if( frag.a > 0.95 )
|
|
| 101 |
if( color.a > 0.95 )
|
|
| 102 | 102 |
{
|
| 103 | 103 |
gl_FragDepth = depth; |
| 104 |
fragColor = frag;
|
|
| 104 |
fragColor = color;
|
|
| 105 | 105 |
} |
| 106 | 106 |
else |
| 107 | 107 |
{
|
| 108 |
if( frag.a > 0.0 )
|
|
| 108 |
if( color.a > 0.0 )
|
|
| 109 | 109 |
{
|
| 110 | 110 |
const float S= 2147483647.0; // max signed int. Could probably be max unsigned int but this is enough. |
| 111 |
insert(v_Pixel, uint(S*(1.0-depth)/2.0), convert(frag) );
|
|
| 111 |
insert(v_Pixel, uint(S*(1.0-depth)/2.0), convert(color) );
|
|
| 112 | 112 |
} |
| 113 | 113 |
discard; |
| 114 | 114 |
} |
Also available in: Unified diff
Progress with non-postprocessed OIT.
Status: compiles, but fails to work on both Adreno and Mali. Crashes the app (Adreno) or the whole system (Mali)