Three.js 在三个.Js中剪切一个卷,给出黑色区域而不是内部材质
我正试图从三个平面中剪裁一个体积,以观察内部结构 剪裁是在片段着色器中完成的,如果超出剪裁限制,则丢弃像素的图形:Three.js 在三个.Js中剪切一个卷,给出黑色区域而不是内部材质,three.js,rendering,clipping,Three.js,Rendering,Clipping,我正试图从三个平面中剪裁一个体积,以观察内部结构 剪裁是在片段着色器中完成的,如果超出剪裁限制,则丢弃像素的图形: gl_FragColor = accumulatedColor; if(worldSpaceCoords.x < xClippingPlaneMin) discard; if(worldSpaceCoords.x < xClippingPlaneMin) discard; if(worldSpaceCoords.z < zClippingPlaneMin) d
gl_FragColor = accumulatedColor;
if(worldSpaceCoords.x < xClippingPlaneMin) discard;
if(worldSpaceCoords.x < xClippingPlaneMin) discard;
if(worldSpaceCoords.z < zClippingPlaneMin) discard;
if(worldSpaceCoords.z > zClippingPlaneMax) discard;
if(worldSpaceCoords.y < yClippingPlaneMin) discard;
if(worldSpaceCoords.y > yClippingPlaneMax) discard;
它看起来像是这样的黑色边界,我想把它作为渲染曲面。
更新:我的动机是分别从所有三个方向平面X、Y和Z查看体积剪裁内部。你也可以考虑切片,就像我想查看某个切片的体积一样
我研究了这些示例,但它们没有多大用处,因此使用了基于坐标的丢弃和剪裁方法来实现我的目标。如前所述,您的方法存在的问题是,通过丢弃碎片着色器上的像素,您根本无法对其进行渲染
正确的方法是,如果光线位置在剪裁框之外,则防止光线移动累积颜色和alpha。剪辑框坐标必须在[0,1]空间内
bool withinBoundaries( vec3 pos ) {
if (
pos.x < xClippingPlaneMin ||
pos.y < yClippingPlaneMin ||
pos.z < zClippingPlaneMin ||
pos.x > xClippingPlaneMax ||
pos.y > yClippingPlaneMax ||
pos.z > zClippingPlaneMax
) return false;
return true;
}
// ...
//Perform the ray marching iterations
for( int i = 0; i < MAX_STEPS; i++) {
// ...
if ( withinBoundaries( currentPosition ) ) {
//Perform the composition.
accumulatedColor += colorSample * alphaSample;
//Store the alpha accumulated so far.
accumulatedAlpha += alphaSample;
}
// ...
}
bool带边界(vec3位置){
如果(
位置xxClippingPlaneMax||
位置y>yClippingPlaneMax||
位置z>zClippingPlaneMax
)返回false;
返回true;
}
// ...
//执行光线行进迭代
对于(int i=0;i
bool withinBoundaries( vec3 pos ) {
if (
pos.x < xClippingPlaneMin ||
pos.y < yClippingPlaneMin ||
pos.z < zClippingPlaneMin ||
pos.x > xClippingPlaneMax ||
pos.y > yClippingPlaneMax ||
pos.z > zClippingPlaneMax
) return false;
return true;
}
// ...
//Perform the ray marching iterations
for( int i = 0; i < MAX_STEPS; i++) {
// ...
if ( withinBoundaries( currentPosition ) ) {
//Perform the composition.
accumulatedColor += colorSample * alphaSample;
//Store the alpha accumulated so far.
accumulatedAlpha += alphaSample;
}
// ...
}