From ca759c0c82cce0f8c5aad0370df0c162cdab227b Mon Sep 17 00:00:00 2001 From: tatsy Date: Wed, 23 Mar 2016 17:51:20 +0900 Subject: [PATCH] Image texture mapping class is added. --- sources/core/forward_decl.h | 1 + sources/texture/CMakeLists.txt | 2 ++ sources/texture/imagemap.cc | 23 ++++++++++++++++++++++ sources/texture/imagemap.h | 35 ++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 sources/texture/imagemap.cc create mode 100644 sources/texture/imagemap.h diff --git a/sources/core/forward_decl.h b/sources/core/forward_decl.h index c67b033..3ecc0de 100644 --- a/sources/core/forward_decl.h +++ b/sources/core/forward_decl.h @@ -40,6 +40,7 @@ namespace spica { class Image; class Film; class MipMap; + enum class ImageWrap; // Math module template diff --git a/sources/texture/CMakeLists.txt b/sources/texture/CMakeLists.txt index 8cfd799..493e4e7 100644 --- a/sources/texture/CMakeLists.txt +++ b/sources/texture/CMakeLists.txt @@ -1,12 +1,14 @@ set(SOURCES ${SOURCES} ${CMAKE_CURRENT_LIST_DIR}/texture.cc ${CMAKE_CURRENT_LIST_DIR}/constant.cc + ${CMAKE_CURRENT_LIST_DIR}/imagemap.cc ${CMAKE_CURRENT_LIST_DIR}/uv.cc PARENT_SCOPE) set(HEADERS ${HEADERS} ${CMAKE_CURRENT_LIST_DIR}/spica_texture.h ${CMAKE_CURRENT_LIST_DIR}/constant.h + ${CMAKE_CURRENT_LIST_DIR}/imagemap.h ${CMAKE_CURRENT_LIST_DIR}/texture.h ${CMAKE_CURRENT_LIST_DIR}/uv.h PARENT_SCOPE) diff --git a/sources/texture/imagemap.cc b/sources/texture/imagemap.cc new file mode 100644 index 0000000..1912eb2 --- /dev/null +++ b/sources/texture/imagemap.cc @@ -0,0 +1,23 @@ +#define SPICA_API_EXPORT +#include "imagemap.h" + +#include "../core/point2d.h" +#include "../math/vector2d.h" +#include "../image/mipmap.h" + +namespace spica { + +ImageTexture::ImageTexture(const Image& image, + std::unique_ptr texmap, + ImageWrap wrap) + : mipmap_{ std::make_unique(image, wrap) } + , texmap_{ std::move(texmap) } { +} + +Spectrum ImageTexture::evaluate(const SurfaceInteraction& intr) const { + Vector2d dstdx, dstdy; + Point2d st = texmap_->map(intr); + return mipmap_->lookup(st); +} + +} // namespace spica diff --git a/sources/texture/imagemap.h b/sources/texture/imagemap.h new file mode 100644 index 0000000..849706d --- /dev/null +++ b/sources/texture/imagemap.h @@ -0,0 +1,35 @@ +#ifdef _MSC_VER +#pragma once +#endif + +#ifndef _SPICA_IMAGEMAP_H_ +#define _SPICA_IMAGEMAP_H_ + +#include +#include + +#include "../core/common.h" +#include "../core/forward_decl.h" +#include "../core/spectrum.h" + +#include "texture.h" + +namespace spica { + +class ImageTexture : public Texture { +public: + ImageTexture(const Image& image, + std::unique_ptr texmap, + ImageWrap wrap); + + Spectrum evaluate(const SurfaceInteraction& intr) const; + +private: + // Private field + std::unique_ptr mipmap_; + std::unique_ptr texmap_; +}; + +} // namespace spica + +#endif // _SPICA_IMAGEMAP_H_