Hello guys,
I've run into another kinda interesting bug which I'm having trouble figuring out.
I'm trying to do some (albeit strange) lighting calculations where the point light diffuse, radius and position are baked (in the case of radius and position, encoded) into 1D textures. As such, I've created 1D textures like so:
bool CreateTexture1DClass::Initialize(ID3D11Device *device, std::vector<UINT8> &perChannelData, int width)
{
m_width = width;
D3D11_TEXTURE1D_DESC desc;
ZeroMemory(&desc, sizeof(desc));
desc.Width = m_width;
desc.MipLevels = desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.MiscFlags = 0;
desc.Usage = D3D11_USAGE_DYNAMIC ;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
HRESULT result;
D3D11_SUBRESOURCE_DATA subresource;
subresource.SysMemSlicePitch = 0;
subresource.SysMemPitch = perChannelData.size() * sizeof(UINT8);
subresource.pSysMem = &perChannelData[0];
result = device->CreateTexture1D(&desc, &subresource, &m_pTexture);
if(FAILED(result))
{
return false;
}
D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;
shaderResourceViewDesc.Format = desc.Format;
shaderResourceViewDesc.Texture1D.MostDetailedMip = 0;
shaderResourceViewDesc.Texture1D.MipLevels = 1;
shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
result = device->CreateShaderResourceView(m_pTexture, &shaderResourceViewDesc, &m_shaderResourceView);
if(FAILED(result))
{
return false;
}
return true;
}
Now, for testing purposes I pre-load the color and radius into textures, then outputted them as 1D DDS files to see if my logic was right. The good news here is, it worked!
Now, onto using them in my shaders. As I said I'm trying to do something (possibly) weird, which is to render the point-light diffuse values to a texture as part of the deferred step, but sampling the values in the domain shader (as I have new vertices being made and such). Here's how I've declared my textures and the samplers:
Texture2D tex;
Texture2D normalMap;
Texture2D specularMap;
Texture2D displacementMap;
Texture1D pointLightDiffuseMap;
Texture1D pointLightPositionMap;
Texture1D pointLightRadiusMap;
SamplerState PixelSampler;
SamplerState DomainSampler;
in my domain shader for now, I'm just doing the following:
output.pointDiffuseAdd = pointLightDiffuseMap.SampleLevel(DomainSampler, 0, 0);
this essentially gets piped straight thru to the PixelOutput, so essentially i get a deferred render target which is filled with a flat color.
Now, The problem is this: The pointLightDiffuseMap at the moment is just a 1D texture which has two values: Red, Blue. If my understanding is correct, with the SampleLevel's second parameter being 0, I should get back a full-red image. However, what I get back is a deep shade of purple! (it /almost/ looks like its blending the red and blue). Any ideas as to what could cause this? Is my sampler states setup wrong?
Here's a sampler state setup:
D3D11_SAMPLER_DESC samplerDesc;
samplerDesc.Filter = D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR;
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.MipLODBias = 0.0f;
samplerDesc.MaxAnisotropy = 1;
samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
samplerDesc.BorderColor[0] = 0;
samplerDesc.BorderColor[1] = 0;
samplerDesc.BorderColor[2] = 0;
samplerDesc.BorderColor[3] = 0;
samplerDesc.MinLOD = 0;
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
device->CreateSamplerState(&samplerDesc, &m_displacementSampler);
P.S. i do check the result to make sure I don't error, I just don't put it here to reduce code-confusion
also, here's how I'm setting my samplers / textures into their respective locations:
deviceContext->PSSetShaderResources(0, 1, &diffuseTexture);
deviceContext->PSSetShaderResources(1, 1, &normalMap);
deviceContext->PSSetShaderResources(2, 1, &specularMap);
deviceContext->DSSetShaderResources(0, 1, &displacementMap);
deviceContext->DSSetShaderResources(1, 1, &pointLightDiffuseMap);
deviceContext->DSSetShaderResources(2, 1, &pointLightPositionMap);
deviceContext->DSSetShaderResources(3, 1, &pointLightRadiusMap);
Oddly enough, none of the other code seems effected by the weirdness happening from the 1D texture sampling issue. Any ideas as to what I could be doing wrong?