Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Model got no depth?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Inukai   Members   -  Reputation: 1297

Like
0Likes
Like

Posted 21 May 2012 - 03:03 PM

Hi guys,
I'm quite new to Directx 11 and tried to load my model.
However, I got a problem with its rendering. It looks like my model got no depth(look at his hands, feet, head), even though I got a depth/stencil buffer.


Posted Image
My importer works with less complex models.

Am i missing something?
What could cause this?

I hope you guys can help me ;)

Sponsor:

#2 Hornsj3   Members   -  Reputation: 191

Like
1Likes
Like

Posted 21 May 2012 - 03:27 PM

If you post your device & swap chain creation code it would help.

Specifically, post your depth/stencil and backbuffer configuration structures and the call to create them.

It also appears to me you have some wind-ordering issue with your model. Have you tried setting the rasterizer state to not cull back/front faces?

#3 Inukai   Members   -  Reputation: 1297

Like
0Likes
Like

Posted 21 May 2012 - 03:41 PM

Ty for your answer.
This is the D3dInit code(based on Frank Lunas Dx11 Book)
bool Dx11Base::Init(HINSTANCE hInstance, HWND hwnd)
{
hInstance_ = hInstance;
hwnd_ = hwnd;
RECT dimensions;
GetClientRect(hwnd, &dimensions);
unsigned int width = dimensions.right - dimensions.left;
unsigned int height = dimensions.bottom - dimensions.top;
D3D_DRIVER_TYPE driverTypes[] =
{
   D3D_DRIVER_TYPE_HARDWARE, D3D_DRIVER_TYPE_WARP,
	    D3D_DRIVER_TYPE_SOFTWARE, D3D_DRIVER_TYPE_REFERENCE,
};
unsigned int totalDriverTypes = ARRAYSIZE(driverTypes);
D3D_FEATURE_LEVEL featureLevels[] =
{
  D3D_FEATURE_LEVEL_11_0,
  D3D_FEATURE_LEVEL_10_1,
  D3D_FEATURE_LEVEL_10_0
};
unsigned int totalFeatureLevels = ARRAYSIZE(featureLevels);
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Width = width;
swapChainDesc.BufferDesc.Height = height;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.OutputWindow = hwnd;
swapChainDesc.Windowed = true;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
unsigned int creationFlags = 0;
#ifdef _DEBUG
creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
HRESULT result;
unsigned int driver = 0;
for(driver = 0; driver < totalDriverTypes; ++driver)
{
  result = D3D11CreateDeviceAndSwapChain(0, driverTypes[driver], 0,
   creationFlags, featureLevels, totalFeatureLevels,
   D3D11_SDK_VERSION, &swapChainDesc, &swapChain_,
   &d3dDevice_, &featureLevel_, &d3dContext_);
 
  if(SUCCEEDED(result))
  {
   driverType_=driverTypes[driver];
   break;
  }
}
if(FAILED(result))
{
  DXTRACE_MSG("Failes to create the Direct3D device!");
  return false;
}
ID3D11Texture2D* backBufferTexture;
result = swapChain_->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferTexture);
if(FAILED(result))
{
  DXTRACE_MSG("Failed to get  the swap chain back buffer!");
  return false;
}
result = d3dDevice_->CreateRenderTargetView(backBufferTexture, 0, &backBufferTarget_);
if(backBufferTexture)
  backBufferTexture->Release();
if(FAILED(result))
{
  DXTRACE_MSG("Failed to create the renderTargetView!");
  return false;
}
D3D11_TEXTURE2D_DESC depthTexDesc;
ZeroMemory(&depthTexDesc, sizeof(depthTexDesc));
depthTexDesc.Width = width;
depthTexDesc.Height = height;
depthTexDesc.MipLevels = 1;
depthTexDesc.ArraySize = 1;
depthTexDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthTexDesc.SampleDesc.Count = 1;
depthTexDesc.SampleDesc.Quality = 0;
depthTexDesc.Usage = D3D11_USAGE_DEFAULT;
depthTexDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
depthTexDesc.CPUAccessFlags = 0;
depthTexDesc.MiscFlags = 0;
result = d3dDevice_->CreateTexture2D(&depthTexDesc, NULL, &depthTexture_);
if(FAILED(result))
{
  DXTRACE_MSG("Failed to create the depth texture!");
  return false;
}
//depth stencil view
D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
ZeroMemory(&descDSV, sizeof(descDSV));
descDSV.Format = depthTexDesc.Format;
descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
descDSV.Texture2D.MipSlice = 0;
result = d3dDevice_->CreateDepthStencilView(depthTexture_, &descDSV, &depthStencilView_);
if(FAILED(result))
{
  DXTRACE_MSG("Failed to create the depth stencil target view!");
  return false;
}

d3dContext_->OMSetRenderTargets(1, &backBufferTarget_, 0);
D3D11_VIEWPORT viewport;
viewport.Width = static_cast<float>(width);
viewport.Height = static_cast<float>(height);
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
viewport.TopLeftX = 0.0f;
viewport.TopLeftY = 0.0f;
d3dContext_->RSSetViewports(1, &viewport);
return LoadContent();
}

