1

我指的是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;

        }

在此处输入图像描述

这是我对 X 射线模式渲染以及生成的图像进行更改的代码。 在此处输入图像描述

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;

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

4

0 回答 0