work in progress.

This commit is contained in:
castano
2011-09-29 00:58:47 +00:00
parent 9de43e7757
commit 676a0b2908
7 changed files with 386 additions and 258 deletions

View File

@ -153,7 +153,7 @@ int Compressor::estimateSize(const Surface & tex, int mipmapCount, const Compres
bool Compressor::outputHeader(const CubeSurface & cube, int mipmapCount, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const
{
return m.outputHeader(TextureType_Cube, cube.size(), cube.size(), 1, mipmapCount, false, compressionOptions.m, outputOptions.m);
return m.outputHeader(TextureType_Cube, cube.edgeLength(), cube.edgeLength(), 1, mipmapCount, false, compressionOptions.m, outputOptions.m);
}
bool Compressor::compress(const CubeSurface & cube, int mipmap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const
@ -168,7 +168,7 @@ bool Compressor::compress(const CubeSurface & cube, int mipmap, const Compressio
int Compressor::estimateSize(const CubeSurface & cube, int mipmapCount, const CompressionOptions & compressionOptions) const
{
return 6 * estimateSize(cube.size(), cube.size(), 1, mipmapCount, compressionOptions);
return 6 * estimateSize(cube.edgeLength(), cube.edgeLength(), 1, mipmapCount, compressionOptions);
}

View File

@ -24,9 +24,12 @@
#include "CubeSurface.h"
#include "Surface.h"
#include "nvimage/DirectDrawSurface.h"
#include "nvmath/Vector.h"
#include "nvcore/Array.h"
#include "nvcore/StrLib.h"
using namespace nv;
@ -73,17 +76,17 @@ void CubeSurface::detach()
bool CubeSurface::isNull() const
{
return m->size == 0;
return m->edgeLength == 0;
}
int CubeSurface::size() const
int CubeSurface::edgeLength() const
{
return m->size;
return m->edgeLength;
}
int CubeSurface::countMipmaps() const
{
return nv::countMipmaps(m->size);
return nv::countMipmaps(m->edgeLength);
}
Surface & CubeSurface::face(int f)
@ -101,6 +104,52 @@ const Surface & CubeSurface::face(int f) const
bool CubeSurface::load(const char * fileName)
{
if (strcmp(Path::extension(fileName), ".dds") == 0) {
nv::DirectDrawSurface dds(fileName);
if (!dds.isValid()/* || !dds.isSupported()*/) {
return false;
}
if (!dds.isTextureCube()) {
return false;
}
// Make sure it's a valid cube.
if (dds.header.width != dds.header.height) return false;
//if ((dds.header.caps.caps2 & DDSCAPS2_CUBEMAP_ALL_FACES) != DDSCAPS2_CUBEMAP_ALL_FACES) return false;
nvtt::InputFormat inputFormat = nvtt::InputFormat_RGBA_16F;
if (dds.header.hasDX10Header()) {
if (dds.header10.dxgiFormat == DXGI_FORMAT_R16G16B16A16_FLOAT) inputFormat = nvtt::InputFormat_RGBA_16F;
else if (dds.header10.dxgiFormat == DXGI_FORMAT_R32G32B32A32_FLOAT) inputFormat = nvtt::InputFormat_RGBA_32F;
else return false;
}
else {
if ((dds.header.pf.flags & DDPF_FOURCC) == 0) return false;
if (dds.header.pf.fourcc == D3DFMT_A16B16G16R16F) inputFormat = nvtt::InputFormat_RGBA_16F;
else if (dds.header.pf.fourcc == D3DFMT_A32B32G32R32F) inputFormat = nvtt::InputFormat_RGBA_32F;
else return false;
}
uint edgeLength = dds.header.width;
uint size = dds.surfaceSize(0);
void * data = malloc(size);
for (int f = 0; f < 6; f++) {
dds.readSurface(f, 0, data, size);
m->face[f].setImage(inputFormat, edgeLength, edgeLength, 1, data);
}
m->edgeLength = edgeLength;
free(data);
}
// @@ TODO
return false;
}
@ -205,7 +254,7 @@ Vector3 texelDirection(uint face, uint x, uint y, float ilen)
}
struct VectorTable {
VectorTable(int edgeLength) : size(edgeLength) {
VectorTable(uint edgeLength) : size(edgeLength) {
float invEdgeLength = 1.0f / edgeLength;
for (uint f = 0; f < 6; f++) {
@ -222,14 +271,14 @@ struct VectorTable {
return data[(f * size + y) * size + x];
}
int size;
uint size;
nv::Array<Vector3> data;
};
CubeSurface CubeSurface::cosinePowerFilter(int size, float cosinePower) const
{
const uint edgeLength = m->size;
const uint edgeLength = m->edgeLength;
// Allocate output cube.
CubeSurface filteredCube;
@ -256,15 +305,15 @@ CubeSurface CubeSurface::cosinePowerFilter(int size, float cosinePower) const
float g = face.m->image->pixel(1, x, y, 0) * solidAngle;;
float b = face.m->image->pixel(2, x, y, 0) * solidAngle;;
Vector3 texelDir = texelDirection(f, x, y, edgeLength);
Vector3 texelDir = texelDirection(f, x, y, 1.0f / edgeLength);
for (uint ff = 0; ff < 6; ff++) {
FloatImage * filteredFace = filteredCube.m->face[ff].m->image;
for (uint yy = 0; yy < size; yy++) {
for (uint xx = 0; xx < size; xx++) {
for (uint yy = 0; yy < uint(size); yy++) {
for (uint xx = 0; xx < uint(size); xx++) {
Vector3 filterDir = texelDirection(ff, xx, yy, size);
Vector3 filterDir = texelDirection(ff, xx, yy, 1.0f / size);
float power = powf(saturate(dot(texelDir, filterDir)), cosinePower);

View File

@ -44,13 +44,13 @@ namespace nvtt
{
nvDebugCheck( refCount() == 0 );
size = 0;
edgeLength = 0;
}
Private(const Private & p) : RefCounted() // Copy ctor. inits refcount to 0.
{
nvDebugCheck( refCount() == 0 );
size = p.size;
edgeLength = p.edgeLength;
for (uint i = 0; i < 6; i++) {
face[i] = p.face[6];
}
@ -59,17 +59,17 @@ namespace nvtt
{
}
void allocate(int size)
void allocate(uint edgeLength)
{
this->size = size;
this->edgeLength = edgeLength;
for (uint i = 0; i < 6; i++) {
face[i].detach();
face[i].m->image = new nv::FloatImage;
face[i].m->image->allocate(size, size, 1);
face[i].m->image->allocate(edgeLength, edgeLength, 1);
}
}
int size;
uint edgeLength;
Surface face[6];
};

View File

@ -538,7 +538,7 @@ namespace nvtt
// Queries.
NVTT_API bool isNull() const;
NVTT_API int size() const;
NVTT_API int edgeLength() const;
NVTT_API int countMipmaps() const;
// Texture data.