Skip to main content
GameDev.net gamedev.net
🔒 Locked

[ps1.4] Cubemap not sampling properly

Started by Soul Reaver Sep 13, 2011 at 12:35 AM 5 replies 2.3k views
Original Post
Soul Reaver
Soul Reaver
Hi,

currently I'm trying to implement bump mapping in a topdown game of mine.
Unfortunately the engine of this game is based on DirectX 8.1 so I'm forced to use ps.1.4 & vs.1.1 as shader model.

As you may or may not know ps.1.4 doesn't have functions like sqrt() or pow() so it's a real pain in the ass to implement the specular component of the blinn phong lighting model. To avoid these restrictions I decided to use a renormalization cubemap which is then used to renormalize the half vector which is passed from the vertex shader to the pixel shader.

The problem is that sampling the cubemap returns always black, thus (0, 0, 0, a). I create my cubemap on the fly as follows:

[source lang=cpp]
// Create the cube map and fill it
pDevice->CreateCubeTexture(512, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_pNormalizationCubemap);
D3DXFillCubeTexture(m_pNormalizationCubemap, FillCubeMap, NULL);

// Fill callback
void FillCubeMap(D3DXVECTOR4 *pOut, D3DXVECTOR3 *pTexCoord, D3DXVECTOR3 *pTexelSize, LPVOID pData)
{
// For testing purposes I set every texel to red
pOut->x = 1.0f; //pTexCoord->x * 0.5f + 0.5f;
pOut->y = 0.0f; //pTexCoord->y * 0.5f + 0.5f;
pOut->z = 0.0f //pTexCoord->z * 0.5f + 0.5f;
pOut->w = 0;
}
[/source]

Both functions return S_OK, I bind this texture to texture stage 2 with IDirect3DDevice8::SetTexture() which also returns S_OK and let the pixel shader sample it as follows:

[source]
texld r2, t2
mov r0, r2
[/source]

The primitives should now be rendered in bright red but instead everything is black, which means that the sampling returned black. But why?
I really have no idea what I'm doing wrong.
21st Century Moose
21st Century Moose
I'd bite the bullet and upgrade to D3D9. The two versions of the API are incredibly similar (it may require no more than an hour or two of work) and this problem will just go away.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
Soul Reaver
Soul Reaver
Unfortunately that's not possible. I didn't develop the engine and it isn't open source, so changing the engine would mean rewriting the whole game as this engine offers much high level functionality.
MJP
MJP
The first thing I would do would be to make sure that the cubemap is getting filled properly. I'm guessing PIX doesn't work with DX8? If not, you could just save out the cubemap as a .DDS and then look at it with DXTex to make sure it looks like what you're expecting.
Soul Reaver
Soul Reaver

The first thing I would do would be to make sure that the cubemap is getting filled properly. I'm guessing PIX doesn't work with DX8? If not, you could just save out the cubemap as a .DDS and then look at it with DXTex to make sure it looks like what you're expecting.


I tried that and it looks like the cubemap is being filled like expected.
Are there any render or sampler states which could cause my problem? Maybe the engine screws that up without me knowing about it.
MJP
MJP
I suppose border sampling mode could potentially screw you up if your texture coordinates are way off, but that's all I can think of off the top of my head.
Soul Reaver
Soul Reaver
Seems like I have to abandon bump mapping then.
Thanks for your help anyway.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.