Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TLinearGradientTexture.ipp
Go to the documentation of this file.
1#pragma once
2
5
6#include <Common/assertion.h>
7
8namespace ph
9{
10
11template<typename OutputType>
13 const real beginU,
14 const std::shared_ptr<TTexture<OutputType>>& beginTexture,
15 const real endU,
16 const std::shared_ptr<TTexture<OutputType>>& endTexture) :
17
19 {beginU, 0, 0},
20 beginTexture,
21 {endU, 0, 0},
22 endTexture)
23{}
24
25template<typename OutputType>
27 const math::Vector2R& beginUV,
28 const std::shared_ptr<TTexture<OutputType>>& beginTexture,
29 const math::Vector2R& endUV,
30 const std::shared_ptr<TTexture<OutputType>>& endTexture) :
31
33 {beginUV.x, beginUV.y, 0},
34 beginTexture,
35 {endUV.x, endUV.y, 0},
36 endTexture)
37{}
38
39template<typename OutputType>
41 const math::Vector3R& beginUVW,
42 const std::shared_ptr<TTexture<OutputType>>& beginTexture,
43 const math::Vector3R& endUVW,
44 const std::shared_ptr<TTexture<OutputType>>& endTexture) :
45
46 TTexture<OutputType>(),
47
48 m_beginUVW (beginUVW),
49 m_beginTexture(beginTexture),
50 m_endUVW (endUVW),
51 m_endTexture (endTexture)
52{
53 PH_ASSERT(!beginUVW.isEqual(endUVW));
54 PH_ASSERT(beginTexture);
55 PH_ASSERT(endTexture);
56}
57
58template<typename OutputType>
59inline void TLinearGradientTexture<OutputType>::sample(const SampleLocation& sampleLocation, OutputType* const out_value) const
60{
61 PH_ASSERT(out_value);
62 PH_ASSERT(m_beginTexture);
63 PH_ASSERT(m_beginTexture.get() != this);
64 PH_ASSERT(m_endTexture);
65 PH_ASSERT(m_endTexture.get() != this);
66
67 const auto baseVec = m_endUVW - m_beginUVW;
68 const real baseLength = baseVec.length();
69 const real rcpBaseLength = 1.0_r / baseLength;
70 const auto baseAxis = baseVec * rcpBaseLength;
71 const auto sampleVec = sampleLocation.uvw() - m_beginUVW;
72 const real sampleLength = sampleVec.dot(baseAxis);
73
74 // Lerp between endpoints
75
76 const real beginRatio = (baseLength - sampleLength) * rcpBaseLength;
77 const real endRatio = sampleLength * rcpBaseLength;
78
79 OutputType beginValue, endValue;
80 m_beginTexture->sample(sampleLocation, &beginValue);
81 m_endTexture->sample(sampleLocation, &endValue);
82
83 *out_value = beginValue * beginRatio + endValue * endRatio;
84}
85
86}// 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
Definition TLinearGradientTexture.h:16
void sample(const SampleLocation &sampleLocation, OutputType *out_value) const override
Definition TLinearGradientTexture.ipp:59
TLinearGradientTexture(real beginU, const std::shared_ptr< TTexture< OutputType > > &beginTexture, real endU, const std::shared_ptr< TTexture< OutputType > > &endTexture)
Definition TLinearGradientTexture.ipp:12
Definition TTexture.h:12
T & x()
Definition TVector2.ipp:38
T & y()
Definition TVector2.ipp:44
T dot(const Derived &rhs) const
Definition TVectorNBase.ipp:14
bool isEqual(const Derived &other) const
Definition TArithmeticArrayBase.ipp:646
The root for all renderer implementations.
Definition EEngineProject.h:6