@@ -1285,20 +1285,23 @@ protected void end2D() {
1285
1285
// SHADER FILTER
1286
1286
1287
1287
1288
+
1288
1289
@ Override
1289
1290
public void filter (PShader shader ) {
1290
1291
// The filter method needs to use the geometry-generation in the base class.
1291
1292
// We could re-implement it here, but this is easier.
1292
- if (!useParentImpl ) {
1293
- useOldP2D ();
1294
- super .filter (shader );
1295
- useNewP2D ();
1296
- } else {
1297
- super .filter (shader );
1298
- }
1293
+ // if (!useParentImpl) {
1294
+ // useOldP2D();
1295
+ // super.filter(shader);
1296
+ // useNewP2D();
1297
+ // } else {
1298
+ // super.filter(shader);
1299
+ // }
1300
+ super .filter (shader );
1299
1301
}
1300
1302
1301
1303
1304
+
1302
1305
//////////////////////////////////////////////////////////////
1303
1306
1304
1307
// SHADER API
@@ -1531,28 +1534,31 @@ private void init() {
1531
1534
private int vbo ;
1532
1535
private int texWidth , texHeight ;
1533
1536
1537
+ // Determination of the smallest increments and largest-greater-than-minus-one
1538
+ // https://en.wikipedia.org/wiki/Half-precision_floating-point_format
1539
+
1540
+ // Using the smallest positive normal number in half (16-bit) precision, which is how the depth
1541
+ // buffer is initialized in mobile
1542
+ private float smallestDepthIncrement = (float )Math .pow (2 , -14 );
1543
+
1544
+ // As the limit for the depth increase, we take the minus the largest number less than one in
1545
+ // half (16-bit) precision
1546
+ private float largestNumberLessThanOne = 1 - (float )Math .pow (2 , -11 );
1534
1547
1535
1548
private void incrementDepth () {
1536
- //by resetting the depth buffer when needed, we are able to have arbitrarily many
1537
- //layers, unlimited by depth buffer precision. in practice, the precision of this
1538
- //algorithm seems to be very good (~1,000,000 layers), so it pretty much won't happen
1539
- //unless you're drawing enough geometry per frame to set your computer on fire
1540
- if (depth < -0.9999f ) {
1549
+ // By resetting the depth buffer when needed, we are able to have arbitrarily many
1550
+ // layers, unlimited by depth buffer precision. In practice, the precision of this
1551
+ // algorithm seems to be acceptable (exactly (1 + 1 - pow(2, -11))/pow(2, -14) = 32,760 layers)
1552
+ // for mobile.
1553
+ if (depth < -largestNumberLessThanOne ) {
1541
1554
flushBuffer ();
1542
1555
pgl .clear (PGL .DEPTH_BUFFER_BIT );
1543
- //depth test will fail at depth = 1.0 after clearing the depth buffer,
1544
- //but since we always increment before drawing anything, this should be okay
1556
+ // Depth test will fail at depth = 1.0 after clearing the depth buffer,
1557
+ // But since we always increment before drawing anything, this should be okay
1545
1558
depth = 1.0f ;
1546
1559
}
1547
1560
1548
- //found to be a small but reliable increment value for a 24-bit depth buffer
1549
- //through trial and error. as numbers approach zero, absolute floating point
1550
- //precision increases, while absolute fixed point precision stays the same,
1551
- //so regardless of representation, this value should work for all depths in
1552
- //range (-1, 1), as long as it works for depths at either end of the range
1553
- depth -= 0.000001f ;
1554
-
1555
- //TODO: use an increment value based on good math instead of lazy trial-and-error
1561
+ depth -= smallestDepthIncrement ;
1556
1562
}
1557
1563
1558
1564
@@ -1694,6 +1700,10 @@ private PShader getShader() {
1694
1700
return shader ;
1695
1701
}
1696
1702
1703
+ @ Override
1704
+ protected PShader getPolyShader (boolean lit , boolean tex ) {
1705
+ return super .getPolyShader (lit , tex );
1706
+ }
1697
1707
1698
1708
private void setAttribs () {
1699
1709
pgl .vertexAttribPointer (positionLoc , 3 , PGL .FLOAT , false , vertSize , 0 );
0 commit comments