Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TSampler.h
Go to the documentation of this file.
1#pragma once
2
4#include "Core/SurfaceHit.h"
6#include "Math/math_fwd.h"
8
9#include <Common/primitive_type.h>
10
11namespace ph
12{
13
16template<typename OutputType>
17class TSampler final
18{
19public:
22 {}
23
24 TSampler(const math::EColorUsage sampleUsage) :
25 TSampler(sampleUsage, 0)
26 {}
27
28 TSampler(const math::EColorUsage sampleUsage, const uint32 sampledChannel) :
29 m_sampleUsage(sampleUsage), m_sampledChannel(sampledChannel)
30 {}
31
32 OutputType sample(const TTexture<OutputType>& texture, const SurfaceHit& X) const
33 {
34 HitDetail channeledDetail = X.getDetail();
35 if(m_sampledChannel != 0)
36 {
37 channeledDetail = X.switchChannel(m_sampledChannel).getDetail();
38 }
39
40 OutputType value;
41 texture.sample(SampleLocation(channeledDetail, m_sampleUsage), &value);
42 return value;
43 }
44
45 OutputType sample(const TTexture<OutputType>& texture, const math::Vector3R& uvw) const
46 {
47 OutputType value;
48 texture.sample(SampleLocation(uvw, m_sampleUsage), &value);
49 return value;
50 }
51
52 OutputType sample(const TTexture<OutputType>& texture, const math::Vector2R& uv) const
53 {
54 OutputType value;
55 texture.sample(SampleLocation(uv, m_sampleUsage), &value);
56 return value;
57 }
58
59 OutputType sampleOrDefault(
60 const TTexture<OutputType>* texture,
61 const SurfaceHit& X,
62 const OutputType& defaultValue) const
63 {
64 if(texture)
65 {
66 return sample(*texture, X);
67 }
68 else
69 {
70 return defaultValue;
71 }
72 }
73
74private:
75 math::EColorUsage m_sampleUsage;
76 uint32 m_sampledChannel;
77};
78
79}// end namespace ph
Detailed information regarding a ray-primitive intersection.
Definition HitDetail.h:26
Definition SampleLocation.h:22
General information about a ray-surface intersection event.
Definition SurfaceHit.h:59
const HitDetail & getDetail() const
Definition SurfaceHit.h:159
SurfaceHit switchChannel(uint32 newChannel) const
Definition SurfaceHit.cpp:28
Common settings and operations for sampling a texture.
Definition TSampler.h:18
OutputType sample(const TTexture< OutputType > &texture, const SurfaceHit &X) const
Definition TSampler.h:32
TSampler(const math::EColorUsage sampleUsage, const uint32 sampledChannel)
Definition TSampler.h:28
OutputType sample(const TTexture< OutputType > &texture, const math::Vector2R &uv) const
Definition TSampler.h:52
OutputType sample(const TTexture< OutputType > &texture, const math::Vector3R &uvw) const
Definition TSampler.h:45
TSampler()
Definition TSampler.h:20
OutputType sampleOrDefault(const TTexture< OutputType > *texture, const SurfaceHit &X, const OutputType &defaultValue) const
Definition TSampler.h:59
TSampler(const math::EColorUsage sampleUsage)
Definition TSampler.h:24
Definition TTexture.h:12
virtual void sample(const SampleLocation &sampleLocation, Output *out_value) const =0
EColorUsage
Definition color_enums.h:140
The root for all renderer implementations.
Definition EEngineProject.h:6