00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00080 #include <optix.h>
00081 #include <optixu/optixu_math_namespace.h>
00082 #include <optixu/optixu_matrix_namespace.h>
00083 #include <optixu/optixu_aabb_namespace.h>
00084 #include "OptiXShaders.h"
00085
00086
00087
00088
00089
00090
00091
00092
00093 #define ORT_TIME_NORMALIZATION (1e-9 / 2.5f)
00094
00095
00096
00097 #define ORT_TIME_COMBINE_MAX 1
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 #define ORT_USE_RAY_STEP 1
00109 #define ORT_TRANS_USE_INCIDENT 1
00110 #define ORT_RAY_STEP N*scene_epsilon*4.0f
00111 #define ORT_RAY_STEP2 ray.direction*scene_epsilon*4.0f
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 #define REVERSE_RAY_STEP (scene_epsilon*10.0f)
00127 #define REVERSE_RAY_LENGTH 3.0f
00128
00129
00130
00131
00132 #define ORT_USE_SPHERES_HEARNBAKER 1
00133
00134
00135 using namespace optix;
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 template<unsigned int N> static __host__ __device__ __inline__
00148 unsigned int tea(unsigned int val0, unsigned int val1) {
00149 unsigned int v0 = val0;
00150 unsigned int v1 = val1;
00151 unsigned int s0 = 0;
00152
00153 for( unsigned int n = 0; n < N; n++ ) {
00154 s0 += 0x9e3779b9;
00155 v0 += ((v1<<4)+0xa341316c)^(v1+s0)^((v1>>5)+0xc8013ea4);
00156 v1 += ((v0<<4)+0xad90777d)^(v0+s0)^((v0>>5)+0x7e95761e);
00157 }
00158
00159 return v0;
00160 }
00161
00162
00163
00164 rtBuffer<uchar4, 2> framebuffer;
00165 rtBuffer<float4, 2> accumulation_buffer;
00166 rtDeclareVariable(float, accumulation_normalization_factor, , );
00167 rtDeclareVariable(uint2, launch_index, rtLaunchIndex, );
00168 rtDeclareVariable(uint2, launch_dim, rtLaunchDim, );
00169 #if defined(VMDOPTIX_PROGRESSIVEAPI)
00170 rtDeclareVariable(unsigned int, progressiveSubframeIndex, rtSubframeIndex, );
00171 #endif
00172 rtDeclareVariable(unsigned int, accumCount, , );
00173 rtDeclareVariable(int, progressive_enabled, , );
00174
00175 #if defined(ORT_RAYSTATS)
00176
00177 rtBuffer<uint4, 2> raystats1_buffer;
00178 rtBuffer<uint4, 2> raystats2_buffer;
00179 #endif
00180
00181
00182 rtDeclareVariable(float, scene_epsilon, , );
00183
00184
00185 rtDeclareVariable(unsigned int, max_depth, , );
00186
00187
00188 rtDeclareVariable(unsigned int, max_trans, , );
00189
00190
00191
00192
00193 rtDeclareVariable(float, anim_interp, , );
00194
00195
00196 rtDeclareVariable(int, shadows_enabled, , );
00197 rtDeclareVariable(int, aa_samples, , );
00198
00199
00200 rtDeclareVariable(int, ao_samples, , );
00201 rtDeclareVariable(float, ao_ambient, , );
00202 rtDeclareVariable(float, ao_direct, , );
00203 rtDeclareVariable(float, ao_maxdist, , );
00204
00205
00206 rtDeclareVariable(float3, scene_bg_color, , );
00207 rtDeclareVariable(float3, scene_bg_color_grad_top, , );
00208 rtDeclareVariable(float3, scene_bg_color_grad_bot, , );
00209 rtDeclareVariable(float3, scene_gradient, , );
00210 rtDeclareVariable(float, scene_gradient_topval, , );
00211 rtDeclareVariable(float, scene_gradient_botval, , );
00212 rtDeclareVariable(float, scene_gradient_invrange, , );
00213
00214
00215 rtDeclareVariable(int, clipview_mode, , );
00216 rtDeclareVariable(float, clipview_start, , );
00217 rtDeclareVariable(float, clipview_end, , );
00218
00219
00220 rtDeclareVariable(int, headlight_mode, , );
00221
00222
00223 rtDeclareVariable(int, fog_mode, , );
00224 rtDeclareVariable(float, fog_start, , );
00225 rtDeclareVariable(float, fog_end, , );
00226 rtDeclareVariable(float, fog_density, , );
00227
00228
00229 rtDeclareVariable(float, cam_zoom, , );
00230 rtDeclareVariable(float3, cam_pos, , );
00231 rtDeclareVariable(float3, cam_U, , );
00232 rtDeclareVariable(float3, cam_V, , );
00233 rtDeclareVariable(float3, cam_W, , );
00234
00235
00236 rtDeclareVariable(float, cam_stereo_eyesep, , );
00237 rtDeclareVariable(float, cam_stereo_convergence_dist, , );
00238
00239
00240 rtDeclareVariable(float, cam_dof_aperture_rad, , );
00241 rtDeclareVariable(float, cam_dof_focal_dist, , );
00242
00243
00244 rtDeclareVariable(unsigned int, radiance_ray_type, , );
00245 rtDeclareVariable(unsigned int, shadow_ray_type, , );
00246 rtDeclareVariable(rtObject, root_object, , );
00247 rtDeclareVariable(rtObject, root_shadower, , );
00248
00249 rtDeclareVariable(optix::Ray, ray, rtCurrentRay, );
00250 rtDeclareVariable(float, t_hit, rtIntersectionDistance, );
00251
00252
00253
00254
00255
00256 rtDeclareVariable(float3, geometric_normal, attribute geometric_normal, );
00257 rtDeclareVariable(float3, shading_normal, attribute shading_normal, );
00258
00259 rtDeclareVariable(float3, obj_color, attribute obj_color, );
00260
00261 #if defined(ORT_USERTXAPIS)
00262
00263
00264
00265 rtDeclareVariable(float2, barycentrics, attribute rtTriangleBarycentrics, );
00266 rtBuffer<uint4> normalBuffer;
00267 rtBuffer<uchar4> colorBuffer;
00268 rtDeclareVariable(int, has_vertex_normals, , );
00269 rtDeclareVariable(int, has_vertex_colors, , );
00270 #endif
00271
00272
00273 struct PerRayData_radiance {
00274 float3 result;
00275 float alpha;
00276 float importance;
00277 unsigned int depth;
00278 unsigned int transcnt;
00279 };
00280
00281 struct PerRayData_shadow {
00282 float3 attenuation;
00283 };
00284
00285 rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload, );
00286 rtDeclareVariable(PerRayData_radiance, prd, rtPayload, );
00287 rtDeclareVariable(PerRayData_shadow, prd_shadow, rtPayload, );
00288
00289
00290 #if defined(VMDOPTIX_LIGHTUSEROBJS)
00291 rtDeclareVariable(DirectionalLightList, dir_light_list, , );
00292 rtDeclareVariable(PositionalLightList, pos_light_list, , );
00293 #else
00294 rtBuffer<DirectionalLight> dir_lights;
00295 rtBuffer<DirectionalLight> pos_lights;
00296 #endif
00297
00298
00299
00300
00301 static __device__ __inline__ uchar4 make_color_rgb4u(const float3& c) {
00302 return make_uchar4(static_cast<unsigned char>(__saturatef(c.x)*255.99f),
00303 static_cast<unsigned char>(__saturatef(c.y)*255.99f),
00304 static_cast<unsigned char>(__saturatef(c.z)*255.99f),
00305 255u);
00306 }
00307
00308
00309
00310
00311 static __device__ __inline__ uchar4 make_color_rgb4u(const float4& c) {
00312 return make_uchar4(static_cast<unsigned char>(__saturatef(c.x)*255.99f),
00313 static_cast<unsigned char>(__saturatef(c.y)*255.99f),
00314 static_cast<unsigned char>(__saturatef(c.z)*255.99f),
00315 static_cast<unsigned char>(__saturatef(c.w)*255.99f));
00316 }
00317
00318
00319
00320
00321
00322
00323
00324
00325 RT_PROGRAM void miss_solid_bg() {
00326
00327
00328 prd_radiance.result = scene_bg_color;
00329 prd_radiance.alpha = 0.0f;
00330 #if defined(ORT_RAYSTATS)
00331 raystats1_buffer[launch_index].w++;
00332 #endif
00333 }
00334
00335
00336
00337
00338
00339
00340 RT_PROGRAM void miss_gradient_bg_sky_sphere() {
00341 float IdotG = dot(ray.direction, scene_gradient);
00342 float val = (IdotG - scene_gradient_botval) * scene_gradient_invrange;
00343 val = __saturatef(val);
00344 float3 col = val * scene_bg_color_grad_top +
00345 (1.0f - val) * scene_bg_color_grad_bot;
00346 prd_radiance.result = col;
00347 prd_radiance.alpha = 0.0f;
00348 #if defined(ORT_RAYSTATS)
00349 raystats1_buffer[launch_index].w++;
00350 #endif
00351 }
00352
00353
00354
00355
00356
00357
00358 RT_PROGRAM void miss_gradient_bg_sky_plane() {
00359 float IdotG = dot(ray.origin, scene_gradient);
00360 float val = (IdotG - scene_gradient_botval) * scene_gradient_invrange;
00361 val = __saturatef(val);
00362 float3 col = val * scene_bg_color_grad_top +
00363 (1.0f - val) * scene_bg_color_grad_bot;
00364 prd_radiance.result = col;
00365 prd_radiance.alpha = 0.0f;
00366 #if defined(ORT_RAYSTATS)
00367 raystats1_buffer[launch_index].w++;
00368 #endif
00369 }
00370
00371
00372
00373
00374
00375 #define MYRT_RAND_MAX 4294967296.0f
00376 #define MYRT_RAND_MAX_INV .00000000023283064365f
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390 static __device__ __inline__
00391 unsigned int myrt_rand(unsigned int &idum) {
00392
00393 idum *= 1099087573;
00394 return idum;
00395 }
00396
00397
00398
00399
00400 static __device__ __inline__
00401 void jitter_offset2f(unsigned int &pval, float2 &xy) {
00402 xy.x = (myrt_rand(pval) * MYRT_RAND_MAX_INV) - 0.5f;
00403 xy.y = (myrt_rand(pval) * MYRT_RAND_MAX_INV) - 0.5f;
00404 }
00405
00406
00407
00408
00409 static __device__ __inline__
00410 void jitter_disc2f(unsigned int &pval, float2 &xy, float radius) {
00411 #if 1
00412
00413
00414
00415
00416
00417 float r=(myrt_rand(pval) * MYRT_RAND_MAX_INV);
00418 float phi=(myrt_rand(pval) * MYRT_RAND_MAX_INV) * 2.0f * M_PIf;
00419 __sincosf(phi, &xy.x, &xy.y);
00420 xy *= sqrtf(r) * radius;
00421 #else
00422
00423
00424
00425 do {
00426 xy.x = 2.0f * (myrt_rand(pval) * MYRT_RAND_MAX_INV) - 1.0f;
00427 xy.y = 2.0f * (myrt_rand(pval) * MYRT_RAND_MAX_INV) - 1.0f;
00428 } while ((xy.x*xy.x + xy.y*xy.y) > 1.0f);
00429 xy *= radius;
00430 #endif
00431 }
00432
00433
00434
00435 static __device__ __inline__
00436 void jitter_sphere3f(unsigned int &pval, float3 &dir) {
00437 #if 1
00438
00439
00440
00441
00442
00443
00444
00445
00446 float u1 = myrt_rand(pval) * MYRT_RAND_MAX_INV;
00447 dir.z = 2.0f * u1 - 1.0f;
00448 float R = __fsqrt_rn(1.0f - dir.z*dir.z);
00449 float u2 = myrt_rand(pval) * MYRT_RAND_MAX_INV;
00450 float phi = 2.0f * M_PIf * u2;
00451 float sinphi, cosphi;
00452 __sincosf(phi, &sinphi, &cosphi);
00453 dir.x = R * cosphi;
00454 dir.y = R * sinphi;
00455 #elif 1
00456
00457
00458
00459
00460
00461 float u1 = myrt_rand(pval) * MYRT_RAND_MAX_INV;
00462 dir.z = 2.0f * u1 - 1.0f;
00463 float R = sqrtf(1.0f - dir.z*dir.z);
00464
00465 float u2 = myrt_rand(pval) * MYRT_RAND_MAX_INV;
00466 float phi = 2.0f * M_PIf * u2;
00467 float sinphi, cosphi;
00468 sincosf(phi, &sinphi, &cosphi);
00469 dir.x = R * cosphi;
00470 dir.y = R * sinphi;
00471 #else
00472
00473
00474
00475
00476
00477
00478 float len;
00479 float3 d;
00480 do {
00481 d.x = (myrt_rand(pval) * MYRT_RAND_MAX_INV) - 0.5f;
00482 d.y = (myrt_rand(pval) * MYRT_RAND_MAX_INV) - 0.5f;
00483 d.z = (myrt_rand(pval) * MYRT_RAND_MAX_INV) - 0.5f;
00484 len = dot(d, d);
00485 } while (len > 0.250f);
00486 float invlen = rsqrtf(len);
00487
00488
00489 dir = d * invlen;
00490 #endif
00491 }
00492
00493
00494
00495
00496
00497
00498
00499
00500 __device__ void sphere_fade_and_clip(const float3 &hit_point,
00501 const float3 &cam_pos,
00502 float fade_start, float fade_end,
00503 float &alpha) {
00504 float camdist = length(hit_point - cam_pos);
00505
00506
00507
00508 float fade_len = fade_start - fade_end;
00509 alpha *= __saturatef((camdist - fade_start) / fade_len);
00510
00511 }
00512
00513
00514 __device__ void ray_sphere_clip_interval(const optix::Ray &ray, float3 center,
00515 float rad, float2 &tinterval) {
00516 float3 V = center - ray.origin;
00517 float b = dot(V, ray.direction);
00518 float disc = b*b + rad*rad - dot(V, V);
00519
00520
00521 if (disc > 0.0f) {
00522 disc = sqrtf(disc);
00523 tinterval.x = b-disc;
00524 tinterval.y = b+disc;
00525 } else {
00526 tinterval.x = -RT_DEFAULT_MAX;
00527 tinterval.y = RT_DEFAULT_MAX;
00528 }
00529 }
00530
00531
00532 __device__ void clip_ray_by_plane(optix::Ray &ray, const float4 plane) {
00533 float3 n = make_float3(plane);
00534 float dt = dot(ray.direction, n);
00535 float t = (-plane.w - dot(n, ray.origin))/dt;
00536 if(t > ray.tmin && t < ray.tmax) {
00537 if (dt <= 0) {
00538 ray.tmax = t;
00539 } else {
00540 ray.tmin = t;
00541 }
00542 } else {
00543
00544 float3 p = ray.origin + ray.tmin * ray.direction;
00545 if (dot(make_float4(p, 1.0f), plane) < 0) {
00546 ray.tmin = ray.tmax = RT_DEFAULT_MAX;
00547 }
00548 }
00549 }
00550
00551
00552
00553
00554
00555 #if defined(ORT_RAYSTATS)
00556 RT_PROGRAM void clear_raystats_buffers() {
00557 raystats1_buffer[launch_index] = make_uint4(0, 0, 0, 0);
00558 raystats2_buffer[launch_index] = make_uint4(0, 0, 0, 0);
00559 }
00560 #endif
00561
00562
00563
00564
00565
00566 RT_PROGRAM void clear_accumulation_buffer() {
00567 accumulation_buffer[launch_index] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
00568 }
00569
00570
00571
00572
00573
00574
00575
00576
00577 RT_PROGRAM void draw_accumulation_buffer() {
00578 #if defined(ORT_TIME_COLORING) && defined(ORT_TIME_COMBINE_MAX)
00579 float4 curcol = accumulation_buffer[launch_index];
00580
00581
00582 curcol.x /= accumulation_normalization_factor;
00583
00584
00585 curcol.y *= accumulation_normalization_factor;
00586 curcol.z *= accumulation_normalization_factor;
00587 curcol.w *= accumulation_normalization_factor;
00588
00589 framebuffer[launch_index] = make_color_rgb4u(curcol);
00590 #else
00591 framebuffer[launch_index] = make_color_rgb4u(accumulation_buffer[launch_index] * accumulation_normalization_factor);
00592 #endif
00593 }
00594
00595
00596 RT_PROGRAM void draw_accumulation_buffer_stub() {
00597 }
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608 static void __inline__ __device__ accumulate_color(float3 &col,
00609 float alpha = 1.0f) {
00610 #if defined(VMDOPTIX_PROGRESSIVEAPI)
00611 if (progressive_enabled) {
00612 col *= accumulation_normalization_factor;
00613 alpha *= accumulation_normalization_factor;
00614
00615 #if OPTIX_VERSION < 3080
00616
00617
00618 float invgamma = 1.0f / 0.4545f;
00619 col.x = powf(col.x, invgamma);
00620 col.y = powf(col.y, invgamma);
00621 col.z = powf(col.z, invgamma);
00622 #endif
00623
00624
00625 accumulation_buffer[launch_index] = make_float4(col, alpha);
00626 } else {
00627
00628 accumulation_buffer[launch_index] += make_float4(col, alpha);
00629 }
00630 #else
00631
00632 accumulation_buffer[launch_index] += make_float4(col, alpha);
00633 #endif
00634 }
00635
00636
00637 #if defined(ORT_TIME_COLORING)
00638
00639 static void __inline__ __device__
00640 accumulate_time_coloring(float3 &col, clock_t t0) {
00641 clock_t t1 = clock();
00642 float4 curcol = accumulation_buffer[launch_index];
00643
00644
00645
00646 float pixel_time = (t1 - t0) * ORT_TIME_NORMALIZATION;
00647 col.x = __saturatef(pixel_time);
00648
00649 #if defined(ORT_TIME_COMBINE_MAX)
00650
00651 curcol.x = fmaxf(curcol.x, col.x);
00652 curcol.y += col.y;
00653 curcol.z += col.z;
00654 curcol.w += 1.0f;
00655 #else
00656
00657 curcol += make_float4(col, 1.0f);
00658 #endif
00659
00660 accumulation_buffer[launch_index] = curcol;
00661 }
00662 #endif
00663
00664
00665 static int __inline__ __device__ subframe_count() {
00666 #if defined(VMDOPTIX_PROGRESSIVEAPI)
00667 return (accumCount + progressiveSubframeIndex);
00668 #else
00669 return accumCount;
00670 #endif
00671 }
00672
00673
00674
00675
00676
00677
00678
00679 static __device__ __inline__
00680 void dof_ray(const float3 &ray_origin_orig, float3 &ray_origin,
00681 const float3 &ray_direction_orig, float3 &ray_direction,
00682 unsigned int &randseed, const float3 &up, const float3 &right) {
00683 float3 focuspoint = ray_origin_orig + ray_direction_orig * cam_dof_focal_dist;
00684 float2 dofjxy;
00685 jitter_disc2f(randseed, dofjxy, cam_dof_aperture_rad);
00686 ray_origin = ray_origin_orig + dofjxy.x*right + dofjxy.y*up;
00687 ray_direction = normalize(focuspoint - ray_origin);
00688 }
00689
00690
00691
00692
00693
00694
00695 template<int STEREO_ON, int DOF_ON>
00696 static __device__ __inline__
00697 void vmd_camera_cubemap_general() {
00698 #if defined(ORT_TIME_COLORING)
00699 clock_t t0 = clock();
00700 #endif
00701
00702
00703 uint facesz = launch_dim.y;
00704 uint face = (launch_index.x / facesz) % 6;
00705 uint2 face_idx = make_uint2(launch_index.x % facesz, launch_index.y);
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716 float3 face_U, face_V, face_W;
00717 switch (face) {
00718 case 0:
00719 face_U = cam_U;
00720 face_V = cam_V;
00721 face_W = -cam_W;
00722 break;
00723
00724 case 1:
00725 face_U = -cam_U;
00726 face_V = cam_V;
00727 face_W = cam_W;
00728 break;
00729
00730 case 2:
00731 face_U = -cam_W;
00732 face_V = cam_U;
00733 face_W = cam_V;
00734 break;
00735
00736 case 3:
00737 face_U = -cam_W;
00738 face_V = -cam_U;
00739 face_W = -cam_V;
00740 break;
00741
00742 case 4:
00743 face_U = -cam_W;
00744 face_V = cam_V;
00745 face_W = -cam_U;
00746 break;
00747
00748 case 5:
00749 face_U = cam_W;
00750 face_V = cam_V;
00751 face_W = cam_U;
00752 break;
00753 }
00754
00755
00756
00757
00758
00759
00760 uint viewport_sz_x, viewport_idx_x;
00761 float eyeshift;
00762 if (STEREO_ON) {
00763
00764 viewport_sz_x = launch_dim.x >> 1;
00765 if (launch_index.x >= viewport_sz_x) {
00766
00767 viewport_idx_x = launch_index.x - viewport_sz_x;
00768 eyeshift = 0.5f * cam_stereo_eyesep;
00769 } else {
00770
00771 viewport_idx_x = launch_index.x;
00772 eyeshift = -0.5f * cam_stereo_eyesep;
00773 }
00774 } else {
00775
00776 viewport_sz_x = launch_dim.x;
00777 viewport_idx_x = launch_index.x;
00778 eyeshift = 0.0f;
00779 }
00780
00781
00782
00783
00784 float facescale = 1.0f / facesz;
00785 float2 d = make_float2(face_idx.x, face_idx.y) * facescale * 2.f - 1.0f;
00786
00787 unsigned int randseed = tea<4>(launch_dim.x*(launch_index.y)+viewport_idx_x, subframe_count());
00788
00789 float3 col = make_float3(0.0f);
00790 for (int s=0; s<aa_samples; s++) {
00791 float2 jxy;
00792 jitter_offset2f(randseed, jxy);
00793 jxy = jxy * facescale * 2.f + d;
00794 float3 ray_direction = normalize(jxy.x*face_U + jxy.y*face_V + face_W);
00795
00796 float3 ray_origin = cam_pos;
00797 if (STEREO_ON) {
00798 ray_origin += eyeshift * cross(ray_direction, cam_V);
00799 }
00800
00801
00802 if (DOF_ON) {
00803 dof_ray(ray_origin, ray_origin, ray_direction, ray_direction,
00804 randseed, face_V, face_U);
00805 }
00806
00807
00808 PerRayData_radiance prd;
00809 prd.importance = 1.f;
00810 prd.depth = 0;
00811 prd.transcnt = max_trans;
00812 optix::Ray ray = optix::make_Ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon, RT_DEFAULT_MAX);
00813 rtTrace(root_object, ray, prd);
00814 col += prd.result;
00815 }
00816 #if defined(ORT_RAYSTATS)
00817 raystats1_buffer[launch_index].x+=aa_samples;
00818 #endif
00819
00820 #if defined(ORT_TIME_COLORING)
00821 accumulate_time_coloring(col, t0);
00822 #else
00823 accumulate_color(col);
00824 #endif
00825 }
00826
00827 RT_PROGRAM void vmd_camera_cubemap() {
00828 vmd_camera_cubemap_general<0, 0>();
00829 }
00830
00831 RT_PROGRAM void vmd_camera_cubemap_dof() {
00832 vmd_camera_cubemap_general<0, 1>();
00833 }
00834
00835 RT_PROGRAM void vmd_camera_cubemap_stereo() {
00836 vmd_camera_cubemap_general<1, 0>();
00837 }
00838
00839 RT_PROGRAM void vmd_camera_cubemap_stereo_dof() {
00840 vmd_camera_cubemap_general<1, 1>();
00841 }
00842
00843
00844
00845
00846
00847
00848
00849 template<int STEREO_ON, int DOF_ON>
00850 static __device__ __inline__
00851 void vmd_camera_dome_general() {
00852 #if defined(ORT_TIME_COLORING)
00853 clock_t t0 = clock();
00854 #endif
00855
00856
00857
00858
00859
00860
00861 uint viewport_sz_y, viewport_idx_y;
00862 float eyeshift;
00863 if (STEREO_ON) {
00864
00865 viewport_sz_y = launch_dim.y >> 1;
00866 if (launch_index.y >= viewport_sz_y) {
00867
00868 viewport_idx_y = launch_index.y - viewport_sz_y;
00869 eyeshift = -0.5f * cam_stereo_eyesep;
00870 } else {
00871
00872 viewport_idx_y = launch_index.y;
00873 eyeshift = 0.5f * cam_stereo_eyesep;
00874 }
00875 } else {
00876
00877 viewport_sz_y = launch_dim.y;
00878 viewport_idx_y = launch_index.y;
00879 eyeshift = 0.0f;
00880 }
00881
00882 float fov = M_PIf;
00883
00884
00885
00886 float thetamax = 0.5 * fov;
00887
00888
00889
00890
00891
00892
00893
00894 float2 viewport_sz = make_float2(launch_dim.x, viewport_sz_y);
00895 float2 radperpix = fov / viewport_sz;
00896 float2 viewport_mid = viewport_sz * 0.5f;
00897
00898 unsigned int randseed = tea<4>(launch_dim.x*(launch_index.y)+launch_index.x, subframe_count());
00899
00900 float3 col = make_float3(0.0f);
00901 float alpha = 0.0f;
00902 for (int s=0; s<aa_samples; s++) {
00903
00904 float2 jxy;
00905 jitter_offset2f(randseed, jxy);
00906 float2 viewport_idx = make_float2(launch_index.x, viewport_idx_y) + jxy;
00907
00908
00909 float2 p = (viewport_idx - viewport_mid) * radperpix;
00910 float theta = hypotf(p.x, p.y);
00911
00912
00913
00914 if (theta < thetamax) {
00915 float3 ray_direction;
00916 float3 ray_origin = cam_pos;
00917
00918 if (theta == 0) {
00919
00920
00921 ray_direction = cam_W;
00922 } else {
00923 float sintheta, costheta;
00924 sincosf(theta, &sintheta, &costheta);
00925 float rsin = sintheta / theta;
00926 ray_direction = cam_U*rsin*p.x + cam_V*rsin*p.y + cam_W*costheta;
00927 if (STEREO_ON) {
00928
00929
00930 ray_origin += eyeshift * cross(ray_direction, cam_W);
00931 }
00932
00933 if (DOF_ON) {
00934 float rcos = costheta / theta;
00935 float3 ray_up = -cam_U*rcos*p.x -cam_V*rcos*p.y + cam_W*sintheta;
00936 float3 ray_right = cam_U*(p.y/theta) + cam_V*(-p.x/theta);
00937 dof_ray(ray_origin, ray_origin, ray_direction, ray_direction,
00938 randseed, ray_up, ray_right);
00939 }
00940 }
00941
00942
00943 PerRayData_radiance prd;
00944 prd.importance = 1.f;
00945 prd.alpha = 1.f;
00946 prd.depth = 0;
00947 prd.transcnt = max_trans;
00948 optix::Ray ray = optix::make_Ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon, RT_DEFAULT_MAX);
00949 rtTrace(root_object, ray, prd);
00950 col += prd.result;
00951 alpha += prd.alpha;
00952 }
00953 }
00954 #if defined(ORT_RAYSTATS)
00955 raystats1_buffer[launch_index].x+=aa_samples;
00956 #endif
00957
00958 #if defined(ORT_TIME_COLORING)
00959 accumulate_time_coloring(col, t0);
00960 #else
00961 accumulate_color(col, alpha);
00962 #endif
00963 }
00964
00965 RT_PROGRAM void vmd_camera_dome_master() {
00966 vmd_camera_dome_general<0, 0>();
00967 }
00968
00969 RT_PROGRAM void vmd_camera_dome_master_dof() {
00970 vmd_camera_dome_general<0, 1>();
00971 }
00972
00973 RT_PROGRAM void vmd_camera_dome_master_stereo() {
00974 vmd_camera_dome_general<1, 0>();
00975 }
00976
00977 RT_PROGRAM void vmd_camera_dome_master_stereo_dof() {
00978 vmd_camera_dome_general<1, 1>();
00979 }
00980
00981
00982
00983
00984
00985
00986
00987
00988 template<int STEREO_ON, int DOF_ON>
00989 static __device__ __inline__
00990 void vmd_camera_equirectangular_general() {
00991 #if defined(ORT_TIME_COLORING)
00992 clock_t t0 = clock();
00993 #endif
00994
00995
00996
00997
00998
00999
01000
01001
01002 uint viewport_sz_y, viewport_idx_y;
01003 float eyeshift;
01004 if (STEREO_ON) {
01005
01006 viewport_sz_y = launch_dim.y >> 1;
01007 if (launch_index.y >= viewport_sz_y) {
01008
01009 viewport_idx_y = launch_index.y - viewport_sz_y;
01010 eyeshift = -0.5f * cam_stereo_eyesep;
01011 } else {
01012
01013 viewport_idx_y = launch_index.y;
01014 eyeshift = 0.5f * cam_stereo_eyesep;
01015 }
01016 } else {
01017
01018 viewport_sz_y = launch_dim.y;
01019 viewport_idx_y = launch_index.y;
01020 eyeshift = 0.0f;
01021 }
01022
01023 float2 viewport_sz = make_float2(launch_dim.x, viewport_sz_y);
01024 float2 radperpix = M_PIf / viewport_sz * make_float2(2.0f, 1.0f);
01025 float2 viewport_mid = viewport_sz * 0.5f;
01026
01027 unsigned int randseed = tea<4>(launch_dim.x*(launch_index.y)+launch_index.x, subframe_count());
01028
01029 float3 col = make_float3(0.0f);
01030 for (int s=0; s<aa_samples; s++) {
01031 float2 jxy;
01032 jitter_offset2f(randseed, jxy);
01033
01034 float2 viewport_idx = make_float2(launch_index.x, viewport_idx_y) + jxy;
01035 float2 rangle = (viewport_idx - viewport_mid) * radperpix;
01036
01037 float sin_ax, cos_ax, sin_ay, cos_ay;
01038 sincosf(rangle.x, &sin_ax, &cos_ax);
01039 sincosf(rangle.y, &sin_ay, &cos_ay);
01040
01041 float3 ray_direction = normalize(cos_ay * (cos_ax * cam_W + sin_ax * cam_U) + sin_ay * cam_V);
01042
01043 float3 ray_origin = cam_pos;
01044 if (STEREO_ON) {
01045 ray_origin += eyeshift * cross(ray_direction, cam_V);
01046 }
01047
01048
01049 if (DOF_ON) {
01050 float3 ray_right = normalize(cos_ay * (-sin_ax * cam_W - cos_ax * cam_U) + sin_ay * cam_V);
01051 float3 ray_up = cross(ray_direction, ray_right);
01052 dof_ray(ray_origin, ray_origin, ray_direction, ray_direction,
01053 randseed, ray_up, ray_right);
01054 }
01055
01056
01057 PerRayData_radiance prd;
01058 prd.importance = 1.f;
01059 prd.depth = 0;
01060 prd.transcnt = max_trans;
01061 optix::Ray ray = optix::make_Ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon, RT_DEFAULT_MAX);
01062 rtTrace(root_object, ray, prd);
01063 col += prd.result;
01064 }
01065 #if defined(ORT_RAYSTATS)
01066 raystats1_buffer[launch_index].x+=aa_samples;
01067 #endif
01068
01069 #if defined(ORT_TIME_COLORING)
01070 accumulate_time_coloring(col, t0);
01071 #else
01072 accumulate_color(col);
01073 #endif
01074 }
01075
01076 RT_PROGRAM void vmd_camera_equirectangular() {
01077 vmd_camera_equirectangular_general<0, 0>();
01078 }
01079
01080 RT_PROGRAM void vmd_camera_equirectangular_dof() {
01081 vmd_camera_equirectangular_general<0, 1>();
01082 }
01083
01084 RT_PROGRAM void vmd_camera_equirectangular_stereo() {
01085 vmd_camera_equirectangular_general<1, 0>();
01086 }
01087
01088 RT_PROGRAM void vmd_camera_equirectangular_stereo_dof() {
01089 vmd_camera_equirectangular_general<1, 1>();
01090 }
01091
01092
01093
01094
01095
01096 template<int STEREO_ON, int DOF_ON>
01097 static __device__ __inline__
01098 void vmd_camera_oculus_rift_general() {
01099 #if defined(ORT_TIME_COLORING)
01100 clock_t t0 = clock();
01101 #endif
01102
01103
01104
01105
01106
01107
01108 uint viewport_sz_x, viewport_idx_x;
01109 float eyeshift;
01110 if (STEREO_ON) {
01111
01112 viewport_sz_x = launch_dim.x >> 1;
01113 if (launch_index.x >= viewport_sz_x) {
01114
01115 viewport_idx_x = launch_index.x - viewport_sz_x;
01116 eyeshift = 0.5f * cam_stereo_eyesep;
01117 } else {
01118
01119 viewport_idx_x = launch_index.x;
01120 eyeshift = -0.5f * cam_stereo_eyesep;
01121 }
01122 } else {
01123
01124 viewport_sz_x = launch_dim.x;
01125 viewport_idx_x = launch_index.x;
01126 eyeshift = 0.0f;
01127 }
01128
01129
01130
01131
01132 float2 aspect = make_float2(float(viewport_sz_x) / float(launch_dim.y), 1.0f) * cam_zoom;
01133 float2 viewportscale = 1.0f / make_float2(viewport_sz_x, launch_dim.y);
01134 float2 d = make_float2(viewport_idx_x, launch_index.y) * viewportscale * aspect * 2.f - aspect;
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153 float2 cp = make_float2(viewport_sz_x >> 1, launch_dim.y >> 1) * viewportscale * aspect * 2.f - aspect;;
01154 float2 dr = d - cp;
01155 float r2 = dr.x*dr.x + dr.y*dr.y;
01156 float r = 0.24f*r2*r2 + 0.22f*r2 + 1.0f;
01157 d = r * dr;
01158
01159 int subframecount = subframe_count();
01160 unsigned int randseed = tea<4>(launch_dim.x*(launch_index.y)+viewport_idx_x, subframecount);
01161
01162 float3 eyepos = cam_pos;
01163 if (STEREO_ON) {
01164 eyepos += eyeshift * cam_U;
01165 }
01166
01167 float3 ray_origin = eyepos;
01168 float3 col = make_float3(0.0f);
01169 for (int s=0; s<aa_samples; s++) {
01170 float2 jxy;
01171 jitter_offset2f(randseed, jxy);
01172
01173
01174
01175 jxy *= (subframecount > 0 || s > 0);
01176
01177 jxy = jxy * viewportscale * aspect * 2.f + d;
01178 float3 ray_direction = normalize(jxy.x*cam_U + jxy.y*cam_V + cam_W);
01179
01180
01181 if (DOF_ON) {
01182 dof_ray(eyepos, ray_origin, ray_direction, ray_direction,
01183 randseed, cam_V, cam_U);
01184 }
01185
01186
01187 PerRayData_radiance prd;
01188 prd.importance = 1.f;
01189 prd.depth = 0;
01190 prd.transcnt = max_trans;
01191 optix::Ray ray = optix::make_Ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon, RT_DEFAULT_MAX);
01192 rtTrace(root_object, ray, prd);
01193 col += prd.result;
01194 }
01195 #if defined(ORT_RAYSTATS)
01196 raystats1_buffer[launch_index].x+=aa_samples;
01197 #endif
01198
01199 #if defined(ORT_TIME_COLORING)
01200 accumulate_time_coloring(col, t0);
01201 #else
01202 accumulate_color(col);
01203 #endif
01204 }
01205
01206 RT_PROGRAM void vmd_camera_oculus_rift() {
01207 vmd_camera_oculus_rift_general<0, 0>();
01208 }
01209
01210 RT_PROGRAM void vmd_camera_oculus_rift_dof() {
01211 vmd_camera_oculus_rift_general<0, 1>();
01212 }
01213
01214 RT_PROGRAM void vmd_camera_oculus_rift_stereo() {
01215 vmd_camera_oculus_rift_general<1, 0>();
01216 }
01217
01218 RT_PROGRAM void vmd_camera_oculus_rift_stereo_dof() {
01219 vmd_camera_oculus_rift_general<1, 1>();
01220 }
01221
01222
01223
01224
01225
01226
01227 template<int STEREO_ON, int DOF_ON>
01228 static __device__ __inline__
01229 void vmd_camera_perspective_general() {
01230 #if defined(ORT_TIME_COLORING)
01231 clock_t t0 = clock();
01232 #endif
01233
01234
01235
01236
01237
01238
01239 float3 eyepos;
01240 uint viewport_sz_y, viewport_idx_y;
01241 if (STEREO_ON) {
01242
01243 viewport_sz_y = launch_dim.y >> 1;
01244 if (launch_index.y >= viewport_sz_y) {
01245
01246 viewport_idx_y = launch_index.y - viewport_sz_y;
01247 eyepos = cam_pos + cam_U * cam_stereo_eyesep * 0.5f;
01248 } else {
01249
01250 viewport_idx_y = launch_index.y;
01251 eyepos = cam_pos - cam_U * cam_stereo_eyesep * 0.5f;
01252 }
01253 } else {
01254
01255 viewport_sz_y = launch_dim.y;
01256 viewport_idx_y = launch_index.y;
01257 eyepos = cam_pos;
01258 }
01259
01260
01261
01262
01263 float2 aspect = make_float2(float(launch_dim.x) / float(viewport_sz_y), 1.0f) * cam_zoom;
01264 float2 viewportscale = 1.0f / make_float2(launch_dim.x, viewport_sz_y);
01265 float2 d = make_float2(launch_index.x, viewport_idx_y) * viewportscale * aspect * 2.f - aspect;
01266
01267 unsigned int randseed = tea<4>(launch_dim.x*(viewport_idx_y)+launch_index.x, subframe_count());
01268
01269 float3 col = make_float3(0.0f);
01270 float alpha = 0.0f;
01271 float3 ray_origin = eyepos;
01272 for (int s=0; s<aa_samples; s++) {
01273 float2 jxy;
01274 jitter_offset2f(randseed, jxy);
01275
01276 jxy = jxy * viewportscale * aspect * 2.f + d;
01277 float3 ray_direction = normalize(jxy.x*cam_U + jxy.y*cam_V + cam_W);
01278
01279
01280 if (DOF_ON) {
01281 dof_ray(eyepos, ray_origin, ray_direction, ray_direction,
01282 randseed, cam_V, cam_U);
01283 }
01284
01285
01286 PerRayData_radiance prd;
01287 prd.importance = 1.f;
01288 prd.alpha = 1.f;
01289 prd.depth = 0;
01290 prd.transcnt = max_trans;
01291 optix::Ray ray = optix::make_Ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon, RT_DEFAULT_MAX);
01292 rtTrace(root_object, ray, prd);
01293 col += prd.result;
01294 alpha += prd.alpha;
01295 }
01296 #if defined(ORT_RAYSTATS)
01297 raystats1_buffer[launch_index].x+=aa_samples;
01298 #endif
01299
01300 #if defined(ORT_TIME_COLORING)
01301 accumulate_time_coloring(col, t0);
01302 #else
01303 accumulate_color(col, alpha);
01304 #endif
01305 }
01306
01307
01308 RT_PROGRAM void vmd_camera_perspective() {
01309 vmd_camera_perspective_general<0, 0>();
01310 }
01311
01312 RT_PROGRAM void vmd_camera_perspective_dof() {
01313 vmd_camera_perspective_general<0, 1>();
01314 }
01315
01316 RT_PROGRAM void vmd_camera_perspective_stereo() {
01317 vmd_camera_perspective_general<1, 0>();
01318 }
01319
01320 RT_PROGRAM void vmd_camera_perspective_stereo_dof() {
01321 vmd_camera_perspective_general<1, 1>();
01322 }
01323
01324
01325
01326
01327
01328 template<int STEREO_ON, int DOF_ON>
01329 static __device__ __inline__
01330 void vmd_camera_orthographic_general() {
01331 #if defined(ORT_TIME_COLORING)
01332 clock_t t0 = clock();
01333 #endif
01334
01335
01336
01337
01338
01339
01340 float3 eyepos;
01341 uint viewport_sz_y, viewport_idx_y;
01342 float3 view_direction;
01343 if (STEREO_ON) {
01344
01345 viewport_sz_y = launch_dim.y >> 1;
01346 if (launch_index.y >= viewport_sz_y) {
01347
01348 viewport_idx_y = launch_index.y - viewport_sz_y;
01349 eyepos = cam_pos + cam_U * cam_stereo_eyesep * 0.5f;
01350 } else {
01351
01352 viewport_idx_y = launch_index.y;
01353 eyepos = cam_pos - cam_U * cam_stereo_eyesep * 0.5f;
01354 }
01355 view_direction = normalize(cam_pos-eyepos + normalize(cam_W) * cam_stereo_convergence_dist);
01356 } else {
01357
01358 viewport_sz_y = launch_dim.y;
01359 viewport_idx_y = launch_index.y;
01360 eyepos = cam_pos;
01361 view_direction = normalize(cam_W);
01362 }
01363
01364
01365
01366
01367 float2 aspect = make_float2(float(launch_dim.x) / float(viewport_sz_y), 1.0f) * cam_zoom;
01368 float2 viewportscale = 1.0f / make_float2(launch_dim.x, viewport_sz_y);
01369
01370 float2 d = make_float2(launch_index.x, viewport_idx_y) * viewportscale * aspect * 2.f - aspect;
01371
01372 unsigned int randseed = tea<4>(launch_dim.x*(viewport_idx_y)+launch_index.x, subframe_count());
01373
01374 float3 col = make_float3(0.0f);
01375 float alpha = 0.0f;
01376 float3 ray_direction = view_direction;
01377 for (int s=0; s<aa_samples; s++) {
01378 float2 jxy;
01379 jitter_offset2f(randseed, jxy);
01380 jxy = jxy * viewportscale * aspect * 2.f + d;
01381 float3 ray_origin = eyepos + jxy.x*cam_U + jxy.y*cam_V;
01382
01383
01384 if (DOF_ON) {
01385 dof_ray(ray_origin, ray_origin, view_direction, ray_direction,
01386 randseed, cam_V, cam_U);
01387 }
01388
01389
01390 PerRayData_radiance prd;
01391 prd.importance = 1.f;
01392 prd.alpha = 1.f;
01393 prd.depth = 0;
01394 prd.transcnt = max_trans;
01395 optix::Ray ray = optix::make_Ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon, RT_DEFAULT_MAX);
01396 rtTrace(root_object, ray, prd);
01397 col += prd.result;
01398 alpha += prd.alpha;
01399 }
01400 #if defined(ORT_RAYSTATS)
01401 raystats1_buffer[launch_index].x+=aa_samples;
01402 #endif
01403
01404 #if defined(ORT_TIME_COLORING)
01405 accumulate_time_coloring(col, t0);
01406 #else
01407 accumulate_color(col, alpha);
01408 #endif
01409 }
01410
01411 RT_PROGRAM void vmd_camera_orthographic() {
01412 vmd_camera_orthographic_general<0, 0>();
01413 }
01414
01415 RT_PROGRAM void vmd_camera_orthographic_dof() {
01416 vmd_camera_orthographic_general<0, 1>();
01417 }
01418
01419 RT_PROGRAM void vmd_camera_orthographic_stereo() {
01420 vmd_camera_orthographic_general<1, 0>();
01421 }
01422
01423 RT_PROGRAM void vmd_camera_orthographic_stereo_dof() {
01424 vmd_camera_orthographic_general<1, 1>();
01425 }
01426
01427
01428
01429
01430
01431 RT_PROGRAM void exception() {
01432 const unsigned int code = rtGetExceptionCode();
01433 switch (code) {
01434 case RT_EXCEPTION_STACK_OVERFLOW:
01435 rtPrintf("Stack overflow at launch index (%d,%d):\n",
01436 launch_index.x, launch_index.y );
01437 break;
01438
01439 #if OPTIX_VERSION >= 3050
01440 case RT_EXCEPTION_TEXTURE_ID_INVALID:
01441 case RT_EXCEPTION_BUFFER_ID_INVALID:
01442 #endif
01443 case RT_EXCEPTION_INDEX_OUT_OF_BOUNDS:
01444 case RT_EXCEPTION_BUFFER_INDEX_OUT_OF_BOUNDS:
01445 case RT_EXCEPTION_INVALID_RAY:
01446 case RT_EXCEPTION_INTERNAL_ERROR:
01447 case RT_EXCEPTION_USER:
01448 default:
01449 printf("Caught exception 0x%X (%d) at launch index (%d,%d)\n",
01450 code, code, launch_index.x, launch_index.y );
01451 break;
01452 }
01453
01454 #ifndef VMDOPTIX_PROGRESSIVEAPI
01455 framebuffer[launch_index] = make_color_rgb4u(make_float3(0.f, 0.f, 0.f));
01456 #endif
01457 }
01458
01459
01460
01461
01462
01463 static __device__ float fog_coord(float3 hit_point) {
01464 #if defined(CADENSMOVIE)
01465
01466
01467 float r = t_hit;
01468 #else
01469
01470
01471 float r = dot(ray.direction, cam_W) * t_hit;
01472 #endif
01473
01474 float f=1.0f;
01475 float v;
01476
01477 switch (fog_mode) {
01478 case 1:
01479 f = (fog_end - r) / (fog_end - fog_start);
01480 break;
01481
01482 case 2:
01483
01484
01485
01486 v = fog_density * r;
01487 f = expf(-v);
01488 break;
01489
01490 case 3:
01491
01492
01493
01494 v = fog_density * r;
01495 f = expf(-v*v);
01496 break;
01497
01498 case 0:
01499 default:
01500 break;
01501 }
01502
01503 return __saturatef(f);
01504 }
01505
01506
01507 static __device__ float3 fog_color(float fogmod, float3 hit_col) {
01508 float3 col = (fogmod * hit_col) + ((1.0f - fogmod) * scene_bg_color);
01509 return col;
01510 }
01511
01512
01513
01514
01515
01516
01517 static __device__ float3 shade_ambient_occlusion(float3 hit, float3 N, float aoimportance) {
01518
01519 float lightscale = 2.0f / ao_samples;
01520 float3 inten = make_float3(0.0f);
01521
01522 unsigned int randseed = tea<2>(subframe_count(), subframe_count());
01523
01524 PerRayData_shadow shadow_prd;
01525 #if 1
01526
01527 for (int s=0; s<ao_samples; s++) {
01528 #else
01529
01530
01531
01532
01533
01534
01535
01536
01537 int nsamples = ao_samples * prd.importance * aoimportance;
01538 if (nsamples < 1)
01539 nsamples=1;
01540 lightscale = 2.0f / nsamples;
01541 for (int s=0; s<nsamples; s++) {
01542 #endif
01543 float3 dir;
01544 jitter_sphere3f(randseed, dir);
01545 float ndotambl = dot(N, dir);
01546
01547
01548 if (ndotambl < 0.0f) {
01549 ndotambl = -ndotambl;
01550 dir = -dir;
01551 }
01552
01553 Ray ambray;
01554 #ifdef USE_REVERSE_SHADOW_RAYS
01555 if (shadows_enabled == RT_SHADOWS_ON_REVERSE) {
01556
01557
01558
01559
01560
01561
01562
01563
01564 float tmax = REVERSE_RAY_LENGTH - REVERSE_RAY_STEP;
01565 ambray = make_Ray(hit + dir * REVERSE_RAY_LENGTH, -dir, shadow_ray_type, 0, tmax);
01566 } else
01567 #endif
01568 #if defined(ORT_USE_RAY_STEP)
01569 ambray = make_Ray(hit + ORT_RAY_STEP, dir, shadow_ray_type, scene_epsilon, ao_maxdist);
01570 #else
01571 ambray = make_Ray(hit, dir, shadow_ray_type, scene_epsilon, ao_maxdist);
01572 #endif
01573 shadow_prd.attenuation = make_float3(1.0f);
01574
01575
01576
01577
01578 rtTrace(root_shadower, ambray, shadow_prd);
01579 inten += ndotambl * shadow_prd.attenuation;
01580 }
01581 #if defined(ORT_RAYSTATS)
01582 raystats1_buffer[launch_index].z+=ao_samples;
01583 #endif
01584
01585 return inten * lightscale;
01586 }
01587
01588
01589 template<int SHADOWS_ON>
01590 static __device__ __inline__ void shade_light(float3 &result,
01591 float3 &hit_point,
01592 float3 &N, float3 &L,
01593 float p_Kd,
01594 float p_Ks,
01595 float p_phong_exp,
01596 float3 &col,
01597 float3 &phongcol,
01598 float shadow_tmax) {
01599 float inten = dot(N, L);
01600
01601
01602 float3 light_attenuation = make_float3(static_cast<float>(inten > 0.0f));
01603 if (SHADOWS_ON && shadows_enabled && inten > 0.0f) {
01604 PerRayData_shadow shadow_prd;
01605 shadow_prd.attenuation = make_float3(1.0f);
01606
01607 Ray shadow_ray;
01608 #ifdef USE_REVERSE_SHADOW_RAYS
01609 if (shadows_enabled == RT_SHADOWS_ON_REVERSE) {
01610
01611
01612
01613
01614
01615
01616
01617
01618 float tmax = REVERSE_RAY_LENGTH - REVERSE_RAY_STEP;
01619 shadow_ray = make_Ray(hit_point + L * REVERSE_RAY_LENGTH, -L, shadow_ray_type, 0, fminf(tmax, shadow_tmax));
01620 }
01621 else
01622 #endif
01623 shadow_ray = make_Ray(hit_point + ORT_RAY_STEP, L, shadow_ray_type, scene_epsilon, shadow_tmax);
01624
01625
01626
01627
01628 rtTrace(root_shadower, shadow_ray, shadow_prd);
01629 #if defined(ORT_RAYSTATS)
01630 raystats1_buffer[launch_index].y++;
01631 #endif
01632 light_attenuation = shadow_prd.attenuation;
01633 }
01634
01635
01636
01637 if (!SHADOWS_ON || fmaxf(light_attenuation) > 0.0f) {
01638 result += col * p_Kd * inten * light_attenuation;
01639
01640
01641 float3 H = normalize(L - ray.direction);
01642 float nDh = dot(N, H);
01643 if (nDh > 0) {
01644 float power = powf(nDh, p_phong_exp);
01645 phongcol += make_float3(p_Ks) * power * light_attenuation;
01646 }
01647 }
01648 }
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673 template<int CLIP_VIEW_ON,
01674 int HEADLIGHT_ON,
01675 int FOG_ON,
01676 int SHADOWS_ON,
01677 int AO_ON,
01678 int OUTLINE_ON,
01679 int REFLECTION_ON,
01680 int TRANSMISSION_ON>
01681 static __device__ void shader_template(float3 p_obj_color, float3 N,
01682 float p_Ka, float p_Kd, float p_Ks,
01683 float p_phong_exp, float p_reflectivity,
01684 float p_opacity,
01685 float p_outline, float p_outlinewidth,
01686 int p_transmode) {
01687 float3 hit_point = ray.origin + t_hit * ray.direction;
01688 float3 result = make_float3(0.0f);
01689 float3 phongcol = make_float3(0.0f);
01690
01691
01692
01693 float fogmod = 1.0f;
01694 if (FOG_ON && fog_mode != 0) {
01695 fogmod = fog_coord(hit_point);
01696 }
01697
01698 #if 1
01699
01700
01701
01702 float Ntest = N.x + N.y + N.z;
01703 if (isnan(Ntest) || isinf(Ntest)) {
01704
01705 if (FOG_ON && fogmod < 1.0f) {
01706 result = fog_color(fogmod, result);
01707 }
01708 return;
01709 }
01710 #endif
01711
01712 #if 1
01713
01714
01715
01716 if ((p_opacity < 1.0f) && (prd.transcnt < 1)) {
01717
01718 PerRayData_radiance new_prd;
01719 new_prd.importance = prd.importance * (1.0f - p_opacity);
01720 new_prd.alpha = 1.0f;
01721 new_prd.result = scene_bg_color;
01722
01723
01724
01725
01726
01727
01728
01729
01730 new_prd.depth = prd.depth + 1;
01731
01732
01733 new_prd.transcnt = 0;
01734 if (new_prd.importance >= 0.001f && new_prd.depth < max_depth) {
01735 #if defined(ORT_USE_RAY_STEP)
01736 #if defined(ORT_TRANS_USE_INCIDENT)
01737
01738 Ray trans_ray = make_Ray(hit_point + ORT_RAY_STEP2, ray.direction, radiance_ray_type, scene_epsilon, RT_DEFAULT_MAX);
01739 #else
01740
01741
01742 Ray trans_ray = make_Ray(hit_point - ORT_RAY_STEP, ray.direction, radiance_ray_type, scene_epsilon, RT_DEFAULT_MAX);
01743 #endif
01744 #else
01745 Ray trans_ray = make_Ray(hit_point, ray.direction, radiance_ray_type, scene_epsilon, RT_DEFAULT_MAX);
01746 #endif
01747 rtTrace(root_object, trans_ray, new_prd);
01748 #if defined(ORT_RAYSTATS)
01749 raystats2_buffer[launch_index].x++;
01750 #endif
01751 }
01752 prd.result = new_prd.result;
01753 return;
01754 }
01755 #endif
01756
01757
01758 float3 col = p_obj_color;
01759
01760
01761 #if defined(VMDOPTIX_LIGHTUSEROBJS)
01762 unsigned int num_dir_lights = dir_light_list.num_lights;
01763 for (int i = 0; i < num_dir_lights; ++i) {
01764 float3 L = dir_light_list.dirs[i];
01765 #else
01766 unsigned int num_dir_lights = dir_lights.size();
01767 for (int i = 0; i < num_dir_lights; ++i) {
01768 DirectionalLight light = dir_lights[i];
01769 float3 L = light.dir;
01770 #endif
01771 shade_light<SHADOWS_ON>(result, hit_point, N, L, p_Kd, p_Ks, p_phong_exp,
01772 col, phongcol, RT_DEFAULT_MAX);
01773 }
01774
01775 #if 0
01776
01777 #if defined(VMDOPTIX_LIGHTUSEROBJS)
01778 unsigned int num_pos_lights = pos_light_list.num_lights;
01779 for (int i = 0; i < num_pos_lights; ++i) {
01780 float3 L = pos_light_list.posns[i];
01781 #else
01782 unsigned int num_pos_lights = pos_lights.size();
01783 for (int i = 0; i < num_pos_lights; ++i) {
01784 PositionalLight light = pos_lights[i];
01785 float3 L = light.pos - hit_point;
01786 #endif
01787 float shadow_tmax = length(L);
01788 L = normalize(L);
01789 shade_light<SHADOWS_ON>(result, hit_point, N, L, p_Kd, p_Ks, p_phong_exp,
01790 col, phongcol, shadow_tmax);
01791 }
01792 #endif
01793
01794
01795
01796 if (HEADLIGHT_ON && (headlight_mode != 0)) {
01797 float3 L = cam_pos - hit_point;
01798 float shadow_tmax = length(L);
01799 L = normalize(L);
01800 shade_light<SHADOWS_ON>(result, hit_point, N, L, p_Kd, p_Ks, p_phong_exp,
01801 col, phongcol, shadow_tmax);
01802 }
01803
01804
01805 if (AO_ON && ao_samples > 0) {
01806 result *= ao_direct;
01807 result += ao_ambient * col * p_Kd * shade_ambient_occlusion(hit_point, N, fogmod * p_opacity);
01808 }
01809
01810
01811 if (OUTLINE_ON && p_outline > 0.0f) {
01812 float edgefactor = dot(N, ray.direction);
01813 edgefactor *= edgefactor;
01814 edgefactor = 1.0f - edgefactor;
01815 edgefactor = 1.0f - powf(edgefactor, (1.0f - p_outlinewidth) * 32.0f);
01816 float outlinefactor = __saturatef((1.0f - p_outline) + (edgefactor * p_outline));
01817 result *= outlinefactor;
01818 }
01819
01820 result += make_float3(p_Ka);
01821 result += phongcol;
01822
01823
01824 if (REFLECTION_ON && p_reflectivity > 0.0f) {
01825
01826 PerRayData_radiance new_prd;
01827 new_prd.importance = prd.importance * p_reflectivity;
01828 new_prd.depth = prd.depth + 1;
01829 new_prd.transcnt = prd.transcnt;
01830
01831
01832 if (new_prd.importance >= 0.001f && new_prd.depth < max_depth) {
01833 float3 refl_dir = reflect(ray.direction, N);
01834 #if defined(ORT_USE_RAY_STEP)
01835 Ray refl_ray = make_Ray(hit_point + ORT_RAY_STEP, refl_dir, radiance_ray_type, scene_epsilon, RT_DEFAULT_MAX);
01836 #else
01837 Ray refl_ray = make_Ray(hit_point, refl_dir, radiance_ray_type, scene_epsilon, RT_DEFAULT_MAX);
01838 #endif
01839 rtTrace(root_object, refl_ray, new_prd);
01840 #if defined(ORT_RAYSTATS)
01841 raystats2_buffer[launch_index].w++;
01842 #endif
01843 result += p_reflectivity * new_prd.result;
01844 }
01845 }
01846
01847
01848 float alpha = p_opacity;
01849
01850 #if 1
01851 if (CLIP_VIEW_ON && (clipview_mode == 2))
01852 sphere_fade_and_clip(hit_point, cam_pos,
01853 clipview_start, clipview_end, alpha);
01854 #else
01855 if (CLIP_VIEW_ON && (clipview_mode == 2)) {
01856
01857 float fade_start = 1.00f;
01858 float fade_end = 0.20f;
01859 float camdist = length(hit_point - cam_pos);
01860
01861
01862
01863 float fade_len = fade_start - fade_end;
01864 alpha *= __saturatef((camdist - fade_start) / fade_len);
01865
01866 }
01867 #endif
01868
01869
01870
01871
01872
01873
01874 #if defined(CADENSMOVIE)
01875
01876
01877 if ((p_transmode>1 || (TRANSMISSION_ON || CLIP_VIEW_ON)) && alpha < 0.999f ) {
01878
01879 switch(int(p_transmode)) {
01880
01881 case 3:
01882 alpha = 1.0f + cosf(3.1415926f * (1.0f-alpha) * dot(N, ray.direction));
01883 alpha = alpha*alpha * 0.165;
01884 break;
01885
01886 case 2: {
01887
01888 float d = fminf( dot(N, ray.direction), 0.5f );
01889 float v = alpha * fabsf(d*d);
01890 result = 3.5f * v * result;
01891 alpha = v*0.15;
01892
01893
01894 break;
01895 }
01896
01897 case 1:
01898
01899 alpha = 1.0f + cosf(3.1415926f * (1.0f-alpha) * dot(N, ray.direction));
01900 alpha = alpha*alpha * 0.25f;
01901 break;
01902 }
01903 #else
01904 if ((TRANSMISSION_ON || CLIP_VIEW_ON) && alpha < 0.999f ) {
01905
01906 if (p_transmode) {
01907 alpha = 1.0f + cosf(3.1415926f * (1.0f-alpha) * dot(N, ray.direction));
01908 alpha = alpha*alpha * 0.25f;
01909 }
01910 #endif
01911
01912 result *= alpha;
01913
01914
01915 PerRayData_radiance new_prd;
01916 new_prd.importance = prd.importance * (1.0f - alpha);
01917 new_prd.alpha = 1.0f;
01918 new_prd.result = scene_bg_color;
01919 new_prd.depth = prd.depth + 1;
01920 new_prd.transcnt = max(1, prd.transcnt) - 1;
01921 if (new_prd.importance >= 0.001f && new_prd.depth < max_depth) {
01922 #if defined(ORT_USE_RAY_STEP)
01923 #if defined(ORT_TRANS_USE_INCIDENT)
01924
01925 Ray trans_ray = make_Ray(hit_point + ORT_RAY_STEP2, ray.direction, radiance_ray_type, scene_epsilon, RT_DEFAULT_MAX);
01926 #else
01927
01928
01929 Ray trans_ray = make_Ray(hit_point - ORT_RAY_STEP, ray.direction, radiance_ray_type, scene_epsilon, RT_DEFAULT_MAX);
01930 #endif
01931 #else
01932 Ray trans_ray = make_Ray(hit_point, ray.direction, radiance_ray_type, scene_epsilon, RT_DEFAULT_MAX);
01933 #endif
01934 rtTrace(root_object, trans_ray, new_prd);
01935 #if defined(ORT_RAYSTATS)
01936 raystats2_buffer[launch_index].x++;
01937 #endif
01938 }
01939 result += (1.0f - alpha) * new_prd.result;
01940 prd.alpha = alpha + (1.0f - alpha) * new_prd.alpha;
01941 }
01942
01943
01944 if (FOG_ON && fogmod < 1.0f) {
01945 result = fog_color(fogmod, result);
01946 }
01947
01948 prd.result = result;
01949 }
01950
01951
01952
01953
01954 rtDeclareVariable(float3, uniform_color, , );
01955
01956
01957 rtDeclareVariable(float, Ka, , );
01958 rtDeclareVariable(float, Kd, , );
01959 rtDeclareVariable(float, Ks, , );
01960 rtDeclareVariable(float, phong_exp, , );
01961 rtDeclareVariable(float, Krefl, , );
01962 rtDeclareVariable(float, opacity, , );
01963 rtDeclareVariable(float, outline, , );
01964 rtDeclareVariable(float, outlinewidth, , );
01965 rtDeclareVariable(int, transmode, , );
01966
01967
01968
01969 RT_PROGRAM void any_hit_opaque() {
01970
01971 prd_shadow.attenuation = optix::make_float3(0.0f);
01972
01973
01974
01975 rtTerminateRay();
01976 }
01977
01978
01979
01980 RT_PROGRAM void any_hit_transmission() {
01981
01982 prd_shadow.attenuation *= make_float3(1.0f - opacity);
01983
01984
01985 if (fmaxf(prd_shadow.attenuation) < 0.001f) {
01986 rtTerminateRay();
01987 } else {
01988 #if defined(ORT_RAYSTATS)
01989 raystats2_buffer[launch_index].y++;
01990 #endif
01991 rtIgnoreIntersection();
01992 }
01993 }
01994
01995
01996
01997
01998
01999 RT_PROGRAM void any_hit_clip_sphere() {
02000
02001
02002 float3 hit_point = ray.origin + t_hit * ray.direction;
02003
02004
02005 float clipalpha = 1.0f;
02006 if (clipview_mode == 2) {
02007 sphere_fade_and_clip(hit_point, cam_pos, clipview_start, clipview_end,
02008 clipalpha);
02009 }
02010
02011
02012 prd_shadow.attenuation = make_float3(1.0f - (clipalpha * opacity));
02013
02014
02015 if (fmaxf(prd_shadow.attenuation) < 0.001f) {
02016 rtTerminateRay();
02017 } else {
02018 #if defined(ORT_RAYSTATS)
02019 raystats2_buffer[launch_index].y++;
02020 #endif
02021 rtIgnoreIntersection();
02022 }
02023 }
02024
02025
02026
02027
02028
02029
02030 static __inline__ __device__ float3 calc_ffworld_normal(const float3 &Nshading, const float3 &Ngeometric) {
02031 float3 world_shading_normal = normalize(rtTransformNormal(RT_OBJECT_TO_WORLD, Nshading));
02032 float3 world_geometric_normal = normalize(rtTransformNormal(RT_OBJECT_TO_WORLD, Ngeometric));
02033 return faceforward(world_shading_normal, -ray.direction, world_geometric_normal);
02034 }
02035
02036
02037 template<int HWTRIANGLES> static __device__ __inline__
02038 float3 get_intersection_normal() {
02039 #if defined(ORT_USERTXAPIS)
02040
02041 if (HWTRIANGLES) {
02042 const unsigned int primIdx = rtGetPrimitiveIndex();
02043 const float3 Ng = unpackNormal(normalBuffer[primIdx].x);
02044 float3 Ns;
02045 if (has_vertex_normals) {
02046 const float3& n0 = unpackNormal(normalBuffer[primIdx].y);
02047 const float3& n1 = unpackNormal(normalBuffer[primIdx].z);
02048 const float3& n2 = unpackNormal(normalBuffer[primIdx].w);
02049 Ns = optix::normalize(n0 * (1.0f - barycentrics.x - barycentrics.y) +
02050 n1 * barycentrics.x +
02051 n2 * barycentrics.y);
02052 } else {
02053 Ns = Ng;
02054 }
02055 return calc_ffworld_normal(Ns, Ng);
02056 } else {
02057
02058 return calc_ffworld_normal(shading_normal, geometric_normal);
02059 }
02060 #else
02061
02062 return calc_ffworld_normal(shading_normal, geometric_normal);
02063 #endif
02064 }
02065
02066
02067 template<int HWTRIANGLES> static __device__ __inline__
02068 float3 get_intersection_color() {
02069 #if defined(ORT_USERTXAPIS)
02070
02071 if (HWTRIANGLES) {
02072 if (has_vertex_colors) {
02073 const float ci2f = 1.0f / 255.0f;
02074 const unsigned int primIdx = rtGetPrimitiveIndex();
02075 const float3 c0 = colorBuffer[3 * primIdx + 0] * ci2f;
02076 const float3 c1 = colorBuffer[3 * primIdx + 1] * ci2f;
02077 const float3 c2 = colorBuffer[3 * primIdx + 2] * ci2f;
02078
02079
02080 return (c0 * (1.0f - barycentrics.x - barycentrics.y) +
02081 c1 * barycentrics.x +
02082 c2 * barycentrics.y);
02083 } else {
02084 return uniform_color;
02085 }
02086 } else {
02087
02088 return obj_color;
02089 }
02090 #else
02091
02092 return obj_color;
02093 #endif
02094 }
02095
02096
02097
02098
02099
02100 RT_PROGRAM void closest_hit_radiance_general() {
02101 shader_template<1, 1, 1, 1, 1, 1, 1, 1>(get_intersection_color<0>(),
02102 get_intersection_normal<0>(),
02103 Ka, Kd, Ks, phong_exp, Krefl, opacity,
02104 outline, outlinewidth, transmode);
02105 }
02106
02107 #if defined(ORT_USERTXAPIS)
02108
02109 RT_PROGRAM void closest_hit_radiance_general_hwtri() {
02110 shader_template<1, 1, 1, 1, 1, 1, 1, 1>(get_intersection_color<1>(),
02111 get_intersection_normal<1>(),
02112 Ka, Kd, Ks, phong_exp, Krefl, opacity,
02113 outline, outlinewidth, transmode);
02114 }
02115 #endif
02116
02117
02118
02119
02120
02121
02122
02123 rtBuffer<vmd_cylinder> cylinder_buffer;
02124 rtBuffer<vmd_cylinder_color> cylinder_color_buffer;
02125
02126
02127 rtBuffer<vmd_ring_color> ring_color_buffer;
02128
02129
02130 rtBuffer<vmd_sphere> sphere_buffer;
02131 rtBuffer<vmd_sphere_color> sphere_color_buffer;
02132
02133
02134 rtBuffer<vmd_tricolor> tricolor_buffer;
02135 rtBuffer<vmd_trimesh_c4u_n3b_v3f> trimesh_c4u_n3b_v3f_buffer;
02136 rtBuffer<vmd_trimesh_n3f_v3f> trimesh_n3f_v3f_buffer;
02137 rtBuffer<vmd_trimesh_n3b_v3f> trimesh_n3b_v3f_buffer;
02138 rtBuffer<vmd_trimesh_v3f> trimesh_v3f_buffer;
02139
02140
02141
02142
02143
02144 RT_PROGRAM void cylinder_array_intersect(int primIdx) {
02145 float3 start = cylinder_buffer[primIdx].start;
02146 float radius = cylinder_buffer[primIdx].radius;
02147 float3 axis = cylinder_buffer[primIdx].axis;
02148
02149 float3 rc = ray.origin - start;
02150 float3 n = cross(ray.direction, axis);
02151 float ln = length(n);
02152
02153
02154 if (ln == 0.0f) {
02155 return;
02156 }
02157 n /= ln;
02158 float d = fabsf(dot(rc, n));
02159
02160
02161 if (d <= radius) {
02162 float3 O = cross(rc, axis);
02163 float t = -dot(O, n) / ln;
02164 O = cross(n, axis);
02165 O = normalize(O);
02166 float s = dot(ray.direction, O);
02167 s = fabs(sqrtf(radius*radius - d*d) / s);
02168 float axlen = length(axis);
02169 float3 axis_u = normalize(axis);
02170
02171
02172 float tin = t - s;
02173 float3 hit = ray.origin + ray.direction * tin;
02174 float3 tmp2 = hit - start;
02175 float tmp = dot(tmp2, axis_u);
02176 if ((tmp > 0.0f) && (tmp < axlen)) {
02177 if (rtPotentialIntersection(tin)) {
02178 shading_normal = geometric_normal = normalize(hit - (tmp * axis_u + start));
02179
02180
02181 obj_color = uniform_color;
02182 rtReportIntersection(0);
02183 }
02184 }
02185
02186
02187 float tout = t + s;
02188 hit = ray.origin + ray.direction * tout;
02189 tmp2 = hit - start;
02190 tmp = dot(tmp2, axis_u);
02191 if ((tmp > 0.0f) && (tmp < axlen)) {
02192 if (rtPotentialIntersection(tout)) {
02193 shading_normal = geometric_normal = normalize(hit - (tmp * axis_u + start));
02194
02195
02196 obj_color = uniform_color;
02197 rtReportIntersection(0);
02198 }
02199 }
02200 }
02201 }
02202
02203
02204 RT_PROGRAM void cylinder_array_bounds(int primIdx, float result[6]) {
02205 const float3 start = cylinder_buffer[primIdx].start;
02206 const float3 end = start + cylinder_buffer[primIdx].axis;
02207 const float3 rad = make_float3(cylinder_buffer[primIdx].radius);
02208 optix::Aabb* aabb = (optix::Aabb*)result;
02209
02210 if (rad.x > 0.0f && !isinf(rad.x)) {
02211 aabb->m_min = fminf(start - rad, end - rad);
02212 aabb->m_max = fmaxf(start + rad, end + rad);
02213 } else {
02214 aabb->invalidate();
02215 }
02216 }
02217
02218
02219
02220
02221
02222 RT_PROGRAM void cylinder_array_color_intersect(int primIdx) {
02223 float3 start = cylinder_color_buffer[primIdx].start;
02224 float radius = cylinder_color_buffer[primIdx].radius;
02225 float3 axis = cylinder_color_buffer[primIdx].axis;
02226
02227 float3 rc = ray.origin - start;
02228 float3 n = cross(ray.direction, axis);
02229 float ln = length(n);
02230
02231
02232 if (ln == 0.0f) {
02233 return;
02234 }
02235 n /= ln;
02236 float d = fabsf(dot(rc, n));
02237
02238
02239 if (d <= radius) {
02240 float3 O = cross(rc, axis);
02241 float t = -dot(O, n) / ln;
02242 O = cross(n, axis);
02243 O = normalize(O);
02244 float s = dot(ray.direction, O);
02245 s = fabs(sqrtf(radius*radius - d*d) / s);
02246 float axlen = length(axis);
02247 float3 axis_u = normalize(axis);
02248
02249
02250 float tin = t - s;
02251 float3 hit = ray.origin + ray.direction * tin;
02252 float3 tmp2 = hit - start;
02253 float tmp = dot(tmp2, axis_u);
02254 if ((tmp > 0.0f) && (tmp < axlen)) {
02255 if (rtPotentialIntersection(tin)) {
02256 shading_normal = geometric_normal = normalize(hit - (tmp * axis_u + start));
02257 obj_color = cylinder_color_buffer[primIdx].color;
02258 rtReportIntersection(0);
02259 }
02260 }
02261
02262
02263 float tout = t + s;
02264 hit = ray.origin + ray.direction * tout;
02265 tmp2 = hit - start;
02266 tmp = dot(tmp2, axis_u);
02267 if ((tmp > 0.0f) && (tmp < axlen)) {
02268 if (rtPotentialIntersection(tout)) {
02269 shading_normal = geometric_normal = normalize(hit - (tmp * axis_u + start));
02270 obj_color = cylinder_color_buffer[primIdx].color;
02271 rtReportIntersection(0);
02272 }
02273 }
02274 }
02275 }
02276
02277
02278 RT_PROGRAM void cylinder_array_color_bounds(int primIdx, float result[6]) {
02279 const float3 start = cylinder_color_buffer[primIdx].start;
02280 const float3 end = start + cylinder_color_buffer[primIdx].axis;
02281 const float3 rad = make_float3(cylinder_color_buffer[primIdx].radius);
02282 optix::Aabb* aabb = (optix::Aabb*)result;
02283
02284 if (rad.x > 0.0f && !isinf(rad.x)) {
02285 aabb->m_min = fminf(start - rad, end - rad);
02286 aabb->m_max = fmaxf(start + rad, end + rad);
02287 } else {
02288 aabb->invalidate();
02289 }
02290 }
02291
02292
02293
02294
02295
02296 RT_PROGRAM void ring_array_color_intersect(int primIdx) {
02297 const float3 center = ring_color_buffer[primIdx].center;
02298 const float3 norm = ring_color_buffer[primIdx].norm;
02299 const float inrad = ring_color_buffer[primIdx].inrad;
02300 const float outrad = ring_color_buffer[primIdx].outrad;
02301 const float3 color = ring_color_buffer[primIdx].color;
02302
02303 float d = -dot(center, norm);
02304 float t = -(d + dot(norm, ray.origin));
02305 float td = dot(norm, ray.direction);
02306 if (td != 0.0f) {
02307 t /= td;
02308 if (t >= 0.0f) {
02309 float3 hit = ray.origin + t * ray.direction;
02310 float rd = length(hit - center);
02311 if ((rd > inrad) && (rd < outrad)) {
02312 if (rtPotentialIntersection(t)) {
02313 shading_normal = geometric_normal = norm;
02314 obj_color = color;
02315 rtReportIntersection(0);
02316 }
02317 }
02318 }
02319 }
02320 }
02321
02322
02323 RT_PROGRAM void ring_array_color_bounds(int primIdx, float result[6]) {
02324 const float3 center = ring_color_buffer[primIdx].center;
02325 const float3 rad = make_float3(ring_color_buffer[primIdx].outrad);
02326 optix::Aabb* aabb = (optix::Aabb*)result;
02327
02328 if (rad.x > 0.0f && !isinf(rad.x)) {
02329 aabb->m_min = center - rad;
02330 aabb->m_max = center + rad;
02331 } else {
02332 aabb->invalidate();
02333 }
02334 }
02335
02336
02337
02338 #if defined(ORT_USE_SPHERES_HEARNBAKER)
02339
02340
02341
02342
02343
02344
02345
02346 static __host__ __device__ __inline__
02347 void sphere_intersect_hearn_baker2(float3 center, float radius,
02348 const float3 &spcolor) {
02349 float3 deltap = center - ray.origin;
02350 float ddp = dot(ray.direction, deltap);
02351 float3 remedyTerm = deltap - ddp * ray.direction;
02352 float disc = radius*radius - dot(remedyTerm, remedyTerm);
02353 if (disc >= 0.0f) {
02354 float disc_root = sqrtf(disc);
02355 float t1 = ddp - disc_root;
02356 float t2 = ddp + disc_root;
02357
02358 if (rtPotentialIntersection(t1)) {
02359 shading_normal = geometric_normal = (t1*ray.direction - deltap) / radius;
02360 obj_color = spcolor;
02361 rtReportIntersection(0);
02362 }
02363
02364 if (rtPotentialIntersection(t2)) {
02365 shading_normal = geometric_normal = (t2*ray.direction - deltap) / radius;
02366 obj_color = spcolor;
02367 rtReportIntersection(0);
02368 }
02369 }
02370 }
02371
02372 #else
02373
02374
02375
02376
02377 static __host__ __device__ __inline__
02378 void sphere_intersect_classic(float3 center, float radius,
02379 const float3 &spcolor) {
02380 float3 V = center - ray.origin;
02381 float b = dot(V, ray.direction);
02382 float disc = b*b + radius*radius - dot(V, V);
02383 if (disc > 0.0f) {
02384 disc = sqrtf(disc);
02385
02386
02387 #if defined(FASTONESIDEDSPHERES)
02388
02389 float t1 = b - disc;
02390 if (rtPotentialIntersection(t1)) {
02391 shading_normal = geometric_normal = (t1*ray.direction - V) / radius;
02392 obj_color = spcolor;
02393 rtReportIntersection(0);
02394 }
02395 #else
02396 float t2 = b + disc;
02397 if (rtPotentialIntersection(t2)) {
02398 shading_normal = geometric_normal = (t2*ray.direction - V) / radius;
02399 obj_color = spcolor;
02400 rtReportIntersection(0);
02401 }
02402
02403 float t1 = b - disc;
02404 if (rtPotentialIntersection(t1)) {
02405 shading_normal = geometric_normal = (t1*ray.direction - V) / radius;
02406 obj_color = spcolor;
02407 rtReportIntersection(0);
02408 }
02409 #endif
02410 }
02411 }
02412
02413 #endif
02414
02415
02416
02417
02418
02419 RT_PROGRAM void sphere_array_intersect(int primIdx) {
02420 float3 center = sphere_buffer[primIdx].center;
02421 float radius = sphere_buffer[primIdx].radius;
02422
02423
02424 #if defined(ORT_USE_SPHERES_HEARNBAKER)
02425 sphere_intersect_hearn_baker2(center, radius, uniform_color);
02426 #else
02427 sphere_intersect_classic(center, radius, uniform_color);
02428 #endif
02429 }
02430
02431
02432 RT_PROGRAM void sphere_array_bounds(int primIdx, float result[6]) {
02433 const float3 cen = sphere_buffer[primIdx].center;
02434 const float3 rad = make_float3(sphere_buffer[primIdx].radius);
02435 optix::Aabb* aabb = (optix::Aabb*)result;
02436
02437 if (rad.x > 0.0f && !isinf(rad.x)) {
02438 aabb->m_min = cen - rad;
02439 aabb->m_max = cen + rad;
02440 } else {
02441 aabb->invalidate();
02442 }
02443 }
02444
02445
02446
02447
02448
02449 RT_PROGRAM void sphere_array_color_intersect(int primIdx) {
02450 float3 center = sphere_color_buffer[primIdx].center;
02451 float radius = sphere_color_buffer[primIdx].radius;
02452
02453 #if defined(ORT_USE_SPHERES_HEARNBAKER)
02454 sphere_intersect_hearn_baker2(center, radius, sphere_color_buffer[primIdx].color);
02455 #else
02456 sphere_intersect_classic(center, radius, sphere_color_buffer[primIdx].color);
02457 #endif
02458 }
02459
02460
02461 RT_PROGRAM void sphere_array_color_bounds(int primIdx, float result[6]) {
02462 const float3 cen = sphere_color_buffer[primIdx].center;
02463 const float3 rad = make_float3(sphere_color_buffer[primIdx].radius);
02464 optix::Aabb* aabb = (optix::Aabb*)result;
02465
02466 if (rad.x > 0.0f && !isinf(rad.x)) {
02467 aabb->m_min = cen - rad;
02468 aabb->m_max = cen + rad;
02469 } else {
02470 aabb->invalidate();
02471 }
02472 }
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482 __device__ __inline__ void generic_tri_bounds(optix::Aabb *aabb,
02483 float3 v0, float3 v1, float3 v2) {
02484 #if 1
02485
02486 float area = length(cross(v1-v0, v2-v0));
02487 if (area > 0.0f && !isinf(area)) {
02488 aabb->m_min = fminf(fminf(v0, v1), v2);
02489 aabb->m_max = fmaxf(fmaxf(v0, v1), v2);
02490 } else {
02491 aabb->invalidate();
02492 }
02493 #else
02494
02495 aabb->m_min = fminf(fminf(v0, v1), v2);
02496 aabb->m_max = fmaxf(fmaxf(v0, v1), v2);
02497 #endif
02498 }
02499
02500
02501
02502 RT_PROGRAM void tricolor_intersect(int primIdx) {
02503 float3 v0 = tricolor_buffer[primIdx].v0;
02504 float3 v1 = tricolor_buffer[primIdx].v1;
02505 float3 v2 = tricolor_buffer[primIdx].v2;
02506
02507
02508 float3 n;
02509 float t, beta, gamma;
02510 if (intersect_triangle(ray, v0, v1, v2, n, t, beta, gamma)) {
02511 if (rtPotentialIntersection(t)) {
02512 float3 n0 = tricolor_buffer[primIdx].n0;
02513 float3 n1 = tricolor_buffer[primIdx].n1;
02514 float3 n2 = tricolor_buffer[primIdx].n2;
02515 shading_normal = normalize(n1*beta + n2*gamma + n0*(1.0f-beta-gamma));
02516 geometric_normal = normalize(n);
02517
02518 float3 c0 = tricolor_buffer[primIdx].c0;
02519 float3 c1 = tricolor_buffer[primIdx].c1;
02520 float3 c2 = tricolor_buffer[primIdx].c2;
02521 obj_color = c1*beta + c2*gamma + c0*(1.0f-beta-gamma);
02522 rtReportIntersection(0);
02523 }
02524 }
02525 }
02526
02527 RT_PROGRAM void tricolor_bounds(int primIdx, float result[6]) {
02528 float3 v0 = tricolor_buffer[primIdx].v0;
02529 float3 v1 = tricolor_buffer[primIdx].v1;
02530 float3 v2 = tricolor_buffer[primIdx].v2;
02531
02532 optix::Aabb *aabb = (optix::Aabb*)result;
02533 generic_tri_bounds(aabb, v0, v1, v2);
02534 }
02535
02536
02537
02538 RT_PROGRAM void trimesh_c4u_n3b_v3f_intersect(int primIdx) {
02539 float3 v0 = trimesh_c4u_n3b_v3f_buffer[primIdx].v0;
02540 float3 v1 = trimesh_c4u_n3b_v3f_buffer[primIdx].v1;
02541 float3 v2 = trimesh_c4u_n3b_v3f_buffer[primIdx].v2;
02542
02543
02544 float3 n;
02545 float t, beta, gamma;
02546 if (intersect_triangle(ray, v0, v1, v2, n, t, beta, gamma)) {
02547 if (rtPotentialIntersection(t)) {
02548
02549
02550 const float ci2f = 1.0f / 255.0f;
02551 const float cn2f = 1.0f / 127.5f;
02552
02553 float3 n0 = trimesh_c4u_n3b_v3f_buffer[primIdx].n0 * cn2f + ci2f;
02554 float3 n1 = trimesh_c4u_n3b_v3f_buffer[primIdx].n1 * cn2f + ci2f;
02555 float3 n2 = trimesh_c4u_n3b_v3f_buffer[primIdx].n2 * cn2f + ci2f;
02556 shading_normal = normalize(n1*beta + n2*gamma + n0*(1.0f-beta-gamma));
02557 geometric_normal = normalize(n);
02558
02559
02560
02561 float3 c0 = trimesh_c4u_n3b_v3f_buffer[primIdx].c0 * ci2f;
02562 float3 c1 = trimesh_c4u_n3b_v3f_buffer[primIdx].c1 * ci2f;
02563 float3 c2 = trimesh_c4u_n3b_v3f_buffer[primIdx].c2 * ci2f;
02564 obj_color = c1*beta + c2*gamma + c0*(1.0f-beta-gamma);
02565 rtReportIntersection(0);
02566 }
02567 }
02568 }
02569
02570 RT_PROGRAM void trimesh_c4u_n3b_v3f_bounds(int primIdx, float result[6]) {
02571 float3 v0 = trimesh_c4u_n3b_v3f_buffer[primIdx].v0;
02572 float3 v1 = trimesh_c4u_n3b_v3f_buffer[primIdx].v1;
02573 float3 v2 = trimesh_c4u_n3b_v3f_buffer[primIdx].v2;
02574
02575 optix::Aabb *aabb = (optix::Aabb*)result;
02576 generic_tri_bounds(aabb, v0, v1, v2);
02577 }
02578
02579
02580
02581 RT_PROGRAM void trimesh_n3f_v3f_intersect(int primIdx) {
02582 float3 v0 = trimesh_n3f_v3f_buffer[primIdx].v0;
02583 float3 v1 = trimesh_n3f_v3f_buffer[primIdx].v1;
02584 float3 v2 = trimesh_n3f_v3f_buffer[primIdx].v2;
02585
02586
02587 float3 n;
02588 float t, beta, gamma;
02589 if (intersect_triangle(ray, v0, v1, v2, n, t, beta, gamma)) {
02590 if (rtPotentialIntersection(t)) {
02591 float3 n0 = trimesh_n3f_v3f_buffer[primIdx].n0;
02592 float3 n1 = trimesh_n3f_v3f_buffer[primIdx].n1;
02593 float3 n2 = trimesh_n3f_v3f_buffer[primIdx].n2;
02594
02595 shading_normal = normalize(n1*beta + n2*gamma + n0*(1.0f-beta-gamma) );
02596 geometric_normal = normalize(n);
02597
02598
02599 obj_color = uniform_color;
02600 rtReportIntersection(0);
02601 }
02602 }
02603 }
02604
02605 RT_PROGRAM void trimesh_n3f_v3f_bounds(int primIdx, float result[6]) {
02606 float3 v0 = trimesh_n3f_v3f_buffer[primIdx].v0;
02607 float3 v1 = trimesh_n3f_v3f_buffer[primIdx].v1;
02608 float3 v2 = trimesh_n3f_v3f_buffer[primIdx].v2;
02609
02610 optix::Aabb *aabb = (optix::Aabb*)result;
02611 generic_tri_bounds(aabb, v0, v1, v2);
02612 }
02613
02614
02615
02616 RT_PROGRAM void trimesh_n3b_v3f_intersect(int primIdx) {
02617 float3 v0 = trimesh_n3b_v3f_buffer[primIdx].v0;
02618 float3 v1 = trimesh_n3b_v3f_buffer[primIdx].v1;
02619 float3 v2 = trimesh_n3b_v3f_buffer[primIdx].v2;
02620
02621
02622 float3 n;
02623 float t, beta, gamma;
02624 if (intersect_triangle(ray, v0, v1, v2, n, t, beta, gamma)) {
02625 if (rtPotentialIntersection(t)) {
02626
02627
02628 const float ci2f = 1.0f / 255.0f;
02629 const float cn2f = 1.0f / 127.5f;
02630
02631 float3 n0 = trimesh_n3b_v3f_buffer[primIdx].n0 * cn2f + ci2f;
02632 float3 n1 = trimesh_n3b_v3f_buffer[primIdx].n1 * cn2f + ci2f;
02633 float3 n2 = trimesh_n3b_v3f_buffer[primIdx].n2 * cn2f + ci2f;
02634 shading_normal = normalize(n1*beta + n2*gamma + n0*(1.0f-beta-gamma) );
02635 geometric_normal = normalize(n);
02636
02637
02638 obj_color = uniform_color;
02639 rtReportIntersection(0);
02640 }
02641 }
02642 }
02643
02644 RT_PROGRAM void trimesh_n3b_v3f_bounds(int primIdx, float result[6]) {
02645 float3 v0 = trimesh_n3b_v3f_buffer[primIdx].v0;
02646 float3 v1 = trimesh_n3b_v3f_buffer[primIdx].v1;
02647 float3 v2 = trimesh_n3b_v3f_buffer[primIdx].v2;
02648
02649 optix::Aabb *aabb = (optix::Aabb*)result;
02650 generic_tri_bounds(aabb, v0, v1, v2);
02651 }
02652
02653
02654 RT_PROGRAM void trimesh_v3f_intersect(int primIdx) {
02655 float3 v0 = trimesh_v3f_buffer[primIdx].v0;
02656 float3 v1 = trimesh_v3f_buffer[primIdx].v1;
02657 float3 v2 = trimesh_v3f_buffer[primIdx].v2;
02658
02659
02660 float3 n;
02661 float t, beta, gamma;
02662 if (intersect_triangle(ray, v0, v1, v2, n, t, beta, gamma)) {
02663 if (rtPotentialIntersection(t)) {
02664 shading_normal = geometric_normal = normalize(n);
02665
02666
02667 obj_color = uniform_color;
02668 rtReportIntersection(0);
02669 }
02670 }
02671 }
02672
02673 RT_PROGRAM void trimesh_v3f_bounds(int primIdx, float result[6]) {
02674 float3 v0 = trimesh_v3f_buffer[primIdx].v0;
02675 float3 v1 = trimesh_v3f_buffer[primIdx].v1;
02676 float3 v2 = trimesh_v3f_buffer[primIdx].v2;
02677
02678 optix::Aabb *aabb = (optix::Aabb*)result;
02679 generic_tri_bounds(aabb, v0, v1, v2);
02680 }
02681
02682
02683
02684
02685
02686
02687
02688
02689
02690
02691 #if defined(ORT_USE_TEMPLATE_SHADERS)
02692
02693 #define CLIP_VIEW_on 1
02694 #define CLIP_VIEW_off 0
02695 #define HEADLIGHT_on 1
02696 #define HEADLIGHT_off 0
02697 #define FOG_on 1
02698 #define FOG_off 0
02699 #define SHADOWS_on 1
02700 #define SHADOWS_off 0
02701 #define AO_on 1
02702 #define AO_off 0
02703 #define OUTLINE_on 1
02704 #define OUTLINE_off 0
02705 #define REFL_on 1
02706 #define REFL_off 0
02707 #define TRANS_on 1
02708 #define TRANS_off 0
02709
02710 #define DEFINE_CLOSEST_HIT( mclipview, mhlight, mfog, mshad, mao, moutl, mrefl, mtrans ) \
02711 RT_PROGRAM void \
02712 closest_hit_radiance_CLIP_VIEW_##mclipview##_HEADLIGHT_##mhlight##_FOG_##mfog##_SHADOWS_##mshad##_AO_##mao##_OUTLINE_##moutl##_REFL_##mrefl##_TRANS_##mtrans() { \
02713 \
02714 shader_template<CLIP_VIEW_##mclipview, \
02715 HEADLIGHT_##mhlight, \
02716 FOG_##mfog, \
02717 SHADOWS_##mshad, \
02718 AO_##mao, \
02719 OUTLINE_##moutl, \
02720 REFL_##mrefl, \
02721 TRANS_##mtrans > \
02722 (get_intersection_color<0>(), \
02723 get_intersection_normal<0>(), \
02724 Ka, Kd, Ks, phong_exp, Krefl, \
02725 opacity, outline, outlinewidth, transmode); \
02726 }
02727
02728
02729
02730
02731
02732
02733
02734 DEFINE_CLOSEST_HIT( on, on, on, on, on, on, on, on )
02735 DEFINE_CLOSEST_HIT( on, on, on, on, on, on, on, off )
02736
02737 DEFINE_CLOSEST_HIT( on, on, on, on, on, on, off, on )
02738 DEFINE_CLOSEST_HIT( on, on, on, on, on, on, off, off )
02739
02740 DEFINE_CLOSEST_HIT( on, on, on, on, on, off, on, on )
02741 DEFINE_CLOSEST_HIT( on, on, on, on, on, off, on, off )
02742
02743 DEFINE_CLOSEST_HIT( on, on, on, on, on, off, off, on )
02744 DEFINE_CLOSEST_HIT( on, on, on, on, on, off, off, off )
02745
02746 DEFINE_CLOSEST_HIT( on, on, on, on, off, on, on, on )
02747 DEFINE_CLOSEST_HIT( on, on, on, on, off, on, on, off )
02748
02749 DEFINE_CLOSEST_HIT( on, on, on, on, off, on, off, on )
02750 DEFINE_CLOSEST_HIT( on, on, on, on, off, on, off, off )
02751
02752 DEFINE_CLOSEST_HIT( on, on, on, on, off, off, on, on )
02753 DEFINE_CLOSEST_HIT( on, on, on, on, off, off, on, off )
02754
02755 DEFINE_CLOSEST_HIT( on, on, on, on, off, off, off, on )
02756 DEFINE_CLOSEST_HIT( on, on, on, on, off, off, off, off )
02757
02758
02759 DEFINE_CLOSEST_HIT( on, on, on, off, on, on, on, on )
02760 DEFINE_CLOSEST_HIT( on, on, on, off, on, on, on, off )
02761
02762 DEFINE_CLOSEST_HIT( on, on, on, off, on, on, off, on )
02763 DEFINE_CLOSEST_HIT( on, on, on, off, on, on, off, off )
02764
02765 DEFINE_CLOSEST_HIT( on, on, on, off, on, off, on, on )
02766 DEFINE_CLOSEST_HIT( on, on, on, off, on, off, on, off )
02767
02768 DEFINE_CLOSEST_HIT( on, on, on, off, on, off, off, on )
02769 DEFINE_CLOSEST_HIT( on, on, on, off, on, off, off, off )
02770
02771 DEFINE_CLOSEST_HIT( on, on, on, off, off, on, on, on )
02772 DEFINE_CLOSEST_HIT( on, on, on, off, off, on, on, off )
02773
02774 DEFINE_CLOSEST_HIT( on, on, on, off, off, on, off, on )
02775 DEFINE_CLOSEST_HIT( on, on, on, off, off, on, off, off )
02776
02777 DEFINE_CLOSEST_HIT( on, on, on, off, off, off, on, on )
02778 DEFINE_CLOSEST_HIT( on, on, on, off, off, off, on, off )
02779
02780 DEFINE_CLOSEST_HIT( on, on, on, off, off, off, off, on )
02781 DEFINE_CLOSEST_HIT( on, on, on, off, off, off, off, off )
02782
02783
02784
02785 DEFINE_CLOSEST_HIT( on, on, off, on, on, on, on, on )
02786 DEFINE_CLOSEST_HIT( on, on, off, on, on, on, on, off )
02787
02788 DEFINE_CLOSEST_HIT( on, on, off, on, on, on, off, on )
02789 DEFINE_CLOSEST_HIT( on, on, off, on, on, on, off, off )
02790
02791 DEFINE_CLOSEST_HIT( on, on, off, on, on, off, on, on )
02792 DEFINE_CLOSEST_HIT( on, on, off, on, on, off, on, off )
02793
02794 DEFINE_CLOSEST_HIT( on, on, off, on, on, off, off, on )
02795 DEFINE_CLOSEST_HIT( on, on, off, on, on, off, off, off )
02796
02797 DEFINE_CLOSEST_HIT( on, on, off, on, off, on, on, on )
02798 DEFINE_CLOSEST_HIT( on, on, off, on, off, on, on, off )
02799
02800 DEFINE_CLOSEST_HIT( on, on, off, on, off, on, off, on )
02801 DEFINE_CLOSEST_HIT( on, on, off, on, off, on, off, off )
02802
02803 DEFINE_CLOSEST_HIT( on, on, off, on, off, off, on, on )
02804 DEFINE_CLOSEST_HIT( on, on, off, on, off, off, on, off )
02805
02806 DEFINE_CLOSEST_HIT( on, on, off, on, off, off, off, on )
02807 DEFINE_CLOSEST_HIT( on, on, off, on, off, off, off, off )
02808
02809
02810 DEFINE_CLOSEST_HIT( on, on, off, off, on, on, on, on )
02811 DEFINE_CLOSEST_HIT( on, on, off, off, on, on, on, off )
02812
02813 DEFINE_CLOSEST_HIT( on, on, off, off, on, on, off, on )
02814 DEFINE_CLOSEST_HIT( on, on, off, off, on, on, off, off )
02815
02816 DEFINE_CLOSEST_HIT( on, on, off, off, on, off, on, on )
02817 DEFINE_CLOSEST_HIT( on, on, off, off, on, off, on, off )
02818
02819 DEFINE_CLOSEST_HIT( on, on, off, off, on, off, off, on )
02820 DEFINE_CLOSEST_HIT( on, on, off, off, on, off, off, off )
02821
02822 DEFINE_CLOSEST_HIT( on, on, off, off, off, on, on, on )
02823 DEFINE_CLOSEST_HIT( on, on, off, off, off, on, on, off )
02824
02825 DEFINE_CLOSEST_HIT( on, on, off, off, off, on, off, on )
02826 DEFINE_CLOSEST_HIT( on, on, off, off, off, on, off, off )
02827
02828 DEFINE_CLOSEST_HIT( on, on, off, off, off, off, on, on )
02829 DEFINE_CLOSEST_HIT( on, on, off, off, off, off, on, off )
02830
02831 DEFINE_CLOSEST_HIT( on, on, off, off, off, off, off, on )
02832 DEFINE_CLOSEST_HIT( on, on, off, off, off, off, off, off )
02833
02834
02835
02836
02837
02838 DEFINE_CLOSEST_HIT( on, off, on, on, on, on, on, on )
02839 DEFINE_CLOSEST_HIT( on, off, on, on, on, on, on, off )
02840
02841 DEFINE_CLOSEST_HIT( on, off, on, on, on, on, off, on )
02842 DEFINE_CLOSEST_HIT( on, off, on, on, on, on, off, off )
02843
02844 DEFINE_CLOSEST_HIT( on, off, on, on, on, off, on, on )
02845 DEFINE_CLOSEST_HIT( on, off, on, on, on, off, on, off )
02846
02847 DEFINE_CLOSEST_HIT( on, off, on, on, on, off, off, on )
02848 DEFINE_CLOSEST_HIT( on, off, on, on, on, off, off, off )
02849
02850 DEFINE_CLOSEST_HIT( on, off, on, on, off, on, on, on )
02851 DEFINE_CLOSEST_HIT( on, off, on, on, off, on, on, off )
02852
02853 DEFINE_CLOSEST_HIT( on, off, on, on, off, on, off, on )
02854 DEFINE_CLOSEST_HIT( on, off, on, on, off, on, off, off )
02855
02856 DEFINE_CLOSEST_HIT( on, off, on, on, off, off, on, on )
02857 DEFINE_CLOSEST_HIT( on, off, on, on, off, off, on, off )
02858
02859 DEFINE_CLOSEST_HIT( on, off, on, on, off, off, off, on )
02860 DEFINE_CLOSEST_HIT( on, off, on, on, off, off, off, off )
02861
02862
02863 DEFINE_CLOSEST_HIT( on, off, on, off, on, on, on, on )
02864 DEFINE_CLOSEST_HIT( on, off, on, off, on, on, on, off )
02865
02866 DEFINE_CLOSEST_HIT( on, off, on, off, on, on, off, on )
02867 DEFINE_CLOSEST_HIT( on, off, on, off, on, on, off, off )
02868
02869 DEFINE_CLOSEST_HIT( on, off, on, off, on, off, on, on )
02870 DEFINE_CLOSEST_HIT( on, off, on, off, on, off, on, off )
02871
02872 DEFINE_CLOSEST_HIT( on, off, on, off, on, off, off, on )
02873 DEFINE_CLOSEST_HIT( on, off, on, off, on, off, off, off )
02874
02875 DEFINE_CLOSEST_HIT( on, off, on, off, off, on, on, on )
02876 DEFINE_CLOSEST_HIT( on, off, on, off, off, on, on, off )
02877
02878 DEFINE_CLOSEST_HIT( on, off, on, off, off, on, off, on )
02879 DEFINE_CLOSEST_HIT( on, off, on, off, off, on, off, off )
02880
02881 DEFINE_CLOSEST_HIT( on, off, on, off, off, off, on, on )
02882 DEFINE_CLOSEST_HIT( on, off, on, off, off, off, on, off )
02883
02884 DEFINE_CLOSEST_HIT( on, off, on, off, off, off, off, on )
02885 DEFINE_CLOSEST_HIT( on, off, on, off, off, off, off, off )
02886
02887
02888
02889 DEFINE_CLOSEST_HIT( on, off, off, on, on, on, on, on )
02890 DEFINE_CLOSEST_HIT( on, off, off, on, on, on, on, off )
02891
02892 DEFINE_CLOSEST_HIT( on, off, off, on, on, on, off, on )
02893 DEFINE_CLOSEST_HIT( on, off, off, on, on, on, off, off )
02894
02895 DEFINE_CLOSEST_HIT( on, off, off, on, on, off, on, on )
02896 DEFINE_CLOSEST_HIT( on, off, off, on, on, off, on, off )
02897
02898 DEFINE_CLOSEST_HIT( on, off, off, on, on, off, off, on )
02899 DEFINE_CLOSEST_HIT( on, off, off, on, on, off, off, off )
02900
02901 DEFINE_CLOSEST_HIT( on, off, off, on, off, on, on, on )
02902 DEFINE_CLOSEST_HIT( on, off, off, on, off, on, on, off )
02903
02904 DEFINE_CLOSEST_HIT( on, off, off, on, off, on, off, on )
02905 DEFINE_CLOSEST_HIT( on, off, off, on, off, on, off, off )
02906
02907 DEFINE_CLOSEST_HIT( on, off, off, on, off, off, on, on )
02908 DEFINE_CLOSEST_HIT( on, off, off, on, off, off, on, off )
02909
02910 DEFINE_CLOSEST_HIT( on, off, off, on, off, off, off, on )
02911 DEFINE_CLOSEST_HIT( on, off, off, on, off, off, off, off )
02912
02913
02914 DEFINE_CLOSEST_HIT( on, off, off, off, on, on, on, on )
02915 DEFINE_CLOSEST_HIT( on, off, off, off, on, on, on, off )
02916
02917 DEFINE_CLOSEST_HIT( on, off, off, off, on, on, off, on )
02918 DEFINE_CLOSEST_HIT( on, off, off, off, on, on, off, off )
02919
02920 DEFINE_CLOSEST_HIT( on, off, off, off, on, off, on, on )
02921 DEFINE_CLOSEST_HIT( on, off, off, off, on, off, on, off )
02922
02923 DEFINE_CLOSEST_HIT( on, off, off, off, on, off, off, on )
02924 DEFINE_CLOSEST_HIT( on, off, off, off, on, off, off, off )
02925
02926 DEFINE_CLOSEST_HIT( on, off, off, off, off, on, on, on )
02927 DEFINE_CLOSEST_HIT( on, off, off, off, off, on, on, off )
02928
02929 DEFINE_CLOSEST_HIT( on, off, off, off, off, on, off, on )
02930 DEFINE_CLOSEST_HIT( on, off, off, off, off, on, off, off )
02931
02932 DEFINE_CLOSEST_HIT( on, off, off, off, off, off, on, on )
02933 DEFINE_CLOSEST_HIT( on, off, off, off, off, off, on, off )
02934
02935 DEFINE_CLOSEST_HIT( on, off, off, off, off, off, off, on )
02936 DEFINE_CLOSEST_HIT( on, off, off, off, off, off, off, off )
02937
02941
02942 DEFINE_CLOSEST_HIT( off, on, on, on, on, on, on, on )
02943 DEFINE_CLOSEST_HIT( off, on, on, on, on, on, on, off )
02944
02945 DEFINE_CLOSEST_HIT( off, on, on, on, on, on, off, on )
02946 DEFINE_CLOSEST_HIT( off, on, on, on, on, on, off, off )
02947
02948 DEFINE_CLOSEST_HIT( off, on, on, on, on, off, on, on )
02949 DEFINE_CLOSEST_HIT( off, on, on, on, on, off, on, off )
02950
02951 DEFINE_CLOSEST_HIT( off, on, on, on, on, off, off, on )
02952 DEFINE_CLOSEST_HIT( off, on, on, on, on, off, off, off )
02953
02954 DEFINE_CLOSEST_HIT( off, on, on, on, off, on, on, on )
02955 DEFINE_CLOSEST_HIT( off, on, on, on, off, on, on, off )
02956
02957 DEFINE_CLOSEST_HIT( off, on, on, on, off, on, off, on )
02958 DEFINE_CLOSEST_HIT( off, on, on, on, off, on, off, off )
02959
02960 DEFINE_CLOSEST_HIT( off, on, on, on, off, off, on, on )
02961 DEFINE_CLOSEST_HIT( off, on, on, on, off, off, on, off )
02962
02963 DEFINE_CLOSEST_HIT( off, on, on, on, off, off, off, on )
02964 DEFINE_CLOSEST_HIT( off, on, on, on, off, off, off, off )
02965
02966
02967 DEFINE_CLOSEST_HIT( off, on, on, off, on, on, on, on )
02968 DEFINE_CLOSEST_HIT( off, on, on, off, on, on, on, off )
02969
02970 DEFINE_CLOSEST_HIT( off, on, on, off, on, on, off, on )
02971 DEFINE_CLOSEST_HIT( off, on, on, off, on, on, off, off )
02972
02973 DEFINE_CLOSEST_HIT( off, on, on, off, on, off, on, on )
02974 DEFINE_CLOSEST_HIT( off, on, on, off, on, off, on, off )
02975
02976 DEFINE_CLOSEST_HIT( off, on, on, off, on, off, off, on )
02977 DEFINE_CLOSEST_HIT( off, on, on, off, on, off, off, off )
02978
02979 DEFINE_CLOSEST_HIT( off, on, on, off, off, on, on, on )
02980 DEFINE_CLOSEST_HIT( off, on, on, off, off, on, on, off )
02981
02982 DEFINE_CLOSEST_HIT( off, on, on, off, off, on, off, on )
02983 DEFINE_CLOSEST_HIT( off, on, on, off, off, on, off, off )
02984
02985 DEFINE_CLOSEST_HIT( off, on, on, off, off, off, on, on )
02986 DEFINE_CLOSEST_HIT( off, on, on, off, off, off, on, off )
02987
02988 DEFINE_CLOSEST_HIT( off, on, on, off, off, off, off, on )
02989 DEFINE_CLOSEST_HIT( off, on, on, off, off, off, off, off )
02990
02991
02992
02993 DEFINE_CLOSEST_HIT( off, on, off, on, on, on, on, on )
02994 DEFINE_CLOSEST_HIT( off, on, off, on, on, on, on, off )
02995
02996 DEFINE_CLOSEST_HIT( off, on, off, on, on, on, off, on )
02997 DEFINE_CLOSEST_HIT( off, on, off, on, on, on, off, off )
02998
02999 DEFINE_CLOSEST_HIT( off, on, off, on, on, off, on, on )
03000 DEFINE_CLOSEST_HIT( off, on, off, on, on, off, on, off )
03001
03002 DEFINE_CLOSEST_HIT( off, on, off, on, on, off, off, on )
03003 DEFINE_CLOSEST_HIT( off, on, off, on, on, off, off, off )
03004
03005 DEFINE_CLOSEST_HIT( off, on, off, on, off, on, on, on )
03006 DEFINE_CLOSEST_HIT( off, on, off, on, off, on, on, off )
03007
03008 DEFINE_CLOSEST_HIT( off, on, off, on, off, on, off, on )
03009 DEFINE_CLOSEST_HIT( off, on, off, on, off, on, off, off )
03010
03011 DEFINE_CLOSEST_HIT( off, on, off, on, off, off, on, on )
03012 DEFINE_CLOSEST_HIT( off, on, off, on, off, off, on, off )
03013
03014 DEFINE_CLOSEST_HIT( off, on, off, on, off, off, off, on )
03015 DEFINE_CLOSEST_HIT( off, on, off, on, off, off, off, off )
03016
03017
03018 DEFINE_CLOSEST_HIT( off, on, off, off, on, on, on, on )
03019 DEFINE_CLOSEST_HIT( off, on, off, off, on, on, on, off )
03020
03021 DEFINE_CLOSEST_HIT( off, on, off, off, on, on, off, on )
03022 DEFINE_CLOSEST_HIT( off, on, off, off, on, on, off, off )
03023
03024 DEFINE_CLOSEST_HIT( off, on, off, off, on, off, on, on )
03025 DEFINE_CLOSEST_HIT( off, on, off, off, on, off, on, off )
03026
03027 DEFINE_CLOSEST_HIT( off, on, off, off, on, off, off, on )
03028 DEFINE_CLOSEST_HIT( off, on, off, off, on, off, off, off )
03029
03030 DEFINE_CLOSEST_HIT( off, on, off, off, off, on, on, on )
03031 DEFINE_CLOSEST_HIT( off, on, off, off, off, on, on, off )
03032
03033 DEFINE_CLOSEST_HIT( off, on, off, off, off, on, off, on )
03034 DEFINE_CLOSEST_HIT( off, on, off, off, off, on, off, off )
03035
03036 DEFINE_CLOSEST_HIT( off, on, off, off, off, off, on, on )
03037 DEFINE_CLOSEST_HIT( off, on, off, off, off, off, on, off )
03038
03039 DEFINE_CLOSEST_HIT( off, on, off, off, off, off, off, on )
03040 DEFINE_CLOSEST_HIT( off, on, off, off, off, off, off, off )
03041
03042
03043
03044
03045
03046 DEFINE_CLOSEST_HIT( off, off, on, on, on, on, on, on )
03047 DEFINE_CLOSEST_HIT( off, off, on, on, on, on, on, off )
03048
03049 DEFINE_CLOSEST_HIT( off, off, on, on, on, on, off, on )
03050 DEFINE_CLOSEST_HIT( off, off, on, on, on, on, off, off )
03051
03052 DEFINE_CLOSEST_HIT( off, off, on, on, on, off, on, on )
03053 DEFINE_CLOSEST_HIT( off, off, on, on, on, off, on, off )
03054
03055 DEFINE_CLOSEST_HIT( off, off, on, on, on, off, off, on )
03056 DEFINE_CLOSEST_HIT( off, off, on, on, on, off, off, off )
03057
03058 DEFINE_CLOSEST_HIT( off, off, on, on, off, on, on, on )
03059 DEFINE_CLOSEST_HIT( off, off, on, on, off, on, on, off )
03060
03061 DEFINE_CLOSEST_HIT( off, off, on, on, off, on, off, on )
03062 DEFINE_CLOSEST_HIT( off, off, on, on, off, on, off, off )
03063
03064 DEFINE_CLOSEST_HIT( off, off, on, on, off, off, on, on )
03065 DEFINE_CLOSEST_HIT( off, off, on, on, off, off, on, off )
03066
03067 DEFINE_CLOSEST_HIT( off, off, on, on, off, off, off, on )
03068 DEFINE_CLOSEST_HIT( off, off, on, on, off, off, off, off )
03069
03070
03071 DEFINE_CLOSEST_HIT( off, off, on, off, on, on, on, on )
03072 DEFINE_CLOSEST_HIT( off, off, on, off, on, on, on, off )
03073
03074 DEFINE_CLOSEST_HIT( off, off, on, off, on, on, off, on )
03075 DEFINE_CLOSEST_HIT( off, off, on, off, on, on, off, off )
03076
03077 DEFINE_CLOSEST_HIT( off, off, on, off, on, off, on, on )
03078 DEFINE_CLOSEST_HIT( off, off, on, off, on, off, on, off )
03079
03080 DEFINE_CLOSEST_HIT( off, off, on, off, on, off, off, on )
03081 DEFINE_CLOSEST_HIT( off, off, on, off, on, off, off, off )
03082
03083 DEFINE_CLOSEST_HIT( off, off, on, off, off, on, on, on )
03084 DEFINE_CLOSEST_HIT( off, off, on, off, off, on, on, off )
03085
03086 DEFINE_CLOSEST_HIT( off, off, on, off, off, on, off, on )
03087 DEFINE_CLOSEST_HIT( off, off, on, off, off, on, off, off )
03088
03089 DEFINE_CLOSEST_HIT( off, off, on, off, off, off, on, on )
03090 DEFINE_CLOSEST_HIT( off, off, on, off, off, off, on, off )
03091
03092 DEFINE_CLOSEST_HIT( off, off, on, off, off, off, off, on )
03093 DEFINE_CLOSEST_HIT( off, off, on, off, off, off, off, off )
03094
03095
03096
03097 DEFINE_CLOSEST_HIT( off, off, off, on, on, on, on, on )
03098 DEFINE_CLOSEST_HIT( off, off, off, on, on, on, on, off )
03099
03100 DEFINE_CLOSEST_HIT( off, off, off, on, on, on, off, on )
03101 DEFINE_CLOSEST_HIT( off, off, off, on, on, on, off, off )
03102
03103 DEFINE_CLOSEST_HIT( off, off, off, on, on, off, on, on )
03104 DEFINE_CLOSEST_HIT( off, off, off, on, on, off, on, off )
03105
03106 DEFINE_CLOSEST_HIT( off, off, off, on, on, off, off, on )
03107 DEFINE_CLOSEST_HIT( off, off, off, on, on, off, off, off )
03108
03109 DEFINE_CLOSEST_HIT( off, off, off, on, off, on, on, on )
03110 DEFINE_CLOSEST_HIT( off, off, off, on, off, on, on, off )
03111
03112 DEFINE_CLOSEST_HIT( off, off, off, on, off, on, off, on )
03113 DEFINE_CLOSEST_HIT( off, off, off, on, off, on, off, off )
03114
03115 DEFINE_CLOSEST_HIT( off, off, off, on, off, off, on, on )
03116 DEFINE_CLOSEST_HIT( off, off, off, on, off, off, on, off )
03117
03118 DEFINE_CLOSEST_HIT( off, off, off, on, off, off, off, on )
03119 DEFINE_CLOSEST_HIT( off, off, off, on, off, off, off, off )
03120
03121
03122 DEFINE_CLOSEST_HIT( off, off, off, off, on, on, on, on )
03123 DEFINE_CLOSEST_HIT( off, off, off, off, on, on, on, off )
03124
03125 DEFINE_CLOSEST_HIT( off, off, off, off, on, on, off, on )
03126 DEFINE_CLOSEST_HIT( off, off, off, off, on, on, off, off )
03127
03128 DEFINE_CLOSEST_HIT( off, off, off, off, on, off, on, on )
03129 DEFINE_CLOSEST_HIT( off, off, off, off, on, off, on, off )
03130
03131 DEFINE_CLOSEST_HIT( off, off, off, off, on, off, off, on )
03132 DEFINE_CLOSEST_HIT( off, off, off, off, on, off, off, off )
03133
03134 DEFINE_CLOSEST_HIT( off, off, off, off, off, on, on, on )
03135 DEFINE_CLOSEST_HIT( off, off, off, off, off, on, on, off )
03136
03137 DEFINE_CLOSEST_HIT( off, off, off, off, off, on, off, on )
03138 DEFINE_CLOSEST_HIT( off, off, off, off, off, on, off, off )
03139
03140 DEFINE_CLOSEST_HIT( off, off, off, off, off, off, on, on )
03141 DEFINE_CLOSEST_HIT( off, off, off, off, off, off, on, off )
03142
03143 DEFINE_CLOSEST_HIT( off, off, off, off, off, off, off, on )
03144 DEFINE_CLOSEST_HIT( off, off, off, off, off, off, off, off )
03145
03146
03147 #undef CLIP_VIEW_on
03148 #undef CLIP_VIEW_off
03149 #undef HEADLIGHT_on
03150 #undef HEADLIGHT_off
03151 #undef FOG_on
03152 #undef FOG_off
03153 #undef SHADOWS_on
03154 #undef SHADOWS_off
03155 #undef AO_on
03156 #undef AO_off
03157 #undef OUTLINE_on
03158 #undef OUTLINE_off
03159 #undef REFL_on
03160 #undef REFL_off
03161 #undef TRANS_on
03162 #undef TRANS_off
03163 #undef DEFINE_CLOSEST_HIT
03164
03165 #endif // ORT_USE_TEMPLATE_SHADERS
03166
03167