I've created a dynamic texture PF_L8 like this:
Code: Select all
heightMapTex = TextureManager::getSingleton().createManual(
"rttHeightMap",
"General",
TEX_TYPE_2D,
33,
33,
0,
PF_L8,
TU_DYNAMIC_WRITE_ONLY
);
Code: Select all
TexturePtr heightMapTex = TextureManager::getSingleton().getByName("rttHeightMap");
HardwarePixelBufferSharedPtr heightPBuf = heightMapTex->getBuffer();
// lock the buffer
heightPBuf->lock(HardwareBuffer::HBL_DISCARD);
const PixelBox& heightPBox = heightPBuf->getCurrentLock();
// case to uint8
uint8* heightDest = static_cast<uint8*>(heightPBox.data);
for(unsigned int i = 0; i < heightPBox.getWidth(); ++i) {
for(unsigned int j = 0; j < heightPBox.getHeight(); ++j) {
*heightDest++ = 255;
}
}
heightPBuf->unlock();
Code: Select all
void main_vp( float4 position : POSITION,
float2 uv : TEXCOORD0,
uniform float4x4 worldViewProj,
out float4 oPosition : POSITION,
out float2 oUv : TEXCOORD0
)
{
oPosition = mul(worldViewProj, position);
oUv = uv;
}
void main_fp(
float2 uv : TEXCOORD0,
uniform sampler2D heightMap : register(s0), // <-- this is the dynamic texture that should be white
out float4 outcolour : COLOR0
)
{
float altitude = tex2D(heightMap,uv).r;
// outcolour should be the height - all white for now because we set it to 255 for every pixel
outcolour = float4(altitude,altitude,altitude,1.0f);
}
My gfx card is a 8600M GT and it supports non-power of 2 textures (From the log -> 22:12:12: * Non-power-of-two textures: yes)
In OpenGL with a GLSL shader that does the same thing this works fine, but in DirectX it doesn't work. Funny thing is if I use tex2D(heightMap, uv).a the texture is all white.
Should I be using a different pixel format? I tried PF_FLOAT16_R and PF_FLOAT_32R and changed the cast from uint8 to uint16 and uint32, but both of those made the texture appear completely black.
*so confused*