Merge changes from private tree.

Eliminate files that are not needed for NVTT.
This commit is contained in:
castano
2009-03-01 00:18:47 +00:00
parent 6fb29816a2
commit 88fc5ca18e
93 changed files with 837 additions and 6561 deletions

View File

@ -23,7 +23,6 @@ SET(IMAGE_SRCS
NormalMap.h
NormalMap.cpp
NormalMipmap.h
NormalMipmap.cpp
PsdFile.h
TgaFile.h
ColorSpace.h

View File

@ -12,7 +12,7 @@
#include <nvcore/Containers.h>
#include <nvcore/StrLib.h>
#include <nvcore/StdStream.h>
//#include <nvcore/Tokenizer.h> // @@ Disable temporarily
#include <nvcore/Tokenizer.h>
#include <nvcore/TextWriter.h>
// Extern
@ -186,14 +186,12 @@ FloatImage * nv::ImageIO::loadFloat(const char * fileName, Stream & s)
}
#endif
/* // @@ Disable temporarily
if (strCaseCmp(extension, ".pfm") == 0) {
return loadFloatPFM(fileName, s);
}
if (strCaseCmp(extension, ".hdr") == 0) {
return loadGridFloat(fileName, s);
}
*/
return NULL;
}
@ -1534,7 +1532,6 @@ bool nv::ImageIO::saveFloatEXR(const char * fileName, const FloatImage * fimage,
#endif // defined(HAVE_OPENEXR)
#if 0 // @@ Disable temporarily.
FloatImage * nv::ImageIO::loadFloatPFM(const char * fileName, Stream & s)
{
@ -1723,7 +1720,6 @@ NVIMAGE_API FloatImage * nv::ImageIO::loadGridFloat(const char * fileName, Strea
return fimage.release();
}
#endif
#if 0

View File

@ -52,7 +52,7 @@ namespace nv
NVIMAGE_API bool saveFloatEXR(const char * fileName, const FloatImage * fimage, uint base_component, uint num_components);
#endif
/*
NVIMAGE_API FloatImage * loadFloatPFM(const char * fileName, Stream & s);
NVIMAGE_API bool saveFloatPFM(const char * fileName, const FloatImage * fimage, uint base_component, uint num_components);
@ -60,7 +60,7 @@ namespace nv
// Expects: 1) fileName will be an ".hdr" header file, 2) there will also exist a corresponding float data
// blob in a ".flt" file. (This is what USGS gives you.)
NVIMAGE_API FloatImage * loadGridFloat(const char * fileName, Stream & s);
*/
} // ImageIO namespace
} // nv namespace

View File

@ -1,99 +0,0 @@
// This code is in the public domain -- castanyo@yahoo.es
#include <nvimage/NormalMipmap.h>
#include <nvimage/FloatImage.h>
#include <nvmath/Montecarlo.h>
#include <nvmath/SphericalHarmonic.h>
#include <nvcore/Ptr.h>
using namespace nv;
FloatImage * nv::createNormalMipmapMap(const FloatImage * img)
{
nvDebugCheck(img != NULL);
uint w = img->width();
uint h = img->height();
uint hw = w / 2;
uint hh = h / 2;
FloatImage dotImg;
dotImg.allocate(1, w, h);
FloatImage shImg;
shImg.allocate(9, hw, hh);
SampleDistribution distribution(256);
const uint sampleCount = distribution.sampleCount();
for (uint d = 0; d < sampleCount; d++)
{
const float * xChannel = img->channel(0);
const float * yChannel = img->channel(1);
const float * zChannel = img->channel(2);
Vector3 dir = distribution.sampleDir(d);
Sh2 basis;
basis.eval(dir);
for(uint i = 0; i < w*h; i++)
{
Vector3 normal(xChannel[i], yChannel[i], zChannel[i]);
normal = normalizeSafe(normal, Vector3(zero), 0.0f);
dotImg.setPixel(dot(dir, normal), d);
}
// @@ It would be nice to have a fastDownSample that took an existing image as an argument, to avoid allocations.
AutoPtr<FloatImage> dotMip(dotImg.fastDownSample());
for(uint p = 0; p < hw*hh; p++)
{
float f = dotMip->pixel(p);
// Project irradiance to sh basis and accumulate.
for (uint i = 0; i < 9; i++)
{
float & sum = shImg.channel(i)[p];
sum += f * basis.elemAt(i);
}
}
}
FloatImage * normalMipmap = new FloatImage;
normalMipmap->allocate(4, hw, hh);
// Precompute the clamped cosine radiance transfer.
Sh2 prt;
prt.cosineTransfer();
// Allocate outside the loop.
Sh2 sh;
for(uint p = 0; p < hw*hh; p++)
{
for (uint i = 0; i < 9; i++)
{
sh.elemAt(i) = shImg.channel(i)[p];
}
// Convolve sh irradiance by radiance transfer.
sh *= prt;
// Now sh(0) is the ambient occlusion.
// and sh(1) is the normal direction.
// Should we use SVD to fit only the normals to the SH?
}
return normalMipmap;
}

