How to fade instanced SOPs relative to camera?

So I have a geo that instances spheres that move towards the camera, but i’d like to set a fade for the instances relative to the camera.

If it’s too close to the camera i’d like the nearest instances to fade out, but if its too far i’d also like the furthest instances to fade out. So generally, there’s going to be a middle section that’ll be visible.

Any techniques that can do this? I’m assuming glsl or something may be required but not sure.

Perhaps some kind of bounding box to isolate the instances i want in a way where theres the ability to fade, or maybe could be done via materials?

Any help is greatly appreciated,

Ariel

Would be good to share something to get more precise feedback. Regardless, off the top of my head, you should be able to inform the alpha channels of the instances by comparing their positions to the camera’s ( you can get the camera’s position with object CHOP) and then some math or lookups to get a ramp in your falloff zones to apply to the instances’ alpha values.

Probably the trickiest part would be adapting to the orientation of the camera so that you are comparing a relative position of the instances from the camera’s frame of view. You can probably account for this by using Object CHOP’s reference/target functions, or using Transform CHOP to transform the object’s positions to be relative to the camera in order to compare the z from it’s point of view.

Shouldn’t need any GLSL for this, though you could do this sort of thing in a custom shader as well.

Thank you for the response, I’ve attached my project file here to demonstrate what I am going for.

Example.toe (5.9 KB)

I’ll respond with a follow up soon to show where I am at, I’ll try with the Object CHOP approach you mentioned. I feel like GLSL might be a quicker/smoother way but who knows, I appreciate the advice.

Resolved this finally, anyone curious you can do this via box fading with a glsl mat

in vec3 vWorldSpacePos;
out vec4 fragColor; 


uniform vec3 uBoxCenter; 
uniform vec3 uBoxScale;  
uniform float uSmoothness; 


float calculateBoxFade(vec3 pos, vec3 center, vec3 scale, float smoothness) {
    vec3 d = abs(pos - center) - scale;
    d = max(d, 0.0);

    float distOutside = length(d);

    return 1.0 - smoothstep(0.0, smoothness, distOutside);
}

void main() 
{
    float alpha = calculateBoxFade(vWorldSpacePos, uBoxCenter, uBoxScale, uSmoothness);

    fragColor = vec4(vec3(alpha), alpha);
}