Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TCheckerboardTexture.ipp
Go to the documentation of this file.
4
5#include <Common/assertion.h>
6#include <Common/logging.h>
7
8#include <memory>
9
10namespace ph
11{
12
13template<typename OutputType>
15 const real numUtiles,
16 const real numVtiles,
17 const OutputType& oddValue, const OutputType& evenValue) :
18
20 numUtiles, numVtiles,
21 std::make_shared<TConstantTexture<OutputType>>(oddValue),
22 std::make_shared<TConstantTexture<OutputType>>(evenValue))
23{}
24
25template<typename OutputType>
27 const real numUtiles,
28 const real numVtiles,
29 const std::shared_ptr<TTexture<OutputType>>& oddTexture,
30 const std::shared_ptr<TTexture<OutputType>>& evenTexture)
31{
32 if(numUtiles <= 0.0f || numVtiles <= 0.0f)
33 {
34 PH_DEFAULT_LOG(Warning,
35 "at TCheckerboardTexture's ctor, number of tiles <= 0 (numUtiles = {}, numVtiles = {})",
36 numUtiles, numVtiles);
37 }
38
39 setOddTexture(oddTexture);
40 setEvenTexture(evenTexture);
41
42 setOddTextureScale(math::Vector3R(1.0_r / numUtiles));
43 setEvenTextureScale(math::Vector3R(1.0_r / numVtiles));
44
45 m_uTileSize = 1.0f / numUtiles;
46 m_vTileSize = 1.0f / numVtiles;
47}
48
49template<typename OutputType>
51 const SampleLocation& sampleLocation, OutputType* const out_value) const
52{
53 PH_ASSERT(m_oddTexture && m_oddTexture.get() != this);
54 PH_ASSERT(m_evenTexture && m_evenTexture.get() != this);
55
56 const math::Vector3R uvw = sampleLocation.uvw();
57 const int32 uNumber = static_cast<int32>(std::floor(uvw.x() / m_uTileSize));
58 const int32 vNumber = static_cast<int32>(std::floor(uvw.y() / m_vTileSize));
59
60 if(std::abs(uNumber % 2) != std::abs(vNumber % 2))
61 {
62 m_oddTexture->sample(sampleLocation.getUvwScaled(m_oddUvwScale),
63 out_value);
64 }
65 else
66 {
67 m_evenTexture->sample(sampleLocation.getUvwScaled(m_evenUvwScale),
68 out_value);
69 }
70}
71
72template<typename OutputType>
74 const std::shared_ptr<TTexture<OutputType>>& oddTexture)
75{
76 if(!oddTexture || oddTexture.get() == this)
77 {
78 PH_DEFAULT_LOG(Warning,
79 "at TCheckerboardTexture::setOddTexture(), does not allow empty or self-referencing tile");
80 return;
81 }
82
83 m_oddTexture = oddTexture;
84}
85
86template<typename OutputType>
88 const std::shared_ptr<TTexture<OutputType>>& evenTexture)
89{
90 if(!evenTexture || evenTexture.get() == this)
91 {
92 PH_DEFAULT_LOG(Warning,
93 "at TCheckerboardTexture::setEvenTexture(), does not allow empty or self-referencing tile");
94 return;
95 }
96
97 m_evenTexture = evenTexture;
98}
99
100/*
101 Note that in order to scale a texture, we need to multiply texture
102 coordinates by a reciprocal factor.
103*/
104
105template<typename OutputType>
107{
108 m_oddUvwScale = scale.rcp();
109}
110
111template<typename OutputType>
113{
114 m_evenUvwScale = scale.rcp();
115}
116
117}// end namespace ph
Definition SampleLocation.h:22
math::Vector3R uvw() const
Gets and sets the uvw coordinates of this sample location.
Definition SampleLocation.h:90
SampleLocation getUvwScaled(const math::Vector3R &scale) const
Definition SampleLocation.h:116
Texture representing checker patterns.
Definition TCheckerboardTexture.h:28
void sample(const SampleLocation &sampleLocation, OutputType *out_value) const override
Definition TCheckerboardTexture.ipp:50
TCheckerboardTexture(real numUtiles, real numVtiles, const OutputType &oddValue, const OutputType &evenValue)
Definition TCheckerboardTexture.ipp:14
void setEvenTextureScale(const math::Vector3R &scale)
Definition TCheckerboardTexture.ipp:112
void setOddTexture(const std::shared_ptr< TTexture< OutputType > > &oddTexture)
Sets the texture that is going to be used in odd cells.
Definition TCheckerboardTexture.ipp:73
void setOddTextureScale(const math::Vector3R &sale)
Sets the scale factors of cell texture. Larger u-, v- and w-scale makes texture appears to be larger ...
Definition TCheckerboardTexture.ipp:106
void setEvenTexture(const std::shared_ptr< TTexture< OutputType > > &evenTexture)
Sets the texture that is going to be used in even cells.
Definition TCheckerboardTexture.ipp:87
Texture storing one single constant of arbitrary type. This texture provides only a constant value....
Definition constant_textures.h:24
Definition TTexture.h:12
T & y()
Definition TVector3.ipp:189
T & x()
Definition TVector3.ipp:183
Derived rcp() const
Definition TArithmeticArrayBase.ipp:484
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition TAABB2D.h:96