102
src/nvimage/TiledImage.cpp Normal file
View File

@ -0,0 +1,102 @@
// This code is in the public domain -- castano@gmail.com
#include "TiledImage.h"
#include <nvcore/StdStream.h>
using namespace nv;
namespace
{
// MRU helpers:
// ...
}
bool Tile::load(const char * name)
{
StdInputStream stream(name);
if (stream.isError()) {
return false;
}
uint header;
stream << header;
if (header == 'NVTC') {
return false;
}
uint count;
stream << count;
if (count != w*h) {
return false;
}
const uint size = count * sizeof(float);
return stream.serialize(data, size) == size;
}
bool Tile::unload(const char * name)
{
StdOutputStream stream(name);
if (stream.isError()) {
return false;
}
uint header = 'NVTC';
uint count = w * h;
const uint size = w * h * sizeof(float);
stream << header << count;
return stream.serialize(data, size) == size;
}
TiledImage::TiledImage()
{
}
void TiledImage::allocate(uint c, uint w, uint h, uint pageCount)
{
// Allocate page map:
const uint pw = ((w + TILE_SIZE - 1) / TILE_SIZE);
const uint ph = ((h + TILE_SIZE - 1) / TILE_SIZE);
const uint size = c * pw * ph;
m_pageMap.resize(size);
m_residentArray.resize(pageCount, ~0);
}
void TiledImage::prefetch(uint c, uint x, uint y)
{
}
void TiledImage::prefetch(uint c, uint x, uint y, uint w, uint h)
{
}
void TiledImage::loadPage(uint x, uint y)
{
const uint pw = ((w + TILE_SIZE - 1) / TILE_SIZE);
const uint ph = ((h + TILE_SIZE - 1) / TILE_SIZE);
nvDebugCheck(x < pw);
nvDebugCheck(y < ph);
}

152
src/nvimage/TiledImage.h Normal file
View File

@ -0,0 +1,152 @@
// This code is in the public domain -- castano@gmail.com
#ifndef NV_IMAGE_TILEDIMAGE_H
#define NV_IMAGE_TILEDIMAGE_H
#include <nvcore/Debug.h>
#include <nvcore/StrLib.h>
#include <nvimage/nvimage.h>
// For simplicity the tile size is fixed at compile time.
#define TILE_SIZE 256
// 256 * 256 * 4 = 2^(8+8+2) = 2^18 = 256 KB
// 512 * 512 * 4 = 2^(9+9+2) = 2^20 = 1 MB
namespace nv
{
#if 0
struct ImageConcept
{
float pixel(uint x, uint y) const;
};
enum WrapMode {
WrapMode_Clamp,
WrapMode_Repeat,
WrapMode_Mirror
};
template <class T>
class Sampler
{
// ...
};
#endif
class Tile
{
Tile(uint x, uint y, uint w, uint h) : xoffset(x), yoffset(y), w(w), h(h)
{
data = new float[w*h];
}
~Tile()
{
delete [] data;
}
uint size() const
{
return w * h * sizeof(float);
}
float pixel(uint x, uint y) const
{
x -= xoffset;
y -= yoffset;
nvDebugCheck (x < w);
nvDebugCheck (y < h);
return data[y * w + x];
}
bool load(const char * name);
void unload(const char * name);
uint xoffset, yoffset;
uint w, h;
float * data;
};
class TiledImage
{
public:
TiledImage();
void allocate(uint c, uint w, uint h, uint pageCount);
uint componentCount() const { return m_componentCount; }
uint width() const { return m_width; }
uint height() const { return m_height; }
uint pageCount() const { return m_residentArray.count(); }
void prefetch(uint c, uint x, uint y);
void prefetch(uint c, uint x, uint y, uint w, uint h);
float pixel(uint c, uint x, uint y);
private:
Tile * tileAt(uint c, uint x, uint y);
Tile * tileAt(uint idx);
uint loadPage(uint x, uint y);
void unloadPage(Tile *);
uint addAndReplace(uint newPage);
private:
uint m_componentCount;
uint m_width;
uint m_height;
struct Page {
Page() : tile(NULL) {}
String tmpFileName;
Tile * tile;
};
mutable Array<Page> m_pageMap;
mutable Array<uint> m_residentArray; // MRU
};
inline float TiledImage::pixel(uint c, uint x, uint y)
{
nvDebugCheck (c < m_componentCount);
nvDebugCheck (x < m_width);
nvDebugCheck (y < m_height);
uint px = x / TILE_SIZE;
uint py = y / TILE_SIZE;
Tile * tile = tileAt(c, px, py);
if (tile == NULL) {
tile = loadPage(c, px, py);
}
return tile->pixel(x, y);
}
inline Tile * TiledImage::tileAt(uint c, uint x, uint y)
{
uint idx = (c * h + y) * w + x;
return tileAt(idx);
}
inline Tile * TiledImage::tileAt(uint idx)
{
return m_pageMap[idx].tile;
}
} // nv namespace
#endif // NV_IMAGE_TILEDIMAGE_H