From db072ad4dc181eca5a1458656b130beb43f475bf Mon Sep 17 00:00:00 2001 From: 53hornet <53hornet@gmail.com> Date: Sat, 2 Feb 2019 23:33:15 -0500 Subject: Init. --- hw6/src/bumpMap.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 hw6/src/bumpMap.cpp (limited to 'hw6/src/bumpMap.cpp') diff --git a/hw6/src/bumpMap.cpp b/hw6/src/bumpMap.cpp new file mode 100644 index 0000000..ecd6f49 --- /dev/null +++ b/hw6/src/bumpMap.cpp @@ -0,0 +1,48 @@ +/******************************************************************/ +/* This file is part of the homework assignments for CSCI-427/527 */ +/* at The College of William & Mary and authored by Pieter Peers. */ +/* No part of this file, whether altered or in original form, can */ +/* be distributed or used outside the context of CSCI-427/527 */ +/* without consent of either the College of William & Mary or */ +/* Pieter Peers. */ +/******************************************************************/ +#include +#include +#include "bumpMap.h" +#include "coordinateTransform.h" + +////////////////// +// Constructors // +////////////////// +bumpMap::bumpMap(const std::shared_ptr& map, float scale, unsigned int channel, const std::shared_ptr& shader) + : shadingFrameTransformation(shader) +{ + _map = map; + _scale = scale; + _channel = std::max(channel, 2u); +} + +///////////// +// Methods // +///////////// +transformation3d bumpMap::_transformation(const vec2d& textureCoord) const +{ + // get derivative in X and Y direction + assert(_map); + float dx = (*_map)(textureCoord)[_channel] - (*_map)(textureCoord + vec2d(1.0f/_map->width(), 0.0f))[_channel]; + float dy = (*_map)(textureCoord)[_channel] - (*_map)(textureCoord + vec2d(0.0f, 1.0f/_map->height()))[_channel]; + + // get desired local normal = (1.0, 0.0, dx) cross (0.0, 1.0, dy) + vec3d normal(-dx, -dy, 1.0f / _scale); + normal.normalize(); + + // create coordinate system. Keep U aligned as close as possible to the X axis. + return coordinateTransformation(normal, vec3d(1.0f, 0.0, 0.0)); +} + + +void bumpMap::_print(std::ostream& s) const +{ + s << "bumpMap (" << _scale << " x " << *_map << "[" << _channel << "]) -> {" << *_shader << "}"; +} + -- cgit v1.2.3