Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TNearestPixelTex2D.h
Go to the documentation of this file.
1#pragma once
2
5#include "Math/math.h"
6
7namespace ph
8{
9
10template<typename T, std::size_t N>
11class TNearestPixelTex2D : public TPixelTex2D<T, N>
12{
13public:
14 using TPixelTex2D<T, N>::TPixelTex2D;
15
16 inline void sample(
17 const SampleLocation& sampleLocation,
18 TTexPixel<T, N>* const out_value) const override
19 {
20 const uint32 w = this->getWidthPx();
21 const uint32 h = this->getHeightPx();
22
23 PH_ASSERT(w != 0 && h != 0);
24
25 // normalize uv first to avoid overflowing xy after multiplying
26 // width and height
27 float64 normU, normV;
28 this->normalizeUV(sampleLocation.uvw().x(), sampleLocation.uvw().y(),
29 &normU, &normV);
30
31 // calculate pixel index and handle potential overflow
32 uint32 x = static_cast<uint32>(normU * w);
33 uint32 y = static_cast<uint32>(normV * h);
34 x = x < w ? x : w - 1;
35 y = y < h ? y : h - 1;
36
37 this->getPixel(x, y, out_value);
38 }
39};
40
41}// 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
uint32 getWidthPx() const
Definition TAbstractPixelTex2D.h:39
uint32 getHeightPx() const
Definition TAbstractPixelTex2D.h:40
void normalizeUV(const float64 u, const float64 v, float64 *const out_u, float64 *const out_v) const
Definition TAbstractPixelTex2D.h:52
Definition TNearestPixelTex2D.h:12
void sample(const SampleLocation &sampleLocation, TTexPixel< T, N > *const out_value) const override
Definition TNearestPixelTex2D.h:16
Definition TPixelTex2D.h:16
void getPixel(const uint32 x, const uint32 y, TTexPixel< T, N > *const out_pixel) const
Definition TPixelTex2D.h:40
TPixelTex2D()
Definition TPixelTex2D.h:18
Definition TArithmeticArray.h:13
T & y()
Definition TVector3.ipp:189
T & x()
Definition TVector3.ipp:183
Miscellaneous math utilities.
The root for all renderer implementations.
Definition EEngineProject.h:6