File: LightDispatch.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 (142 lines) | stat: -rw-r--r-- 5,723 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright 2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "common/DifferentialGeometry.ih"
#include "common/FeatureFlagsEnum.h"
#include "common/Instance.ih"
#include "lights/LightDispatch.ih"
#include "lights/LightShared.h"

#include "lights/AmbientLight.ih"
#include "lights/CylinderLight.ih"
#include "lights/DirectionalLight.ih"
#include "lights/HDRILight.ih"
#include "lights/PointLight.ih"
#include "lights/QuadLight.ih"
#include "lights/SpotLight.ih"
#include "render/pathtracer/GeometryLight.ih"

OSPRAY_BEGIN_ISPC_NAMESPACE

SYCL_EXTERNAL __noinline Light_SampleRes Light_dispatch_sample(
    const Light *uniform self,
    const DifferentialGeometry &dg,
    const vec2f &s,
    const float time,
    const uniform FeatureFlagsHandler &ffh)
{
  const uniform FeatureFlagsGeometry ffg = getFeatureFlagsGeometry(ffh);
  const uniform FeatureFlagsOther ffo = getFeatureFlagsOther(ffh);

#ifndef OSPRAY_TARGET_SYCL
  return self->sample(self, dg, s, time, ffh);
#else
  if ((self->type == LIGHT_TYPE_AMBIENT) && (ffo & FFO_LIGHT_AMBIENT)) {
    return AmbientLight_sample(self, dg, s, time, ffh);
  } else if ((self->type == LIGHT_TYPE_DIRECTIONAL)
      && (ffo & FFO_LIGHT_DIRECTIONAL)) {
    if (self->instance->motionBlur && (ffg & FFG_MOTION_BLUR))
      return DirectionalLight_sample_instanced(self, dg, s, time, ffh);
    else
      return DirectionalLight_sample(self, dg, s, time, ffh);
  } else if ((self->type == LIGHT_TYPE_POINT) && (ffo & FFO_LIGHT_POINT)) {
    if (self->instance->motionBlur && (ffg & FFG_MOTION_BLUR))
      return PointLight_sample_instanced(self, dg, s, time, ffh);
    else
      return PointLight_sample(self, dg, s, time, ffh);
  } else if ((self->type == LIGHT_TYPE_SPOT) && (ffo & FFO_LIGHT_SPOT)) {
    if (self->instance->motionBlur && (ffg & FFG_MOTION_BLUR))
      return SpotLight_sample_instanced(self, dg, s, time, ffh);
    else
      return SpotLight_sample(self, dg, s, time, ffh);
  } else if ((self->type == LIGHT_TYPE_HDRI) && (ffo & FFO_LIGHT_HDRI)) {
    if (self->instance->motionBlur && (ffg & FFG_MOTION_BLUR))
      return HDRILight_sample_instanced(self, dg, s, time, ffh);
    else
      return HDRILight_sample(self, dg, s, time, ffh);
  } else if ((self->type == LIGHT_TYPE_QUAD) && (ffo & FFO_LIGHT_QUAD)) {
    if (self->instance->motionBlur && (ffg & FFG_MOTION_BLUR))
      return QuadLight_sample_instanced(self, dg, s, time, ffh);
    else
      return QuadLight_sample(self, dg, s, time, ffh);
  } else if ((self->type == LIGHT_TYPE_CYLINDER)
      && (ffo & FFO_LIGHT_CYLINDER)) {
    if (self->instance->motionBlur && (ffg & FFG_MOTION_BLUR))
      return CylinderLight_sample_instanced(self, dg, s, time, ffh);
    else
      return CylinderLight_sample(self, dg, s, time, ffh);
  } else if ((self->type == LIGHT_TYPE_GEOMETRY)
      && (ffo & FFO_LIGHT_GEOMETRY)) {
    return GeometryLight_sample(self, dg, s, time, ffh);
  } else {
    Light_SampleRes res;
    res.weight = make_vec3f(0.f);
    res.dir = make_vec3f(0.f);
    res.dist = inf;
    res.pdf = 0.f;
    return res;
  }
#endif
}

SYCL_EXTERNAL __noinline Light_EvalRes Light_dispatch_eval(
    const Light *uniform self,
    const DifferentialGeometry &dg,
    const vec3f &dir,
    const float minDist,
    const float maxDist,
    const float time,
    const uniform FeatureFlagsHandler &ffh)
{
  const uniform FeatureFlagsGeometry ffg = getFeatureFlagsGeometry(ffh);
  const uniform FeatureFlagsOther ffo = getFeatureFlagsOther(ffh);

#ifndef OSPRAY_TARGET_SYCL
  return self->eval(self, dg, dir, minDist, maxDist, time);
#else
  if ((self->type == LIGHT_TYPE_AMBIENT) && (ffo & FFO_LIGHT_AMBIENT)) {
    return AmbientLight_eval(self, dg, dir, minDist, maxDist, time);
  } else if ((self->type == LIGHT_TYPE_DIRECTIONAL)
      && (ffo & FFO_LIGHT_DIRECTIONAL)) {
    if (self->instance->motionBlur && (ffg & FFG_MOTION_BLUR))
      return DirectionalLight_eval_instanced(
          self, dg, dir, minDist, maxDist, time);
    else
      return DirectionalLight_eval(self, dg, dir, minDist, maxDist, time);
  } else if ((self->type == LIGHT_TYPE_POINT) && (ffo & FFO_LIGHT_POINT)) {
    if (self->instance->motionBlur && (ffg & FFG_MOTION_BLUR))
      return PointLight_eval_instanced(self, dg, dir, minDist, maxDist, time);
    else
      return PointLight_eval(self, dg, dir, minDist, maxDist, time);
  } else if ((self->type == LIGHT_TYPE_SPOT) && (ffo & FFO_LIGHT_SPOT)) {
    if (self->instance->motionBlur && (ffg & FFG_MOTION_BLUR))
      return SpotLight_eval_instanced(self, dg, dir, minDist, maxDist, time);
    else
      return SpotLight_eval(self, dg, dir, minDist, maxDist, time);
  } else if ((self->type == LIGHT_TYPE_HDRI) && (ffo & FFO_LIGHT_HDRI)) {
    if (self->instance->motionBlur && (ffg & FFG_MOTION_BLUR))
      return HDRILight_eval_instanced(self, dg, dir, minDist, maxDist, time);
    else
      return HDRILight_eval(self, dg, dir, minDist, maxDist, time);
  } else if ((self->type == LIGHT_TYPE_QUAD) && (ffo & FFO_LIGHT_QUAD)) {
    if (self->instance->motionBlur && (ffg & FFG_MOTION_BLUR))
      return QuadLight_eval_instanced(self, dg, dir, minDist, maxDist, time);
    else
      return QuadLight_eval(self, dg, dir, minDist, maxDist, time);
  } else if ((self->type == LIGHT_TYPE_CYLINDER)
      && (ffo & FFO_LIGHT_CYLINDER)) {
    if (self->instance->motionBlur && (ffg & FFG_MOTION_BLUR))
      return CylinderLight_eval_instanced(
          self, dg, dir, minDist, maxDist, time);
    else
      return CylinderLight_eval(self, dg, dir, minDist, maxDist, time);
  } else {
    Light_EvalRes res;
    res.radiance = make_vec3f(0.f);
    res.pdf = 0.f;
    return res;
  }
#endif
}

OSPRAY_END_ISPC_NAMESPACE