feat: add point-cloud sphere layer

Render the icosphere vertices as rounded points sharing the skin's
displacement and colormap, switched by a renderMode uniform and
toggled with key 3.
This commit is contained in:
L'électron rare
2026-05-18 17:32:29 +02:00
parent 9b82a90579
commit a8be68adff
5 changed files with 25 additions and 0 deletions
@@ -3,6 +3,7 @@
uniform sampler2D spectroTex; // width = time, height = freq, R32F [0,1]
uniform float scrollOffset;
uniform int colormapId;
uniform int renderMode; // 0 = skin, 1 = points
in vec2 vSphereUV;
out vec4 fragColor;
@@ -33,5 +34,9 @@ void main() {
float u = fract(vSphereUV.x - scrollOffset);
float mag = clamp(texture(spectroTex, vec2(u, vSphereUV.y)).r, 0.0, 1.0);
vec3 col = (colormapId == 0) ? magma(mag) : viridis(mag);
if (renderMode == 1) {
vec2 d = gl_PointCoord - vec2(0.5);
if (dot(d, d) > 0.25) discard; // round the points
}
fragColor = vec4(col, 1.0);
}
@@ -4,6 +4,7 @@ uniform mat4 modelViewProjectionMatrix;
uniform sampler2D waveformTex; // width = samples, height = 2 (row0 CH1, row1 CH2)
uniform float displaceAmount;
uniform float baseRadius;
uniform int renderMode; // 0 = skin, 1 = points
in vec4 position;
@@ -21,5 +22,8 @@ void main() {
float r = baseRadius * (1.0 + displaceAmount * wave);
gl_Position = modelViewProjectionMatrix * vec4(dir * r, 1.0);
if (renderMode == 1) {
gl_PointSize = 3.0;
}
vSphereUV = vec2(lon, lat);
}
+14
View File
@@ -74,6 +74,20 @@ void SphereViz::drawSkin() {
shader_.setUniform1f("displaceAmount", displace_);
shader_.setUniform1f("baseRadius", baseRadius_);
shader_.setUniform1i("colormapId", colormapId_);
shader_.setUniform1i("renderMode", 0);
mesh_.draw();
shader_.end();
}
void SphereViz::drawPoints() {
shader_.begin();
shader_.setUniformTexture("spectroTex", spectroTex_, 0);
shader_.setUniformTexture("waveformTex", waveTex_, 1);
shader_.setUniform1f("scrollOffset", scrollOffset_);
shader_.setUniform1f("displaceAmount", displace_);
shader_.setUniform1f("baseRadius", baseRadius_);
shader_.setUniform1i("colormapId", colormapId_);
shader_.setUniform1i("renderMode", 1);
mesh_.drawVertices();
shader_.end();
}
+1
View File
@@ -18,6 +18,7 @@ public:
const std::vector<float>& ch2);
void drawSkin();
void drawPoints();
void setColormap(int id) { colormapId_ = id; }
private:
+1
View File
@@ -56,6 +56,7 @@ void ofApp::draw() {
ofPushMatrix();
ofRotateYDeg(ofGetElapsedTimef() * 6.0f);
if (layerA_) sphere_.drawSkin();
if (layerC_) sphere_.drawPoints();
if (layerB_) rings_.draw();
ofPopMatrix();
cam_.end();