Cesium 官方有例 3D Tiles Clipping Planes
现在想让被剖切的部分透明而不是被舍弃discard。
我改后的示例,目前实现的是让被剖切的部分着色黄色,但其中颜色透明度未生效,不知道为何,望大神们予以解惑。
该页面中引用的Cesium.js我只做了简单的修改:
function clippingFunctionIntersect(clippingPlanesLength) {
var functionString =
'float clip(vec4 fragCoord, sampler2D clippingPlanes, mat4 clippingPlanesMatrix)\n' +
'{\n' +
' bool clipped = true;\n' +
' vec4 position = czm_windowToEyeCoordinates(fragCoord);\n' +
' vec3 clipNormal = vec3(0.0);\n' +
' vec3 clipPosition = vec3(0.0);\n' +
' float clipAmount = 0.0;\n' +
' float pixelWidth = czm_metersPerPixel(position);\n' +
' for (int i = 0; i < ' + clippingPlanesLength + '; ++i)\n' +
' {\n' +
' vec4 clippingPlane = getClippingPlane(clippingPlanes, i, clippingPlanesMatrix);\n' +
' clipNormal = clippingPlane.xyz;\n' +
' clipPosition = -clippingPlane.w * clipNormal;\n' +
' float amount = dot(clipNormal, (position.xyz - clipPosition)) / pixelWidth;\n' +
' clipAmount = max(amount, clipAmount);\n' +
' clipped = clipped && (amount <= 0.0);\n' +
' }\n' +
' if (clipped)\n' +
' {\n' +
// ' discard;\n' +//不满足裁剪 -> 半透明
' gl_FragColor = vec4(1.0,1.0,0.0,0.2);\n'+ //alpha通道 为毛没生效?
' }\n' +
' return clipAmount;\n' +
'}\n';
return functionString;
}
如上,只是将需要被剖切的执行操作discard;
改为了直接着色gl_FragColor = vec4(1.0,1.0,0.0,0.2);
,但如下图所示,颜色值的alpha通道并未生效。