У меня есть текстура, которая может содержать произвольные данные. Я хочу попробовать эту текстуру с помощью бикубической фильтрации (билинеарная недостаточно гладкая). Здесь пример данных: < /p>
struct Data
{
Data operator+(const Data& val) const;
bool operator==(const Data& other);
bool operator!=(const Data& other);
Data& operator=(const Data& other);
//...
private:
float m_values[16];
};
< /code>
Все необходимые операторы предоставляются. Я видел этот ответ, но я не вижу, как я могу расширить это, чтобы поддержать произвольные данные.template
inline T TImage::getBilinearPixelFromCoord(const Math::Vec2& ratio) const
{
const uint32_t widthMinusOne = getWidth() - 1u;
const uint32_t heightMinusOne = getHeight() - 1u;
// Bilinear interpolation.
// The sampling weights.
const Math::Vec2 C00Float = Math::Vec2(ratio.x * (float)getWidth(), ratio.y * (float)getHeight());
const Math::Vec2 weights = glm::fract(C00Float);
// The sampling coordinates.
const Math::Uvec2 C00 = Math::Uvec2(
Math::clamp((uint32_t)C00Float.x, 0u, widthMinusOne),
Math::clamp((uint32_t)C00Float.y, 0u, heightMinusOne));
const Math::Uvec2 C10 = Math::Uvec2(
Math::clamp(C00.x + 1u, 0u, widthMinusOne),
Math::clamp(C00.y, 0u, heightMinusOne));
const Math::Uvec2 C01 = Math::Uvec2(
Math::clamp(C00.x, 0u, widthMinusOne),
Math::clamp(C00.y + 1u, 0u, heightMinusOne));
const Math::Uvec2 C11 = Math::Uvec2(
Math::clamp(C00.x + 1u, 0u, widthMinusOne),
Math::clamp(C00.y + 1u, 0u, heightMinusOne));
// The sampling values.
const T V00 = getPixelFromPosition(C00);
const T V10 = getPixelFromPosition(C10);
const T V01 = getPixelFromPosition(C01);
const T V11 = getPixelFromPosition(C11);
// Perform the interpolation.
const auto lerp = [](T t1, T t2, float t3) { return t1 + (t2 - t1) * t3; };
const T p0 = lerp(V00, V01, weights.y);
const T p1 = lerp(V10, V11, weights.y);
return lerp(p0, p1, weights.x);
}
так бикубик будет выглядеть так:
template
inline T TImage::getBicubicPixelFromCoord(const Math::Vec2& ratio) const
{
// Some code
}
< /code>
Как реализовать это getbicubicpixelfromcoord < /strong>?
У меня есть текстура, которая может содержать произвольные данные. Я хочу попробовать эту текстуру с помощью бикубической фильтрации (билинеарная недостаточно гладкая). Здесь пример данных: < /p> [code]struct Data { Data operator+(const Data& val) const; bool operator==(const Data& other); bool operator!=(const Data& other); Data& operator=(const Data& other); //... private: float m_values[16]; }; < /code> Все необходимые операторы предоставляются. Я видел этот ответ, но я не вижу, как я могу расширить это, чтобы поддержать произвольные данные.template inline T TImage::getBilinearPixelFromCoord(const Math::Vec2& ratio) const { const uint32_t widthMinusOne = getWidth() - 1u; const uint32_t heightMinusOne = getHeight() - 1u;
// The sampling values. const T V00 = getPixelFromPosition(C00); const T V10 = getPixelFromPosition(C10); const T V01 = getPixelFromPosition(C01); const T V11 = getPixelFromPosition(C11);
// Perform the interpolation. const auto lerp = [](T t1, T t2, float t3) { return t1 + (t2 - t1) * t3; };
const T p0 = lerp(V00, V01, weights.y); const T p1 = lerp(V10, V11, weights.y);
return lerp(p0, p1, weights.x); } [/code] [b] так бикубик будет выглядеть так: [/b] template inline T TImage::getBicubicPixelFromCoord(const Math::Vec2& ratio) const { // Some code } < /code> Как реализовать это getbicubicpixelfromcoord < /strong>?