Hardware accelerated ray-box intersection

版本 1.1.0.0 (55.4 KB) 作者: Thomas Seers
GPU portable implementation of the ray-box intersection method of Smits (1998)
557.0 次下载
更新时间 2015/2/13

查看许可证

% Ray-box intersection algorithm of Smit (1998) formatted for arrayfun to
% allow hardware acceleration:
% Smits, B. (1998). Efficiency issues for ray tracing. Journal of Graphics
% Tools, 3(2):1–14.
% Call with gpuarray and arrayfun to execute on the GPU: this
% may give two orders of magnitude speed up over vectorized
% cpu based implementation

% Ray box intersection is typically used to locate (axis aligned) spatial
% bins (e.g. octree bins / regular grid) to optimise ray-tracing (i.e. by
% reducing the number of potential triangles

% INPUT (scalar):
% orx, ory, orz: xyz componants of the ray origin
% Dx, Dy, Dz: xyz components of the ray directional (unit) vectors
% minx, miny, minz: xyz componants of the box minima
% maxx, maxy, maxz: xyz componants of the box maxima
% OUTPUT (scalar:
% tmin: minimum distance from from the ray-box intersection to the
% origin or nan if no intersection is located
% flag: 1 if intersection / 0 if no intersection

% Usage example:
% Step 1: convert mx3 direction vectors, D = [Dx Dy Dz] to gpuarray object
% >> gD = gpuArray(D);
% Step 2: call rayBoxGPU using arrayfun with scalar input formatting
% where min, max are the nx3 vertex lists of the box min-max corner points
% and where or is the xyz coordinates of the origin
% >> [tmin, flag] = arrayfun(@rayBoxGPU, min(:,1)', min(:,2)', min(:,3)', ...
% max(:,1)', max(:,2)', max(:,3)', ...
% or(:,1), or(:,2), or(:,3), ...
% gD(:,1),gD(:,2),gD(:,3));
% Step 3: recover data
% distmin = gather(tmin);
% flagBox = gather(flag);
% Output is one mxn array containing a the distance from the ray-box
% intersection to the origin or nan if no intersection is located (distmin)
% and one mxn logical containing flags for ray-box intersections.

% Per-ray flags can be obtained from the output tmin using the following
% method:
% >> flagB = true(size(D,1),1);
% >> flagB(sum(isnan(tmin),2) == size(min,1)) = false;
% This may save transfer time off the GPU

% Dependencies: requires Parallel Computing Toolbox
% Based upon the implementation by Jesus P. Mena-Chalco
% Test data (testDataBox.mat) is provided with the package

引用格式

Thomas Seers (2024). Hardware accelerated ray-box intersection (https://www.mathworks.com/matlabcentral/fileexchange/49671-hardware-accelerated-ray-box-intersection), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2013a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 GPU Computing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.1.0.0

Added acknowledgement to Paul Peeling's submission on FEX which the implementation takes from

1.0.0.0