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
|
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "../common/DifferentialGeometry.ih"
#include "rkcommon/math/vec.ih"
#include "texture/TextureDispatch.ih"
// c++ shared
#include "TextureShared.h"
OSPRAY_BEGIN_ISPC_NAMESPACE
inline uniform bool hasAlpha(const uniform Texture *uniform self)
{
return (self == NULL) ? false : self->hasAlpha;
}
/*! helper function that returns the sampled value for the first
channel of the given texture
Right now, this function always asks the texture for all four
channels, and then discards all but one; later implementations may
have specialized 'get1f' methods with the texture
\note self may NOT be NULL!
*/
inline float get1f(
const uniform Texture *uniform self, const varying DifferentialGeometry &dg)
{
vec4f ret = Texture_dispatch_get(self, dg);
return ret.x;
}
/*! helper function that returns the sampled value for the first three
channels of the given texture
Right now, this function always asks the texture for all four
channels, and then discards all but one; later implementations may
have specialized 'get3f' methods with the texture
\note self may NOT be NULL!
*/
inline vec3f get3f(
const uniform Texture *uniform self, const varying DifferentialGeometry &dg)
{
vec4f ret = Texture_dispatch_get(self, dg);
return make_vec3f(ret);
}
/*! helper function that returns the sampled value of the four
channels of the given texture.
Note that it's up to the texture to define clearly what happens if
we ask for four channels even if the texture has less physical
channels.
\note self may NOT be NULL!
*/
inline vec4f get4f(
const uniform Texture *uniform self, const varying DifferentialGeometry &dg)
{
return Texture_dispatch_get(self, dg);
}
/*! helper function that returns the sampled values interpreted as a normal */
inline vec3f getNormal(
const uniform Texture *uniform self, const varying DifferentialGeometry &dg)
{
if (self == NULL)
return make_vec3f(0.f, 0.f, 1.f);
else
return Texture_dispatch_getNormal(self, dg);
}
/*! helper function: get1f() with a default value if the texture is NULL */
inline float get1f(const uniform Texture *uniform self,
const varying DifferentialGeometry &dg,
const varying float defaultValue)
{
if (self == NULL)
return defaultValue;
else
return get1f(self, dg);
}
/*! helper function: get3f() with a default value if the texture is NULL */
inline vec3f get3f(const uniform Texture *uniform self,
const varying DifferentialGeometry &dg,
const varying vec3f defaultValue)
{
if (self == NULL)
return defaultValue;
else
return get3f(self, dg);
}
/*! helper function: get4f() with a default value if the texture is NULL */
inline vec4f get4f(const uniform Texture *uniform self,
const varying DifferentialGeometry &dg,
const varying vec4f defaultValue)
{
if (self == NULL)
return defaultValue;
else
return get4f(self, dg);
}
OSPRAY_END_ISPC_NAMESPACE
|