GL Shader โ€“ Possible to render in specific Rhino viewport?

Hello,

I would like to know whether the GL Shader component can be configured to display its output in a specific Rhino viewport only, rather than rendering the GL result in all viewports simultaneously.

My goal is to control the visibility of the GL shader output on a per-viewport basis (for example, showing it only in the Perspective view while hiding it in Top/Front/Right views).

Is this currently supported by the GL Shader component, or would it require a different approach (such as a custom DisplayConduit or plugin-level solution)?

Thank you very much for any clarification or guidance.

vp_glsl.gh (9.2 KB)

GhGL does not currently support this functionality. The project is open source though and code changes are welcome if someone wants to add this

2 Likes

@stevebaer Oh wellโ€ฆ

Could there be any possible workaround method that can do the trick?

Hi @stevebaer,

So this is what I came up so far, I use camera_location and camera_vector to filter.
The disadvantage is the camera info needs to be update whenever view alter.

In Fragment:

#version 330

// --- External Inputs ---
uniform vec3 camera_location;
uniform vec3 camera_vector;

// --- Built-in Uniforms ---
uniform mat4 _worldToCamera;
uniform vec3 _cameraLocation;

in vec4 vertex_color;
out vec4 fragment_color;

void main() {
    // 1. Activation Check
    // If the input vector is (0,0,0), it means no valid plane is assigned.
    // In this case, we show the object in all viewports.
    if (length(camera_vector) < 0.001) {
        fragment_color = vertex_color;
        return; 
    }

    // 2. Safety Check: Handle Rhino focus loss (prevents flickering)
    if (_cameraLocation == vec3(0.0) && _worldToCamera[0][0] == 0.0) {
        fragment_color = vertex_color;
        return;
    }

    // 3. Direction Filtering
    vec3 currentViewDir = normalize(vec3(_worldToCamera[0][2], _worldToCamera[1][2], _worldToCamera[2][2]));
    vec3 targetDir = normalize(camera_vector);
    float dirMatch = abs(dot(currentViewDir, targetDir));

    // 4. Location Filtering (distMatch)
    vec3 v = _cameraLocation - camera_location;
    vec3 projection = v - dot(v, targetDir) * targetDir;
    float distMatch = length(projection);

    // 5. Strict Filtering Logic
    // If aligned with target viewport, render. Otherwise, discard.
    if (dirMatch < 0.999 || distMatch > 0.1) {
        discard;
    }

    // 6. Final Output
    fragment_color = vertex_color;
}