28 #define STB_IMAGE_WRITE_IMPLEMENTATION 33 #if defined(TACHYON_USEPINNEDMEMORY) 34 #include <cuda_runtime.h> 41 float * coords = (
float *) malloc(points * 3 *
sizeof(
float));
44 for (i=0; i<points; i++) {
45 float theta = 2.0f *
M_PI * float(i) / float(points);
46 float r = 2.0f + cos(p * theta);
48 coords[ind ] = r * cos(q * theta);
49 coords[ind + 1] = r * sin(q * theta);
50 coords[ind + 2] = -sin(p * theta);
57 void HSItoRGB(
float h,
float s,
float i,
float &r,
float &g,
float &b) {
58 float t=2.0f *
M_PI * h;
59 float scale = i / 2.0f;
60 r=(1.0f + s*sin(t - 2.0f*
M_PI/3.0f)) * scale;
61 g=(1.0f + s*sin(t)) * scale;
62 b=(1.0f + s*sin(t + 2.0f*
M_PI/3.0f)) * scale;
67 float *colors = (
float *) malloc(numpts * 3 *
sizeof(
float));
69 for (
int i=0; i<numpts; i++) {
71 float h = float(i) / float(numpts);
73 float l = (fmodf(h*40.0f, 1.0f) > 0.5f) ? 0.85f : 0.35f;
74 HSItoRGB(h, s, l, colors[ind], colors[ind + 1], colors[ind + 2]);
85 int numpts,
float radius,
int mat) {
88 spheres.
center.resize(numpts);
89 spheres.
radius.resize(numpts);
92 float3 *verts = spheres.
center.data();
93 float *radii = spheres.
radius.data();
96 memcpy(verts, coords, numpts * 3 *
sizeof(
float));
97 memcpy(cols, colors, numpts * 3 *
sizeof(
float));
98 for (
int i=0; i<numpts; i++)
110 -100.0f, 4.0f, -100.0f,
111 -100.0f, 4.0f, 100.0f,
112 100.0f, 4.0f, -100.0f,
116 1.0f, 1.0f, 1.0f, 1.0f,
117 1.0f, 1.0f, 1.0f, 1.0f,
118 1.0f, 1.0f, 1.0f, 1.0f,
119 1.0f, 1.0f, 1.0f, 1.0f
126 vertex[ 0] = -width / 2.0f;
127 vertex[ 3] = -width / 2.0f;
128 vertex[ 6] = width / 2.0f;
129 vertex[ 9] = width / 2.0f;
136 vertex[ 2] = -
length / 2.0f;
137 vertex[ 5] =
length / 2.0f;
138 vertex[ 8] = -
length / 2.0f;
139 vertex[11] =
length / 2.0f;
146 float3 *verts = mesh.
vertices.data();
148 int3 *indices = mesh.
indices.data();
150 memcpy(verts, vertex, 4 * 3 *
sizeof(
float));
151 memcpy(cols, color, 4 * 3 *
sizeof(
float));
152 memcpy(indices, index, 2 * 3 *
sizeof(
int));
158 int main(
int argc,
const char **argv) {
160 int imgSize[2] = {4096, 4096 };
169 printf(
"Usage: %s P Q\n", argv[0]);
170 printf(
" Knot params P and Q control the knot type generated.\n");
171 printf(
"Using defaults, P=5 and Q=3\n");
180 numpts = atoi(argv[3]);
188 float cam_pos[] = {-2.0f, 0.0f, -8.0f};
189 float cam_up[] = {0.0f, 1.0f, 0.0f};
193 float invlen = 1.0f / sqrtf(cam_pos[0]*cam_pos[0] +
194 cam_pos[1]*cam_pos[1] +
195 cam_pos[2]*cam_pos[2]);
196 cam_view[0] = -cam_pos[0] * invlen;
197 cam_view[1] = -cam_pos[1] * invlen;
198 cam_view[2] = -cam_pos[2] * invlen;
206 printf(
"Calculating knot, p: %d, q: %d, points: %d\n", p, q, numpts);
212 printf(
"Initializing TachyonOptiX...");
219 printf(
"Found %u OptiX devices\n", devcount);
220 printf(
"OptiX version used for build: %d.%d.%d (%u)\n",
222 (optixversion%10000)/100,
236 float rtbgcolor[] = { 1.0, 1.0, 1.0 };
237 float rtbggradtopcolor[] = { 0.6, 0.0, 0.0 };
238 float rtbggradbotcolor[] = { 0.0, 0.0, 0.6 };
244 float bggradient[] = { 0.0f, 1.0f, 0.0f };
269 float lightdir0[] = { -0.5f, 0.5f, -1.0f };
270 float lightcolor0[] = { 1.0f, 1.0f, 1.0f };
277 float campos[3] = {0.0f, 10.0f, 12.0f};
279 float camV[3] = {0.0f, 1.0f, 0.0f};
281 float camat[3] = {0.0f, 0.0f, 0.0f};
297 float density = 0.33f;
309 float ambient = 0.0f;
310 float diffuse = 0.7f;
311 float specular = 0.0f;
312 float shininess = 0.0f;
313 float reflectivity = 0.0f;
314 float opacity = 1.0f;
315 float outline = 0.0f;
316 float outlinewidth = 0.0f;
319 rt->
add_material(ambient, diffuse, specular, shininess, reflectivity,
320 opacity, outline, outlinewidth, transmode, mat);
322 rt->
add_material(ambient, diffuse, specular, shininess, reflectivity,
323 opacity, outline, outlinewidth, transmode, mat2);
331 for (
int w=0; w<100; w++) {
340 gen_knot(rt, coords, colors, numpts, 0.33f, mat);
341 gen_floor(rt, 200.0f, -3.5f, 200.0f, mat2);
346 sprintf(filename,
"knot-%d-%d.png", p, q);
347 printf(
"rendering 100 accumulated frames to '%s'...\n", filename);
370 if (filename != NULL) {
372 size_t bufsz = imgSize[0] * imgSize[1] *
sizeof(int);
373 unsigned char *rgb4u = (
unsigned char *) calloc(1, bufsz);
378 printf(
"Writing rgba4u alpha channel output image 2\n");
379 if (write_image_file_rgba4u(filename, rgb4u, imgSize[0], imgSize[1]))
380 printf(
"Failed to write image '%s'!!\n", filename);
382 if (write_image_file_rgb4u(filename, rgb4u, imgSize[0], imgSize[1]))
383 printf(
"Failed to write image '%s'!!\n", filename);
388 stbi_write_png(filename, imgSize[0], imgSize[1], 4, rgb4u, imgSize[0] *
sizeof(
int));
STBIWDEF void stbi_flip_vertically_on_write(int flip_boolean)
void set_ao_maxdist(float dist)
set AO maximum occlusion distance
std::vector< float3 PINALLOCS(float3)> center
void set_bg_gradient_topval(float v)
set background gradient "top" value (view direction dot product)
float * pq_torus_knot(int p, int q, int points)
void set_ao_samples(int cnt)
ambient occlusion (samples > 1 == on)
void framebuffer_get_size(int &fbwidth, int &fbheight)
void add_directional_light(const float *dir, const float *color)
int add_material(float ambient, float diffuse, float specular, float shininess, float reflectivity, float opacity, float outline, float outlinewidth, int transmode, int userindex)
add a material with an associated user-provided index
CPU and GPU profiling utility macros/routines.
#define PROFILE_PUSH_RANGE(name, cid)
Pushes a time range annotation onto the profiler's trace stack, beginning at the time of submission...
std::vector< float PINALLOCS(float)> radius
void framebuffer_resize(int fbwidth, int fbheight)
void camera_dof_enable(int onoff)
depth of field on/off
static int device_count(void)
static GPU device query
void set_camera_lookat(const float *at, const float *V)
set camera orientation to look "at" a point in space, with a given "up" direction (camera ONB "V" vec...
void print_raystats_info(void)
report performance statistics
std::vector< float3 PINALLOCS(float3) > vertices
Output timing/perf data only.
void set_ao_direct(float aod)
set AO direct lighting rescale factor
void HSItoRGB(float h, float s, float i, float &r, float &g, float &b)
void framebuffer_clear(void)
void set_bg_gradient(float *vec)
set world "up" direction for background gradient
void add_spherearray(SphereArray &model, int matidx)
std::vector< float3 PINALLOCS(float3) > vertcolors3f
#define PROFILE_POP_RANGE()
Pops the innermost time range off of the profiler's trace stack, at the time of execution.
void set_camera_zoom(float zoomfactor)
set camera zoom factor
void set_camera_dof_fnumber(float n)
set depth of field f/stop number
float * knot_colors(int numpts)
void set_bg_color_grad_bot(float *rgb)
set color for "bottom" of background gradient
void set_camera_type(CameraType m)
set the camera projection mode
void framebuffer_download_rgb4u(unsigned char *imgrgb4u)
void set_camera_stereo_convergence_dist(float dist)
set stereo convergence distance
void shadows_enable(int onoff)
enable/disable shadows
void set_bg_color(float *rgb)
set solid background color
void set_ao_ambient(float aoa)
set AO ambient lighting factor
void set_aa_samples(int cnt)
antialiasing (samples > 1 == on)
void set_cue_mode(FogMode mode, float start, float end, float density)
set depth cueing mode and parameters
void set_bg_gradient_botval(float v)
set background gradient "bottom" value (view direction dot product)
STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes)
void set_verbose_mode(TachyonOptiX::Verbosity mode)
programmatically set verbosity
void set_bg_color_grad_top(float *rgb)
set color for "top" of background gradient
void gen_knot(TachyonOptiX *rt, float *coords, float *colors, int numpts, float radius, int mat)
__host__ __device__ float length(const float3 &v)
void set_camera_pos(const float *pos)
set the camera position
static unsigned int optix_version(void)
static OptiX version query
std::vector< int3 PINALLOCS(int3) > indices
int main(int argc, const char **argv)
void set_camera_stereo_eyesep(float eyesep)
set stereo eye separation
void gen_floor(TachyonOptiX *rt, float width, float height, float length, int mat)
void framebuffer_colorspace(int colspace)
Tachyon ray tracing host side routines and internal APIs that provide the core ray OptiX-based RTX-ac...
void set_bg_mode(BGMode m)
set background rendering mode
void set_camera_dof_focal_dist(float d)
set depth of field focal plane distance
std::vector< float3 PINALLOCS(float3)> primcolors3f
void add_trimesh(TriangleMesh &model, int matidx)