[newbie question]
Hello guys,
I'm having a problem with texturing my skybox. I'm trying to load a cube map (.dds format) on top of a box (loaded from .obj).
The picture probably will indicate more advanced users what could be possibly wrong.
My guess is that texture coords have to be fixed.
Vertex Shader
struct VertexType
{
float4 position : POSITION;
float2 texcoord : TEXCOORD0;
float3 normal : NORMAL;
};
struct SkymapVertexType //output structure for skymap vertex shader
{
float4 position : SV_POSITION;
float3 texcoord : TEXCOORD0;
};
SkymapVertexType SKYMAP_VS(VertexType input)
{
input.position.w = 1.0f;
SkymapVertexType output = (SkymapVertexType)0;
output.position = mul(input.position, world_matrix);
output.position = mul(output.position, view_matrix);
output.position = mul(output.position, projection_matrix);
output.texcoord = input.position;
return output;
}
Pixel Shader
SamplerState sample_type;
TextureCube skymap;
float4 SKYMAP_PS(SkymapVertexType input) : SV_TARGET
{
return skymap.Sample(sample_type, input.texcoord);
}
Loading Texture
D3DX11_IMAGE_LOAD_INFO load_info;
load_info.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
ID3D11Texture2D* texture{ nullptr };
HRESULT hr = D3DX11CreateTextureFromFile(device, filename, &load_info, nullptr,
(ID3D11Resource**)&texture, nullptr);
if(FAILED(hr)) return false;
D3D11_TEXTURE2D_DESC texture_desc;
texture->GetDesc(&texture_desc);
// Create Resource Shader View
D3D11_SHADER_RESOURCE_VIEW_DESC resview_desc;
resview_desc.Format = texture_desc.Format;
resview_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
resview_desc.TextureCube.MipLevels = texture_desc.MipLevels;
resview_desc.TextureCube.MostDetailedMip = 0;
hr = device->CreateShaderResourceView(texture, &resview_desc, &m_texture);
Thanks.