Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions synanno/static/SharkViewer/shark_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,8 @@ import {
}
});

this.trackControls.addEventListener("change", this.updateCameraDistance.bind(this));

this.raycaster.params.Points.threshold = DEFAULT_POINT_THRESHOLD;
this.raycaster.params.Line.threshold = DEFAULT_LINE_THRESHOLD;

Expand Down Expand Up @@ -957,6 +959,28 @@ import {
this.render();
}

getCameraDistance() {
if (!this.camera || !this.trackControls) {
return 1.0;
}
return this.camera.position.distanceTo(this.trackControls.target);
}

updateCameraDistance() {
if (!this.camera || !this.scene) return;

const cameraDistance = this.getCameraDistance();

this.scene.traverse((node) => {
if (node.material?.uniforms?.cameraDistance) {
node.material.uniforms.cameraDistance.value = cameraDistance;
node.material.uniforms.cameraDistance.needsUpdate = true;
}
});

console.log("Updated cameraDistance in shader:", cameraDistance);
}

// render the scene
render() {
if (this.postprocessing.enabled) {
Expand Down
28 changes: 19 additions & 9 deletions synanno/static/shaders/ConeShader.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
const ConeShader = {
uniforms: {
sphereTexture: { value: null }, // Texture for 3D shading
sphereTexture: { value: null },
cameraDistance: { value: 1.0 },
},

vertexShader: /* glsl */ `
uniform float cameraDistance;
attribute float radius;
attribute float grey_out; // Now a per-instance attribute
attribute float grey_out;

varying vec2 sphereUv;
varying vec4 mvPosition;
varying float depthScale;
varying vec3 vColor;
varying float vGreyOut; // Pass to frprojectionMatrixagment shader
varying float vGreyOut;

void main()
{
vColor = color; // Keep region-based coloring
vGreyOut = grey_out; // Pass grey-out status
vColor = color;
vGreyOut = grey_out;

mvPosition = modelViewMatrix * vec4(position, 1.0);
vec3 cylAxis = (modelViewMatrix * vec4(normal, 0.0)).xyz;
vec3 sideDir = normalize(cross(vec3(0.0,0.0,-1.0), cylAxis));
mvPosition += vec4(radius * sideDir, 0.0);

float clampedDistance = clamp(cameraDistance, 500.0, 100000.0);

float t = 1.0 - exp(-((clampedDistance - 500.0) / 15000.0));

float baseScale = mix(120.0, 5.0, t);

float adjustedRadius = clamp(radius * (baseScale / 100.0), 10.0, 100.0);

mvPosition += vec4(adjustedRadius * sideDir, 0.0);
gl_Position = projectionMatrix * mvPosition;

sphereUv = uv - vec2(0.5, 0.5);
Expand All @@ -36,7 +47,7 @@ const ConeShader = {

float foreshortening = length(cylAxis) / length(cylAxis.xy);
if (foreshortening > 4.0) foreshortening = 0.9;
depthScale = radius * foreshortening;
depthScale = adjustedRadius * foreshortening;
}
`,

Expand All @@ -47,7 +58,7 @@ const ConeShader = {
varying vec4 mvPosition;
varying float depthScale;
varying vec3 vColor;
varying float vGreyOut; // Get from vertex shader
varying float vGreyOut;

void main()
{
Expand All @@ -59,7 +70,6 @@ const ConeShader = {

float finalAlpha = sphereColors.a;

// Apply greying out if vGreyOut is active
if (vGreyOut > 0.5) {
highlightColor = vec3(dot(highlightColor, vec3(0.299, 0.587, 0.114)));
finalAlpha *= 0.3;
Expand Down
62 changes: 34 additions & 28 deletions synanno/static/shaders/ParticleShader.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,68 @@
const ParticleShader = {
uniforms: {
cameraDistance: { value: 1.0 },
particleScale: { value: 1.0 },
sphereTexture: { value: null },
abstraction_threshold: { value: 0.0 },

},

vertexShader: /* glsl */ `
uniform float cameraDistance;
uniform float particleScale;
attribute float radius;
attribute float grey_out; // Per-instance attribute
attribute float grey_out;

varying vec4 mvPosition;
varying vec3 vColor;
varying float vRadius;
varying float vGreyOut; // Pass to fragment shader
varying float vGreyOut;

void main()
{
mvPosition = modelViewMatrix * vec4(position, 1.0);
gl_PointSize = radius * ((particleScale * 2.5) / length(mvPosition.z));

float clampedDistance = clamp(cameraDistance, 500.0, 100000.0);

float t = 1.0 - exp(-((clampedDistance - 500.0) / 15000.0));

float baseScale = mix(100.0, 1.0, t);

gl_PointSize = clamp(radius * (baseScale / 100.0), 10.0, 50.0);



vColor = color;
vRadius = radius;
vGreyOut = grey_out; // Pass grey-out status
vGreyOut = grey_out;

gl_Position = projectionMatrix * mvPosition;
}
`,

fragmentShader: /* glsl */ `
uniform sampler2D sphereTexture;
varying vec3 vColor;
varying vec4 mvPosition;
varying float vGreyOut; // Get from vertex shader
uniform sampler2D sphereTexture;
varying vec3 vColor;
varying float vGreyOut;

void main()
{
vec3 baseColor = vColor;
vec2 uv = vec2(gl_PointCoord.x, 1.0 - gl_PointCoord.y);
vec4 sphereColors = texture2D(sphereTexture, uv);

void main()
{
vec3 baseColor = vColor;
vec2 uv = vec2(gl_PointCoord.x, 1.0 - gl_PointCoord.y);
vec4 sphereColors = texture2D(sphereTexture, uv);
if (sphereColors.a < 0.3) discard;

if (sphereColors.a < 0.3) discard;
baseColor = mix(baseColor, baseColor * sphereColors.r, 0.75);
baseColor += sphereColors.ggg * 0.6;

baseColor = mix(baseColor, baseColor * sphereColors.r, 0.75);
baseColor += sphereColors.ggg * 0.6;
float finalAlpha = sphereColors.a;

float finalAlpha = sphereColors.a;
if (vGreyOut > 0.5) {
baseColor = vec3(dot(baseColor, vec3(0.299, 0.587, 0.114)));
finalAlpha *= 0.3;
}

// Apply greying out if vGreyOut is active
if (vGreyOut > 0.5) {
baseColor = vec3(dot(baseColor, vec3(0.299, 0.587, 0.114)));
finalAlpha *= 0.3;
gl_FragColor = vec4(baseColor, finalAlpha);
}

gl_FragColor = vec4(baseColor, finalAlpha);
}
`
`
};

export { ParticleShader };
Loading