nro*_*rob 3 shader gpu opengl-es glsl webgl
我们编写了GLSL着色器代码,使用GPU进行光线跟踪可视化.在光线行进循环中提前退出中断似乎是非常标准的,因此如果光线熄灭,则循环中断.
但根据我对GPU代码的了解,每次渲染都需要与最长的循环运行一样长.所以我的问题是:是否值得提前退出?
例如
for(int i = 0; i < MAX_STEPS; i++){
//Get the voxel intensity value from the 3D texture.
dataRGBA = getRGBAfromDataTex(dataTexture, currentPosition, dataShape, textureShape);
// get contribution from the light
lightRayPathRGBA = getPathRGBA(currentPosition, light.position, steps, tex); // this is the light absorbed so we need to take 1.0- to get the light transmitted
lightRayRGBA = (vec4(1.0) - lightRayPathRGBA) * vec4(light.color, light.intensity);
apparentRGB = (1.0 - accumulatedAlpha) * dataRGBA.rgb * lightRayRGBA.rgb * dataRGBA.a * lightRayRGBA.a;
//apparentRGB = (1.0 - accumulatedAlpha) * dataRGBA.rgb * dataRGBA.a * lightRayRGBA.a;
//Perform the composition.
accumulatedColor += apparentRGB;
//Store the alpha accumulated so far.
accumulatedAlpha += dataRGBA.a;
//Adva nce 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;
}
}
Run Code Online (Sandbox Code Playgroud)
GPU的调度单元是warp/wavefront.通常是32或64个线程的连续组.warp的执行时间是该warp中所有线程的执行时间的最大值.
因此,如果您提前退出可以使整个warp更快终止(例如,如果线程0到31 都采用提前退出),那么是的,这是值得的,因为硬件可以安排另一个warp来执行,这会降低整体内核运行时间.否则,它可能不是,因为即使线程1到31采用提前退出,warp仍然占用硬件,直到线程0完成.
| 归档时间: |
|
| 查看次数: |
645 次 |
| 最近记录: |