Skip to content

Commit bb650bf

Browse files
committed
updated shaders to use a constant scale and set depthTest and depthWrite
1 parent 93912ba commit bb650bf

4 files changed

Lines changed: 28 additions & 23 deletions

File tree

synanno/static/shaders/ConeShader.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const ConeShader = {
2121
mvPosition = modelViewMatrix * vec4(position, 1.0);
2222
vec3 cylAxis = (modelViewMatrix * vec4(normal, 0.0)).xyz;
2323
vec3 sideDir = normalize(cross(vec3(0.0,0.0,-1.0), cylAxis));
24-
mvPosition += vec4(radius * sideDir, 0.0);
24+
mvPosition += vec4(radius * 0.30 * sideDir, 0.0);
2525
gl_Position = projectionMatrix * mvPosition;
2626
2727
sphereUv = uv - vec2(0.5, 0.5);
@@ -34,9 +34,8 @@ const ConeShader = {
3434
sphereUv = rotMat * sphereUv;
3535
sphereUv += vec2(0.5, 0.5);
3636
37-
float foreshortening = length(cylAxis) / length(cylAxis.xy);
38-
if (foreshortening > 4.0) foreshortening = 0.9;
39-
depthScale = radius * foreshortening;
37+
// Maintain constant scale
38+
depthScale = radius;
4039
}
4140
`,
4241

synanno/static/shaders/ParticleShader.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ const ParticleShader = {
1919
void main()
2020
{
2121
mvPosition = modelViewMatrix * vec4(position, 1.0);
22-
gl_PointSize = radius * ((particleScale * 2.5) / length(mvPosition.z));
22+
23+
// Keep particle size constant in screen space
24+
gl_PointSize = (radius * 600.0) / -mvPosition.z;
2325
2426
vColor = color;
2527
vRadius = radius;

synanno/static/shaders/SynapseShader.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const SynapseShader = {
33
sphereTexture: { value: null },
44
particleScale: { value: 1.0 },
55
},
6-
vertexShader: `
6+
vertexShader: /* glsl */ `
77
uniform float particleScale;
88
attribute float radius;
99
attribute float alpha;
@@ -12,16 +12,17 @@ const SynapseShader = {
1212
1313
void main() {
1414
vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
15-
float depthScale = -mvPosition.z / 1000.0; // Normalize depth scale
16-
gl_PointSize = clamp(radius * (particleScale / depthScale), 10.0, 20.0);
15+
16+
// Adjust point size based on perspective projection
17+
gl_PointSize = clamp(radius * 2.5 / -mvPosition.z, 10.0, 20.0);
1718
1819
gl_Position = projectionMatrix * mvPosition;
1920
2021
vColor = color;
2122
vAlpha = alpha;
2223
}
2324
`,
24-
fragmentShader: `
25+
fragmentShader: /* glsl */ `
2526
uniform sampler2D sphereTexture;
2627
varying vec3 vColor;
2728
varying float vAlpha;

synanno/static/viewer.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,14 @@ function processSynapseCloudData(data, maxVolumeSize, activeSynapseIDs, initialL
178178
if (activeSynapseIDs.length > 0) {
179179
sizes[i] = activeSynapseIDs.includes(i) ? maxVolumeSize : 10;
180180

181-
window.synapseColors[i] === "green" || window.synapseColors[i] === "red" ? 0.7 : 0.3;
182-
alphas[i] = activeSynapseIDs.includes(i) ? 0.8 : 0.3;
181+
window.synapseColors[i] === "green" || window.synapseColors[i] === "red" ? 1.0 : 0.4;
182+
alphas[i] = activeSynapseIDs.includes(i) ? 1.0 : 0.4;
183183
} else if (initialLoad) {
184184
sizes[i] = 10;
185-
alphas[i] = 0.8;
185+
alphas[i] = 1.0;
186186
} else {
187187
sizes[i] = 10;
188-
alphas[i] = 0.1;
188+
alphas[i] = 0.4;
189189
}
190190
}
191191

@@ -210,8 +210,11 @@ function processSynapseCloudData(data, maxVolumeSize, activeSynapseIDs, initialL
210210
uniforms: SynapseShader.uniforms,
211211
vertexShader: SynapseShader.vertexShader,
212212
fragmentShader: SynapseShader.fragmentShader,
213-
transparent: true,
214213
vertexColors: true,
214+
transparent: true,
215+
depthTest: true, // Objects still get depth-culled
216+
depthWrite: false, // Prevents particles from overwriting depth buffer
217+
renderOrder: 2
215218
});
216219

217220
const pointsMesh = new THREE.Points(geometry, material);
@@ -584,15 +587,15 @@ function createMetadataElement(metadata, colors, activeNeuronSection) {
584587
} else {
585588
// Proceed only if the lock is free
586589
fetch(`/retrieve_first_page_of_section/${sectionIndex}`)
587-
.then(response => response.json())
588-
.then(data => {
589-
if (data.page) {
590-
window.location.href = `/annotation/${data.page}`;
591-
} else {
592-
alert("Failed to retrieve section page.");
593-
}
594-
})
595-
.catch(error => console.error("Error fetching first page:", error));
590+
.then(response => response.json())
591+
.then(data => {
592+
if (data.page) {
593+
window.location.href = `/annotation/${data.page}`;
594+
} else {
595+
alert("Failed to retrieve section page.");
596+
}
597+
})
598+
.catch(error => console.error("Error fetching first page:", error));
596599
}
597600
})
598601
.catch(error => console.error("Error checking metadata lock:", error));

0 commit comments

Comments
 (0)