And here is my Draw Method:
void Modeldemo::Render()
{
if( d3dContext_ == 0 )
	    return;
    float clearColor[4] = { 0.0f, 0.0f, 0.25f, 1.0f };
    d3dContext_->ClearRenderTargetView( backBufferTarget_, clearColor );
    d3dContext_->ClearDepthStencilView( depthStencilView_, D3D11_CLEAR_DEPTH, 1.0f, 0 );

    unsigned int stride = sizeof( VertexPos );
    unsigned int offset = 0;
    d3dContext_->IASetInputLayout( inputLayout_ );
    d3dContext_->IASetVertexBuffers( 0, 1, &vertexBuffer_, &stride, &offset );
    d3dContext_->IASetIndexBuffer( indexBuffer_, DXGI_FORMAT_R16_UINT, 0 );
    d3dContext_->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
d3dContext_->VSSetShader( colorMapVS_, 0, 0 );
    d3dContext_->PSSetShader( colorMapPS_, 0, 0 );
    d3dContext_->PSSetShaderResources( 0, 1, &colorMap_ );
    d3dContext_->PSSetSamplers( 0, 1, &colorMapSampler_ );
    XMMATRIX worldMat = XMMatrixIdentity( );
    worldMat = XMMatrixTranspose( worldMat );
    XMMATRIX viewMat = cam_.GetViewMatrix( );
    viewMat = XMMatrixTranspose( viewMat );
    d3dContext_->UpdateSubresource( worldCB_, 0, 0, &worldMat, 0, 0 );
    d3dContext_->UpdateSubresource( viewCB_, 0, 0, &viewMat, 0, 0 );
    d3dContext_->UpdateSubresource( projCB_, 0, 0, &projMatrix_, 0, 0 );
    d3dContext_->VSSetConstantBuffers( 0, 1, &worldCB_ );
    d3dContext_->VSSetConstantBuffers( 1, 1, &viewCB_ );
    d3dContext_->VSSetConstantBuffers( 2, 1, &projCB_ );
    int size = model->indicesCount;
d3dContext_->Draw( size, 0);
    swapChain_->Present( 0, 0 );
}

It also appears to me you have some wind-ordering issue with your model. Have you tried setting the rasterizer state to not cull back/front faces?


Yes, but no changes to the model.

#4 kubera   Members   -  Reputation: 946

Like
1Likes
Like

Posted 21 May 2012 - 10:40 PM

Maybe the issue is with your shaders, an inccorect matrices transformation.
It would be a Direct3D version's independent problem.

#5 Inukai   Members   -  Reputation: 1297

Like
0Likes
Like

Posted 21 May 2012 - 11:52 PM

Here is my ShaderCode
Texture2D colorMap_ : register( t0 );
SamplerState colorSampler_ : register( s0 );

cbuffer cbChangesEveryFrame : register( b0 )
{
    matrix worldMatrix;
};
cbuffer cbNeverChanges : register( b1 )
{
    matrix viewMatrix;
};
cbuffer cbChangeOnResize : register( b2 )
{
    matrix projMatrix;
};

struct VS_Input
{
    float4 pos  : POSITION;
    float2 tex0 : TEXCOORD0;
};
struct PS_Input
{
    float4 pos  : SV_POSITION;
    float2 tex0 : TEXCOORD0;
};

PS_Input VS_Main( VS_Input vertex )
{
    PS_Input vsOut = ( PS_Input )0;
    vsOut.pos = mul( vertex.pos, worldMatrix );
    vsOut.pos = mul( vsOut.pos, viewMatrix );
    vsOut.pos = mul( vsOut.pos, projMatrix );
    vsOut.tex0 = vertex.tex0;
    return vsOut;
}

float4 PS_Main( PS_Input frag ) : SV_TARGET
{
    return colorMap_.Sample( colorSampler_, frag.tex0 );
}


#6 Tom KQT   Members   -  Reputation: 1612

Like
1Likes
Like

Posted 22 May 2012 - 12:33 AM

Can you also show how do you create your projection matrix?

#7 Inukai   Members   -  Reputation: 1297

Like
0Likes
Like

Posted 22 May 2012 - 12:48 AM

sure.
projMatrix_ = XMMatrixPerspectiveFovLH(XM_PIDIV4, 800.0f / 600.0f, 0.01f, 1000.0f);
projMatrix_ = XMMatrixTranspose(projMatrix_);


#8 kauna   Crossbones+   -  Reputation: 2747

Like
1Likes
Like

Posted 22 May 2012 - 01:11 AM

Seems that you pass NULL as 3rd parameter to the OMSetRenderTargets method.


void OMSetRenderTargets(
[in] UINT NumViews,
[in] ID3D11RenderTargetView *const **ppRenderTargetViews,
[in] ID3D11DepthStencilView *pDepthStencilView
);

3rd parameter should be your DepthStencilView.

Cheers!

#9 Inukai   Members   -  Reputation: 1297

Like
0Likes
Like

Posted 22 May 2012 - 01:19 AM

THX! it works.

I feel so stupid now >.<




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS