File: PanoramicCamera.ispc

package info (click to toggle)
ospray 3.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,048 kB
  • sloc: cpp: 80,569; ansic: 951; sh: 805; makefile: 170; python: 69
file content (103 lines) | stat: -rw-r--r-- 3,160 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "Camera.ih"
#include "common/Embree.h"
#include "common/FeatureFlags.ih"
#include "math/sampling.ih"
#include "ospray/OSPEnums.h"
// c++ shared
#include "PanoramicCameraShared.h"

#include "rkcommon/math/AffineSpace.ih"

OSPRAY_BEGIN_ISPC_NAMESPACE

SYCL_EXTERNAL void PanoramicCamera_initRay(const Camera *uniform _self,
    varying Ray &ray,
    varying RayCone &rayCone,
    const varying CameraSample &sample,
    const uniform FeatureFlagsHandler &ffh)
{
  const PanoramicCamera *uniform self = (const PanoramicCamera *uniform)_self;

  vec2f screen = sample.screen;
  float pixel_center = self->stereoMode == OSP_STEREO_SIDE_BY_SIDE
      ? sample.pixel_center.x
      : sample.pixel_center.y;

  varying float *uniform split =
      self->stereoMode == OSP_STEREO_SIDE_BY_SIDE ? &screen.x : &screen.y;
  float offset = 0.f;
  switch (self->stereoMode) {
  case OSP_STEREO_LEFT:
    offset = -self->ipd_offset;
    break;
  case OSP_STEREO_RIGHT:
    offset = self->ipd_offset;
    break;
  case OSP_STEREO_SIDE_BY_SIDE:
  case OSP_STEREO_TOP_BOTTOM:
    *split *= 2.f;
    if (pixel_center < 0.5f) {
      offset = -self->ipd_offset;
    } else {
      offset = self->ipd_offset;
      *split -= 1.f;
    }
    break;
  }

  screen = Camera_subRegion(_self, screen);

  const float phi = (float)two_pi * screen.x;
  const float theta = (float)pi * screen.y;

  float sinTheta, cosTheta;
  sincos(theta, &sinTheta, &cosTheta);
  const vec3f localDir = cartesian(phi, sinTheta, cosTheta);

  const float time = Camera_shutterTime(_self, screen, sample.time);

  // transform to camera- and then to world-space
  vec3f dir;
  vec3f org;
  const uniform FeatureFlagsOther ffo = getFeatureFlagsOther(ffh);
  if (self->super.motionBlur && (ffo & FFO_CAMERA_MOTION_BLUR)) {
    AffineSpace3f xfm;
    rtcGetGeometryTransformFromScene(
        self->super.scene, 0, time, RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR, &xfm);

    // we cannot just transform the final org & dir, because interpolated
    // transforms can scale (even if original transforms are without scale)
    linear3f frameMB;
    frameMB.vz = normalize(xfmVector(xfm, self->frame.vz));
    frameMB.vx = normalize(cross(xfmVector(xfm, self->frame.vy), frameMB.vz));
    frameMB.vy = cross(frameMB.vz, frameMB.vx);

    dir = frameMB * make_vec3f(-localDir.y, -localDir.z, localDir.x);
    org = xfmPoint(xfm, self->org) + offset * cross(dir, frameMB.vy);
  } else {
    dir = self->frame * make_vec3f(-localDir.y, -localDir.z, localDir.x);
    org = self->org + offset * cross(dir, self->frame.vy);
  }

  setRay(ray, org, dir, self->super.nearClip, inf, time);
  rayCone.width = 0.f;
  rayCone.dwdt = pi * sinTheta;

  const uniform vec2f subImageSize = box_size(self->super.subImage);
  rayCone.dwdt *= abs(subImageSize.y);

  if (self->stereoMode == OSP_STEREO_TOP_BOTTOM)
    rayCone.dwdt *= 2.f;
}

// Exports (called from C++) //////////////////////////////////////////////////

export void *uniform PanoramicCamera_initRay_addr()
{
  return (void *uniform)PanoramicCamera_initRay;
}

OSPRAY_END_ISPC_NAMESPACE