Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 2319abe
  • /
  • src
  • /
  • optix
  • /
  • raytrace.cu
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:ecbb951d67a5be73872815d6e2c2417dfede043f
directory badge
swh:1:dir:596fcd9018d1903061e1b5c4c487927eb3fb8945

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
raytrace.cu
/*
 * Copyright (c) 2021-2022, NVIDIA CORPORATION.  All rights reserved.
 *
 * NVIDIA CORPORATION and its licensors retain all intellectual property
 * and proprietary rights in and to this software, related documentation
 * and any modifications thereto.  Any use, reproduction, disclosure or
 * distribution of this software and related documentation without an express
 * license agreement from NVIDIA CORPORATION is strictly prohibited.
 */

/** @file   raytrace.cu
 *  @author Thomas Müller, NVIDIA
 *  @brief  Minimal optix program.
 */

#include <neural-graphics-primitives/common_device.cuh>

#include <optix.h>

#include "raytrace.h"

namespace ngp {

extern "C" __constant__ char params_data[sizeof(Raytrace::Params)];

extern "C" __global__ void __raygen__rg() {
	const auto* params = (Raytrace::Params*)params_data;

	const uint3 idx = optixGetLaunchIndex();
	const uint3 dim = optixGetLaunchDimensions();

	vec3 ray_origin = params->ray_origins[idx.x];
	vec3 ray_direction = params->ray_directions[idx.x];

	unsigned int p0, p1;
	optixTrace(
		params->handle,
		to_float3(ray_origin),
		to_float3(ray_direction),
		0.0f,                // Min intersection distance
		1e16f,               // Max intersection distance
		0.0f,                // rayTime -- used for motion blur
		OptixVisibilityMask(255), // Specify always visible
		OPTIX_RAY_FLAG_DISABLE_ANYHIT,
		0,                   // SBT offset
		1,                   // SBT stride
		0,                   // missSBTIndex
		p0, p1
	);

	// Hit position
	float t = __int_as_float(p1);
	params->ray_origins[idx.x] = ray_origin + t * ray_direction;

	// If a triangle was hit, p0 is its index, otherwise p0 is -1.
	// Write out the triangle's normal if it (abuse the direction buffer).
	if ((int)p0 == -1) {
		return;
	}

	params->ray_directions[idx.x] = params->triangles[p0].normal();
}

extern "C" __global__ void __miss__ms() {
	optixSetPayload_0((uint32_t)-1);
	optixSetPayload_1(__float_as_int(optixGetRayTmax()));
}

extern "C" __global__ void __closesthit__ch() {
	optixSetPayload_0(optixGetPrimitiveIndex());
	optixSetPayload_1(__float_as_int(optixGetRayTmax()));
}

}

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API