Also it does not fit into the concept of irrlicht 2D-images / textures, it works with (pixel-)shaders. This modification is not intended to have modify able 3D textures! (ITexture::lock() returns 0)
It is not implemented with Dx8, and irrlicht is not even compiled with Dx8 support, because of compile errors when compiling both (see C3DTexture.h modification info).
The procedure is not like for the other textures, where first an IImage is generated. It bypasses some steps and directly loads the file using a D3DX call.
Changed files:
CNullDriver.h /.cpp
CD3D9Driver.h /.cpp
CD3D9Texture.h / .cpp
IrrCompileConfig.h // to disable Dx8 support
I know, this is no clean code, but its working code, which works for me so far, since I desperatly need 3D textures
EDIT: For usage: just call Drv->getTexture("MyVolumeTexture.dds"), add it to a SMaterial and within the pixelshader use sampler3D tex0 (1,2,3) and a lookup with col = tex3D(tex0, texCoord)
EDIT2: This modification is based on Irrlicht 1.4.
Changes to CNullDriver.h:
Code: Select all
/**** BELOW createDeviceDependentTexture(..) */
//! returns a device dependent texture from a file
//! THIS METHOD HAS TO BE OVERRIDDEN BY DERIVED DRIVERS WITH OWN TEXTURES
virtual video::ITexture* createDeviceDependentTextureFromFile(const char* filename);
Code: Select all
/**** WITHIN CNullDriver::loadTextureFromFile */
// After if(image){...}
else
{
if(!hashName)
os::Printer::log("Loading texture from filename failed: NULL");
else
{
// hashName == filename
texture = createDeviceDependentTextureFromFile(hashName);
}
}
/**** NEW (e.g. at end of file [WITHIN namespace's] */
//! returns a device dependent texture from a loaded file
//! THIS METHOD HAS TO BE OVERRIDDEN BY DERIVED DRIVERS WITH OWN TEXTURES
video::ITexture* CNullDriver::createDeviceDependentTextureFromFile(const char* fileName)
{
return 0;
}
Code: Select all
/**** AFTER createDeviceDependentTexture(..) */
//! returns a device dependent texture from a file
//! THIS METHOD HAS TO BE OVERRIDDEN BY DERIVED DRIVERS WITH OWN TEXTURES
virtual video::ITexture* createDeviceDependentTextureFromFile(const char* filename);
Code: Select all
/**** AFTER createDeviceDependentTexture(..) */
video::ITexture* CD3D9Driver::createDeviceDependentTextureFromFile(const char* filename)
{
return new CD3D9Texture(filename, this, TextureCreationFlags, filename);
}
Code: Select all
/**** ADD NEW CONSTRUCTOR */
//! constructor for volumetric textures
CD3D9Texture(const char* filename, CD3D9Driver* driver,
u32 flags, const char* name);
/**** CHANGE FROM */
IDirect3DTexture9* getDX9Texture() const;
/**** CHANGE TO (IDirect3DBaseTexture9 is the base for both 2D and 3D textures) */
IDirect3DBaseTexture9* getDX9Texture() const;
/**** ADD private MEMBER */
IDirect3DVolumeTexture9* VolumeTexture;
As a code comment within this file says, there are errrors when using D3DX functions + Dx9 + Dx8, therefore Dx8 support is disabled within IrrCompileConfig.h.
Since Dx8 support is disabled, we can use D3DX mipmap creation features and the D3DX lib gets linked through the first change.
Code: Select all
/**** UNCOMMENT */
#define _IRR_USE_D3DXFilterTexture_
/**** MODIFY both existent constructors, so that new member gets initialized proper, e.g. add to initialization list:
VolumeTexture(0)
/**** ADD new constructor
//! constructor for volumetric textures
CD3D9Texture::CD3D9Texture(const char * fileName, CD3D9Driver* driver,
u32 flags, const char* name) :
ITexture(name), Image(0), Texture(0), RTTSurface(0), Driver(driver),
TextureSize(0,0), ImageSize(0,0), Pitch(0),
HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(false), VolumeTexture(0)
{
#ifdef _DEBUG
setDebugName("CD3D9Texture");
#endif
const bool generateMipLevels = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
Device=driver->getExposedVideoData().D3D9.D3DDev9;
if (Device)
Device->AddRef();
HRESULT hr = D3DXCreateVolumeTextureFromFile(
Device,
fileName,
&VolumeTexture);
if(FAILED(hr))
{
os::Printer::log("D3D9Texture: Failed to load volume texture from file", fileName, ELL_ERROR);
}
}
/**** MODIFY destructor, add */
if (VolumeTexture)
VolumeTexture->Release();
/**** CHANGE from */
IDirect3DTexture9* CD3D9Texture::getDX9Texture() const
{
return Texture;
}
/**** CHANGE to */
IDirect3DBaseTexture9* CD3D9Texture::getDX9Texture() const
{
if(!Texture && VolumeTexture)
{
return VolumeTexture;
}
else
return Texture;
}
Change IrrCompileConfig.h:
Code: Select all
/**** COMMENT / DELETE */
#define _IRR_COMPILE_WITH_DIRECT3D_8_


