你怎麼能這樣光線追蹤的點雲與three.js所定製的頂點着色器。 ,光線追蹤點雲用自定義的頂點着色器在three.js所
function testPoint(point, index) {
var rayPointDistanceSq = ray.distanceSqToPoint(point);
if (rayPointDistanceSq < localThresholdSq) {
var intersectPoint = ray.closestPointToPoint(point);
intersectPoint.applyMatrix4(matrixWorld);
var distance = raycaster.ray.origin.distanceTo(intersectPoint);
if (distance < raycaster.near || distance > raycaster.far) return;
intersects.push({
distance: distance,
distanceToRay: Math.sqrt(rayPointDistanceSq),
point: intersectPoint.clone(),
index: index,
face: null,
object: object
});
}
}
var vertices = geometry.vertices;
for (var i = 0, l = vertices.length; i < l; i ++) {
testPoint(vertices[ i ], i);
}
但是,由於我使用的是頂點着色器,該geometry.vertices:
這是我的頂點着色器
void main() {
vUvP = vec2(position.x/(width*2.0), position.y/(height*2.0)+0.5);
colorP = vec2(position.x/(width*2.0)+0.5 , position.y/(height*2.0) );
vec4 pos = vec4(0.0,0.0,0.0,0.0);
depthVariance = 0.0;
if ((vUvP.x<0.0)|| (vUvP.x>0.5) || (vUvP.y<0.5) || (vUvP.y>0.0)) {
vec2 smp = decodeDepth(vec2(position.x, position.y));
float depth = smp.x;
depthVariance = smp.y;
float z = -depth;
pos = vec4((position.x/width - 0.5) * z * (1000.0/focallength) * -1.0,(position.y/height - 0.5) * z * (1000.0/focallength),(- z + zOffset/1000.0) * 2.0,1.0);
vec2 maskP = vec2(position.x/(width*2.0), position.y/(height*2.0) );
vec4 maskColor = texture2D(map, maskP);
maskVal = (maskColor.r + maskColor.g + maskColor.b)/3.0 ;
}
gl_PointSize = pointSize;
gl_Position = projectionMatrix * modelViewMatrix * pos;
}
在積分類,光線追蹤是這樣實現的不匹配屏幕上防止射線痕跡工作的頂點。
我們可以得到點從頂點着色器回來?
謝謝!我會在未來爲所有嘗試這個的人添加。在頂點着色器中,您可以設置一個變化的,然後您可以在片段着色器中使用它來設置頂點的顏色 – cjds