Here:
This is how i create my normal. I'm pretty sure the code is correct. (I skip the edges for now..)
for (int z = 1; z < mChunkSamples - 1; z++)
{
for (int x = 1; x < mChunkSamples - 1; x++)
{
D3DXVECTOR3 v0(x, pVertices[x + z*mChunkSamples].y , z);
D3DXVECTOR3 v1(x + 1, pVertices[(x + 1) + z*mChunkSamples].y ,z);
D3DXVECTOR3 v2(x, pVertices[x + (z + 1)*mChunkSamples].y , z + 1);
D3DXVECTOR3 n1 = v1 - v0;
D3DXVECTOR3 n2 = v2 - v0;
D3DXVECTOR3 n;
D3DXVec3Cross(&n, &n2, &n1);
D3DXVec3Normalize(&n, &n);
pNormalmap[x + z*mChunkSamples] = n;
}
}
And this is how i create the normal map:
D3D11_SUBRESOURCE_DATA data;
data.pSysMem = pNormalmap;
data.SysMemPitch = mChunkSamples * 12;
data.SysMemSlicePitch = 0;
Texture2dConfig config;
config.Width = mChunkSamples;
config.Height = mChunkSamples;
config.Format = DXGI_FORMAT_R32G32B32_FLOAT;
Texture2D* pTexture = mRenderer->CreateTexture2D(config, &data);
ShaderResourceViewConfig r_config;
r_config.Format = DXGI_FORMAT_R32G32B32_FLOAT;
r_config.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
r_config.Texture2D.MipLevels = 1;
r_config.Texture2D.MostDetailedMip = 0;
pChunk->mNormalMap = mRenderer->CreateShaderResourceView(pTexture, r_config);
Now i thought that there is a problem with my normal maps, so i did a simple test. I filled the normal map with the vertex positions [x,z] : [-256, 256]
When i rendered, this is what i got:
Now why does this happen?
This is what is supposed to happen: (I think since i hardcoded the shader to output the vertex position as colour)
With that i conclude that the problem is with the normal map itself. I think. I also don't know why the 3rd quadrant is black?
Help me