Hardware accelerated ray-box intersection

GPU portable implementation of the ray-box intersection method of Smits (1998)
553 téléchargements
Mise à jour 13 fév. 2015

Afficher la licence

% 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

Citation pour cette source

Thomas Seers (2024). Hardware accelerated ray-box intersection (https://www.mathworks.com/matlabcentral/fileexchange/49671-hardware-accelerated-ray-box-intersection), MATLAB Central File Exchange. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2013a
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux
En savoir plus sur GPU Computing dans Help Center et MATLAB Answers

Inspiré par : Ray/box Intersection, RayShapeArticle_FEX.zip

Community Treasure Hunt

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

Start Hunting!
Version Publié le Notes de version

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