从简单光线投射转换为X射线渲染

时间:2018-02-12 23:12:56

标签: three.js raycasting volume-rendering webgl2

我指的是Lebarba代码用于体积渲染。我想要做的是X射线渲染而不是光线投射。

以下是使用代码

进行Ray强制转换的结果

光线投射

             for(int i = 0; i < MAX_STEPS; i++)
               {
                //Get the voxel intensity value from the 3D texture.
                colorSample = sampleAs3DTexture( currentPosition );

                //Allow the alpha correction customization.
                alphaSample = colorSample.a * alphaCorrection;

                //Applying this effect to both the color and alpha accumulation results in more realistic transparency.
                alphaSample *= (1.0 - accumulatedAlpha);

                //Scaling alpha by the number of steps makes the final color invariant to the step size.
                alphaSample *= alphaScaleFactor;

                //Perform the composition.
                accumulatedColor += colorSample * alphaSample;

                //Store the alpha accumulated so far.
                accumulatedAlpha += alphaSample;

                //Advance the ray.
                currentPosition += deltaDirection;
                accumulatedLength += deltaDirectionLength;

                //If the length traversed is more than the ray length, or if the alpha accumulated reaches 1.0 then exit.
                if(accumulatedLength >= rayLength || accumulatedAlpha >= 1.0 )
                    break;
            }

            gl_FragColor  = accumulatedColor;

        }

enter image description here

以下是我对X射线模式渲染进行了更改的代码以及生成的图像。 enter image description here

X射线模式

     for(int i = 0; i < MAX_STEPS; i++)
            {
                //Get the voxel intensity value from the 3D texture.
                colorSample = sampleAs3DTexture( currentPosition );


            //console.log(colorSample);

                    //Allow the alpha correction customization.
                alphaSample = colorSample.a * alphaCorrection;

                //Applying this effect to both the color and alpha accumulation results in more realistic transparency.
                alphaSample *= (1.0 - accumulatedAlpha);

                //Scaling alpha by the number of steps makes the final color invariant to the step size.
                alphaSample *= alphaScaleFactor;

                //Perform the composition.
                //accumulatedColor += colorSample/float(887);
                accumulatedColor = accumulatedColor + colorSample/float(MAX_STEPS);

                //Store the alpha accumulated so far.
                accumulatedAlpha += alphaSample;

                //Advance the ray.
                currentPosition += deltaDirection;
                accumulatedLength += deltaDirectionLength;

                //If the length traversed is more than the ray length, or if the alpha accumulated reaches 1.0 then exit.
                if(accumulatedLength >= rayLength || accumulatedAlpha >= 1.0 )
                    break;
            }

            gl_FragColor  = accumulatedColor;

我不确定我所做的是对还是错,因为我是这个领域的新手。 如果有人可以指出错误,那将是非常有帮助的。

0 个答案:

没有答案