#828 Eliminated the redundant position attributes for the line geometries. Like for meshes, re-used the original position attributes as the high parts of our encoding

This commit is contained in:
AlexandruPopovici
2022-07-27 22:54:45 +03:00
parent 3ca2d08e18
commit cc8580b8da
5 changed files with 13 additions and 25 deletions
+1 -3
View File
@@ -39,6 +39,4 @@ sandbox.makeGenericUI()
sandbox.makeSceneUI()
sandbox.makeFilteringUI()
// Load demo object
sandbox.loadUrl(
'https://speckle.xyz/streams/da9e320dad/commits/5388ef24b8?c=%5B-7.66134,10.82932,6.41935,-0.07739,-13.88552,1.8697,0,1%5D'
)
sandbox.loadUrl('https://latest.speckle.dev/streams/3ed8357f29/commits/d10f2af1ce')
@@ -182,6 +182,7 @@ export default class LineBatch implements Batch {
private makeLineGeometryTriangle(position: Float32Array): LineSegmentsGeometry {
const geometry = new LineSegmentsGeometry()
/** This will set the instanceStart and instanceEnd attributes. These will be our high parts */
geometry.setPositions(position)
const buffer = new Float32Array(position.length + position.length / 3)
@@ -285,7 +285,10 @@ export default class MeshBatch implements Batch {
}
if (position) {
/** When RTE enabled, we'll be storing the high component of the encoding here */
/** When RTE enabled, we'll be storing the high component of the encoding here,
* which considering our current encoding method is actually the original casted
* down float32 position!
*/
this.geometry.setAttribute('position', new Float32BufferAttribute(position, 3))
}
@@ -42,7 +42,11 @@ export class Geometry {
geometry.type === 'LineSegmentsGeometry'
) {
const position_low = new Float32Array(doublePositions.length)
const position_high = new Float32Array(doublePositions.length)
/** This is the default instanceStart + instanceEnd interleaved attribute buffer
* We're not altering it in reality since the high part of our encoding is the
* original position double value casted down to float
*/
const position_high = geometry.attributes.instanceStart.array as Float32Array
Geometry.DoubleToHighLowBuffer(doublePositions, position_low, position_high)
@@ -59,20 +63,6 @@ export class Geometry {
'instanceEndLow',
new InterleavedBufferAttribute(instanceBufferLow, 3, 3)
) // xyz
const instanceBufferHigh = new InstancedInterleavedBuffer(
new Float32Array(position_high),
6,
1
) // xyz, xyz
geometry.setAttribute(
'instanceStartHigh',
new InterleavedBufferAttribute(instanceBufferHigh, 3, 0)
) // xyz
geometry.setAttribute(
'instanceEndHigh',
new InterleavedBufferAttribute(instanceBufferHigh, 3, 3)
) // xyz
}
}
@@ -46,12 +46,8 @@ export const speckleLineVert = /* glsl */ `
#endif
#ifdef USE_RTE
// attribute vec3 position_high;
// attribute vec3 position_low;
attribute vec3 instanceStartLow;
attribute vec3 instanceStartHigh;
attribute vec3 instanceEndLow;
attribute vec3 instanceEndHigh;
uniform vec3 uViewer_high;
uniform vec3 uViewer_low;
#endif
@@ -106,14 +102,14 @@ export const speckleLineVert = /* glsl */ `
/** Source https://github.com/virtualglobebook/OpenGlobe/blob/master/Source/Examples/Chapter05/Jitter/GPURelativeToEyeDSFUN90/Shaders/VS.glsl */
vec3 t1 = instanceStartLow.xyz - uViewer_low;
vec3 e = t1 - instanceStartLow.xyz;
vec3 t2 = ((-uViewer_low - e) + (instanceStartLow.xyz - (t1 - e))) + instanceStartHigh.xyz - uViewer_high;
vec3 t2 = ((-uViewer_low - e) + (instanceStartLow.xyz - (t1 - e))) + instanceStart.xyz - uViewer_high;
vec3 highDifference = t1 + t2;
vec3 lowDifference = t2 - (highDifference - t1);
vec4 start = modelViewMatrix * vec4(highDifference.xyz + lowDifference.xyz , 1.);
t1 = instanceEndLow.xyz - uViewer_low;
e = t1 - instanceEndLow.xyz;
t2 = ((-uViewer_low - e) + (instanceEndLow.xyz - (t1 - e))) + instanceEndHigh.xyz - uViewer_high;
t2 = ((-uViewer_low - e) + (instanceEndLow.xyz - (t1 - e))) + instanceEnd.xyz - uViewer_high;
highDifference = t1 + t2;
lowDifference = t2 - (highDifference - t1);
vec4 end = modelViewMatrix * vec4(highDifference.xyz + lowDifference.xyz , 1.);