3d texture

Posted By: Kartoffel

3d texture - 04/13/13 14:24

hey there,
Does anyone know how to use 3d textures properly?

I used the gimp .dds plugin to save a 32³ volume map and I read the texture color by using tex3D but somehow it doesn't work.
(it behaves like a 2D texture and just uses the first layer)
Posted By: BoH_Havoc

Re: 3d texture - 04/13/13 17:57

As the Photoshop .dds plugin also doesn't really work for me (when trying to create 3D textures, everything else works fine), i always use DxTex.exe from the DirectX SDK to do the job. Works great. laugh
Posted By: Kartoffel

Re: 3d texture - 04/13/13 18:15

Thanks a lot, I'll try it!
Posted By: Kartoffel

Re: 3d texture - 04/13/13 19:30

I tried it but somehow it still doesn't work...

Do I have to mind anything special? like special texture coordinates when using tex3D?

EDIT: I'm using it like this:
Code:
texture tLUT_bmap;
sampler3D smpLUT = sampler_state
{
	Texture = <tLUT_bmap>;

	Filter = Linear;
	
	AddressU = Clamp;
	AddressV = Clamp;
	AddressW = Clamp;
};

[...]

Color.rgb = tex3D(smpLUT, Color.rgb).rgb;


If I use the screenspace coordinates as texcoords and change the z-coordinate it always displays the first slice.

Edit: maybe a BMAP * can't handle volume textures?
Posted By: BoH_Havoc

Re: 3d texture - 04/14/13 10:37

As far as i know you can't simply use BMAP* the traditional way to load volume textures.
Here's how i do it:

Code:
STRING* sc_deferredLighting_sBRDFLUT = "shadec/tex/sc_deferredLighting_LUT.dds";
LPDIRECT3DVOLUMETEXTURE9* sc_deferredLighting_texBRDFLUT;

LPDIRECT3DVOLUMETEXTURE9 sc_volumeTexture_create(STRING *filename)
{
	LPDIRECT3DVOLUMETEXTURE9 temptex;
	HRESULT res = D3DXCreateVolumeTextureFromFile((LPDIRECT3DDEVICE9)pd3ddev, _chr(filename), &temptex);
	if(res != S_OK)
	{
		printf("error: %x", res);
		return NULL;
	}
	return temptex;
}

//create brdf LUT
if(!sc_deferredLighting_texBRDFLUT) sc_deferredLighting_texBRDFLUT = sc_volumeTexture_create(sc_deferredLighting_sBRDFLUT);

//In your material event
LPD3DXEFFECT pEffect = (LPD3DXEFFECT)render_d3dxeffect;
pEffect->SetTexture("texBRDFLut", sc_deferredLighting_texBRDFLUT); //assign volumetric brdf lut



I think you can also directly set it to BMAP.d3dtex once you loaded it using sc_volumeTexture_create() but i'm not sure.

The texcoords for fetching the volume slide are in range 0-1. In order to fetch a slide from a volume texture with a depth of 32 you can fetch that by x/32.
Also, if i remember correctly, you always have to use a power of 2 for your volume depth. Volume textures with 3,5,6,7,9,etc slides won't work. I may be wrong on this, but something in my mind tells me it was this way when i used volume textures with gamestudio.

Hope this helps! laugh

[edit] Here's the missing stuff
Code:
// Original code by Nils Daumann | www.slindev.com
// http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=357697&Main=42496#Post357697

#undef INTERFACE
#define INTERFACE IDirect3DTexture9

DECLARE_INTERFACE_(IDirect3DVolumeTexture9, IDirect3DBaseTexture9)
{
    /*** IUnknown methods ***/
    STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj) PURE;
    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
    STDMETHOD_(ULONG,Release)(THIS) PURE;

    /*** IDirect3DBaseTexture9 methods ***/
    STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice) PURE;
    STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags) PURE;
    STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid,void* pData,DWORD* pSizeOfData) PURE;
    STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid) PURE;
    STDMETHOD_(DWORD, SetPriority)(THIS_ DWORD PriorityNew) PURE;
    STDMETHOD_(DWORD, GetPriority)(THIS) PURE;
    STDMETHOD_(void, PreLoad)(THIS) PURE;
    STDMETHOD_(D3DRESOURCETYPE, GetType)(THIS) PURE;
    STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew) PURE;
    STDMETHOD_(DWORD, GetLOD)(THIS) PURE;
    STDMETHOD_(DWORD, GetLevelCount)(THIS) PURE;
    STDMETHOD(SetAutoGenFilterType)(THIS_ D3DTEXTUREFILTERTYPE FilterType) PURE;
    STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)(THIS) PURE;
    STDMETHOD_(void, GenerateMipSubLevels)(THIS) PURE;
    STDMETHOD(GetLevelDesc)(THIS_ UINT Level,D3DSURFACE_DESC *pDesc) PURE;
    STDMETHOD(GetSurfaceLevel)(THIS_ UINT Level,void** ppSurfaceLevel) PURE;//IDirect3DSurface9
    STDMETHOD(LockRect)(THIS_ UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags) PURE;
    STDMETHOD(UnlockRect)(THIS_ UINT Level) PURE;
    STDMETHOD(AddDirtyRect)(THIS_ CONST RECT* pDirtyRect) PURE;
};

MY_DECLARE_INTERFACE(IDirect3DVolumeTexture9)
typedef IDirect3DVolumeTexture9 *LPDIRECT3DVOLUMETEXTURE9;

HRESULT WINAPI
    D3DXCreateVolumeTextureFromFileA(
        LPDIRECT3DDEVICE9         pDevice,
        LPCSTR                    pSrcFile,
        LPDIRECT3DVOLUMETEXTURE9* ppVolumeTexture);

#define D3DXCreateVolumeTextureFromFile D3DXCreateVolumeTextureFromFileA

Posted By: Kartoffel

Re: 3d texture - 04/14/13 10:48

Yes this helps a lot.

The default d3d9.h doesn't include LPDIRECT3DVOLUMETEXTURE9 but I just saw that it's declaration is in sc_volumeTexture.c & .h from shade-c.

I'm going to try it and I'll let you know if it works.
Posted By: Kartoffel

Re: 3d texture - 04/14/13 12:45

Works perfectly, thank you very much.
© 2024 lite-C Forums