Skip to content

Commit

Permalink
Image texture mapping class is added.
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsy committed Mar 23, 2016
1 parent 30a674a commit ca759c0
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions sources/core/forward_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace spica {
class Image;
class Film;
class MipMap;
enum class ImageWrap;

// Math module
template <class T>
Expand Down
2 changes: 2 additions & 0 deletions sources/texture/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 23 additions & 0 deletions sources/texture/imagemap.cc
Original file line number Diff line number Diff line change
@@ -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<TextureMapping2D> texmap,
ImageWrap wrap)
: mipmap_{ std::make_unique<MipMap>(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
35 changes: 35 additions & 0 deletions sources/texture/imagemap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifdef _MSC_VER
#pragma once
#endif

#ifndef _SPICA_IMAGEMAP_H_
#define _SPICA_IMAGEMAP_H_

#include <string>
#include <memory>

#include "../core/common.h"
#include "../core/forward_decl.h"
#include "../core/spectrum.h"

#include "texture.h"

namespace spica {

class ImageTexture : public Texture<Spectrum> {
public:
ImageTexture(const Image& image,
std::unique_ptr<TextureMapping2D> texmap,
ImageWrap wrap);

Spectrum evaluate(const SurfaceInteraction& intr) const;

private:
// Private field
std::unique_ptr<MipMap> mipmap_;
std::unique_ptr<TextureMapping2D> texmap_;
};

} // namespace spica

#endif // _SPICA_IMAGEMAP_H_

0 comments on commit ca759c0

Please sign in to comment.