0
$\begingroup$

I'm currently visualizing scientific data as volumes using Three and GLSL. I have a raymarching script that is pretty standard and colors based on a colormap I feed into the shader.

It looks like this

enter image description here

I want to be able to slice through the data using the slice sliders. However, I'm not certain how to implement this in my raymarching script. I originally had it discard fragments with positions less than the slice sliders. However, that method discards all rays if the camera is also positioned to the negative of that slice value. Not to mention it won't show me the side of the volume.

Here is the main of my shader.

void main(){
    vec3 rayDir = normalize( vDirection );
    vec2 bounds = hitBox( vOrigin, rayDir );

    if ( bounds.x > bounds.y ) discard;

    bounds.x = max( bounds.x, 0.0 );

    vec3 p = vOrigin + bounds.x * rayDir;
    vec3 inc = 1.0 / abs( rayDir );
    float delta = min( inc.x, min( inc.y, inc.z ) );
    delta /= steps;

    for ( float t = bounds.x; t < bounds.y; t += delta ) {

        float d = sample1( p/scaleVec/scale + 0.5 );
        bool cond = d > threshold;
        cond = flip ? !cond: cond;

        if ( cond ) {
            color.rgb = texture2D(cmap, vec2(d, 0.5)).rgb;
            color.a = 1.;

            break;
        }

        p += rayDir * delta;

    }

    if ( color.a == 0.0 ) discard;

}

What is the correct way to be able to slice this while also seeing the side of the volume?

$\endgroup$

1 Answer 1

2
$\begingroup$

I was over thinking it.

Instead of discarding it, I needed to just let the ray keep marching.

adding

if (p.x < xSlicer.x){
       p += rayDir * delta;
       continue;
   }

To the top of the for loop fixed it.

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.