3 registered members (Ayumi, Akow, AndrewAMD),
1,505
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
3d texture
#421207
04/13/13 14:24
04/13/13 14:24
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
OP
Expert
|
OP
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
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)
POTATO-MAN saves the day! - Random
|
|
|
Re: 3d texture
[Re: Kartoffel]
#421220
04/13/13 19:30
04/13/13 19:30
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
OP
Expert
|
OP
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
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:
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?
Last edited by Kartoffel; 04/13/13 20:22.
POTATO-MAN saves the day! - Random
|
|
|
Re: 3d texture
[Re: Kartoffel]
#421239
04/14/13 10:37
04/14/13 10:37
|
Joined: Jun 2004
Posts: 655 to your left
BoH_Havoc
User
|
User
Joined: Jun 2004
Posts: 655
to your left
|
As far as i know you can't simply use BMAP* the traditional way to load volume textures. Here's how i do it:
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! [edit] Here's the missing stuff
// 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
Last edited by BoH_Havoc; 04/14/13 11:08.
|
|
|
Re: 3d texture
[Re: BoH_Havoc]
#421242
04/14/13 10:48
04/14/13 10:48
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
OP
Expert
|
OP
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
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.
POTATO-MAN saves the day! - Random
|
|
|
|