I've been trying to get a simple texture mapped onto a cube and although based on my reading material it seems like I'm doing everything right, I'm obviously missing something.
First I'm creating a Shader resource view to the image file. Then I'm getting a handle to the texture variable in the shader. Followed by setting that shader value to the resource view.
HRESULT _hr = D3DX10CreateShaderResourceViewFromFile(device, TEXT("CubeFace.png"), NULL, NULL, &fxDiffuseMapRV, NULL);if (FAILED(_hr)) FatalError(_hr, TEXT("Failed to create diffuse map view for ground tile."));fxDiffuseMapV = fx->GetVariableByName("diffuseMap")->AsShaderResource();fxDiffuseMapV->SetResource(fxDiffuseMapRV);
Here is my simple shader. All the relevant buffer data is set, including an identity matrix for the texture matrix.
Texture2D diffuseMap;cbuffer cbPerObject{ float4x4 wvpM; float4x4 worldM; float4x4 texM;};struct VS_IN{ float3 posL : POSITION; float2 texC : TEXCOORD;};struct VS_OUT{ float4 posH : SV_POSITION; float2 texC : TEXCOORD;};SamplerState Sampler{ Filter = MIN_MAG_MIP_LINEAR;};VS_OUT VS(VS_IN vIn){ VS_OUT vOut; vOut.posH = mul(float4(vIn.posL, 1.0f), wvpM); vOut.texC = mul(float4(vIn.texC, 0.0f, 1.0f), texM); return vOut;}float4 PS(VS_OUT pIn) : SV_Target{ float4 diffuse = diffuseMap.Sample(Sampler, pIn.texC); return diffuse;}technique10 Render{ pass P0 { SetVertexShader( CompileShader( vs_4_0, VS() ) ); SetGeometryShader( NULL ); SetPixelShader( CompileShader( ps_4_0, PS() ) ); }}
And just in case it is causing the problem (however, I'm fairly sure it isn't) my vertex data.
vertices[0].position = D3DXVECTOR3(-2.0f, -4.0, -2.0f); vertices[1].position = D3DXVECTOR3( 2.0f, -4.0, -2.0f); vertices[2].position = D3DXVECTOR3(-2.0f, -6.0, -2.0f); vertices[3].position = D3DXVECTOR3( 2.0f, -6.0, -2.0f); vertices[4].position = D3DXVECTOR3(-2.0f, -4.0, 2.0f); vertices[5].position = D3DXVECTOR3( 2.0f, -4.0, 2.0f); vertices[6].position = D3DXVECTOR3(-2.0f, -6.0, 2.0f); vertices[7].position = D3DXVECTOR3( 2.0f, -6.0, 2.0f); vertices[0].textureCoordinate = D3DXVECTOR2(0.0f, 1.0f); vertices[1].textureCoordinate = D3DXVECTOR2(1.0f, 1.0f); vertices[2].textureCoordinate = D3DXVECTOR2(1.0f, 1.0f); vertices[3].textureCoordinate = D3DXVECTOR2(0.0f, 1.0f); vertices[4].textureCoordinate = D3DXVECTOR2(0.0f, 0.0f); vertices[5].textureCoordinate = D3DXVECTOR2(1.0f, 0.0f); vertices[6].textureCoordinate = D3DXVECTOR2(1.0f, 0.0f); vertices[7].textureCoordinate = D3DXVECTOR2(0.0f, 0.0f);
(I'm using an index buffer and I'm aware that only the top and bottom might not look screwy. It's going to be a floor tile.)
I've have no problem drawing a white cube when I override the returned color in the shader but when I don't, it's solid black.
My debug output reads "The Pixel Shader unit expects a Shader Resource View at Slot 0, but none is bound." so is my shader resource view just not getting set for somereason?
Thanks!