Renderdoc can see my model but...

Started by
1 comment, last by mellinoe 5 years, 7 months ago

Ok so I had some code using the old DXSDK. I went to windows 10 and updated my code. I also made some changes to where i stored the vector that holds the vertex positions but thats pretty much it. Now my model is not showing up. So I ran renderdoc. Now renderdoc can see my vertices and indices and the finished mesh when I click the draw call...see the attached image. When I run from vs2017 i cant see anything except the background color. I thought it was because of where my camera was positioned so I changed that and I still can't see anything. The camera is sitting slightly back from the origin....shouldn't the model be there? That's where it was before I made the changes to the source to update it for windows 10. I made the model file and made no changes to it ever since it worked before.

 

Here is the source code and shader:


#include "Source.h"
#include "DDSTextureLoader.h"

//Global Declarations - Interfaces//
IDXGISwapChain* SwapChain;
ID3D11Device* d3d11Device;
ID3D11DeviceContext* d3d11DevCon;
ID3D11RenderTargetView* renderTargetView;
ID3D11DepthStencilView* depthStencilView;
ID3D11Texture2D* depthStencilBuffer;
ID3D11Resource* tex;
ID3D11RasterizerState * rasterState;
ID3D11VertexShader* VS;
ID3D11PixelShader* PS;
ID3DBlob* VS_Blob;
ID3DBlob* PS_Blob;
ID3D11InputLayout* vertLayout;
ID3D11Buffer* fbx_vertex_buf;
ID3D11Buffer* fbx_index_buf;
ID3D11Buffer* cbPerObjectBuffer;
ID3D11ShaderResourceView* fbx_rc_view;
ID3D11SamplerState* fbx_sampler_state;
ID3D11ShaderResourceView* normal_rc_view;

std::vector<MeshData> meshList;
myConsole* con;
//Global Declarations - Others//
HWND hwnd = NULL;
HRESULT hr;

int Width = 300;
int Height = 300;


DirectX::XMMATRIX WVP;
///////////////**************new**************////////////////////
DirectX::XMMATRIX mesh_world;
///////////////**************new**************////////////////////
DirectX::XMMATRIX camView;
DirectX::XMMATRIX camProjection;

DirectX::XMVECTOR camPosition;
DirectX::XMVECTOR camTarget;
DirectX::XMVECTOR camUp;

///////////////**************new**************////////////////////
DirectX::XMMATRIX Rotation;
DirectX::XMMATRIX Scale;
DirectX::XMMATRIX Translation;
float rot = 0.01f;
///////////////**************new**************////////////////////

//Create effects constant buffer's structure//
struct cbPerObject
{
	DirectX::XMMATRIX WVP;
};

cbPerObject cbPerObj;



D3D11_INPUT_ELEMENT_DESC layout[] =
{
	{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	{ "NORMAL",     0, DXGI_FORMAT_R32G32B32_FLOAT,    0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	{ "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT,    0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	{ "BITANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT,    0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }
};

UINT numElements = ARRAYSIZE(layout);

// Event table for MyFrame
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
EVT_CLOSE(MyFrame::OnClose)
wxEND_EVENT_TABLE()

// Implements MyApp& GetApp()
DECLARE_APP(MyApp)
// Give wxWidgets the means to create a MyApp object
IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
	// Create the main application window
	MyFrame *frame = new MyFrame(wxT("Worgen Engine Version 0"));
	// Show it
	frame->Show(true);
	return true;
}

void MyFrame::OnQuit(wxCommandEvent& event)
{
	// Destroy the frame
	Close();
}

void MyFrame::OnClose(wxCloseEvent& event)
{
	timer->Stop();

	//Release the COM Objects we created
	SwapChain->Release();
	d3d11Device->Release();
	d3d11DevCon->Release();
	renderTargetView->Release();
	event.Skip();
}


MyFrame::MyFrame(const wxString& title)
	: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition)
{
	// Create a menu bar
	wxMenu *fileMenu = new wxMenu;
	// The “About” item should be in the help menu
	wxMenu *helpMenu = new wxMenu;
	helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"),
		wxT("ABout this program."));
	fileMenu->Append(wxID_EXIT, wxT("E&xit\tAlt - X"),
		wxT("Quit this program"));
	// Now append the freshly created menu to the menu bar...
	wxMenuBar *menuBar = new wxMenuBar();
	menuBar->Append(fileMenu, wxT("&File"));
	menuBar->Append(helpMenu, wxT("&Help"));
	// ... and attach this menu bar to the frame
	SetMenuBar(menuBar);
	// Create a status bar just for fun
	CreateStatusBar(2);
	SetStatusText(wxT("Welcome to Worgen Engine!"));

	nbHierarchy = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(200, 300));
	nbScene = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(800, 600));
	nbInspector = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(200, 300));

	timer = new RenderTimer();
	console = new myConsole(wxSize(800, 300), wxTE_MULTILINE | wxTE_READONLY, this);

	timer->dxPanel = new MyDxPanel((MyFrame*)nbScene);
	wxPanel* hierarchyWindow = new wxPanel(nbHierarchy, wxID_ANY);
	nbHierarchy->AddPage(hierarchyWindow, "Hierarchy", false);
	nbScene->AddPage(timer->dxPanel, "Game", false);
	wxPanel* inspectorWindow = new wxPanel(nbInspector, wxID_ANY);
	nbInspector->AddPage(inspectorWindow, "Inspector", false);

	wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
	sizer->Add(nbHierarchy, 0, wxEXPAND, 0);
	sizer->Add(nbScene, 1, wxEXPAND, 0);
	sizer->Add(nbInspector, 0, wxEXPAND, 0);

	wxBoxSizer* console_sizer = new wxBoxSizer(wxVERTICAL);
	console_sizer->Add(sizer, 0, wxEXPAND, 0);
	console_sizer->Add(console, 0, wxEXPAND, 0);

	SetSizerAndFit(console_sizer);

	timer->dxPanel->c = console;
	timer->dxPanel->aLoader = new LoadMesh("C:\\Models\\wally.fbx", console, meshList);

	timer->dxPanel->initDx(timer->dxPanel->GetHWND());
	timer->dxPanel->initScene();

	timer->Start();
}

MyFrame::~MyFrame()
{
	delete timer;
}

wxBEGIN_EVENT_TABLE(MyDxPanel, wxPanel)
EVT_PAINT(MyDxPanel::OnPaint)
EVT_ERASE_BACKGROUND(MyDxPanel::OnEraseBackground)
wxEND_EVENT_TABLE()

MyDxPanel::MyDxPanel(MyFrame* parent) : wxPanel(parent)
{
	parentFrame = parent;
}

MyDxPanel::~MyDxPanel()
{

}

void MyDxPanel::OnEraseBackground(wxEraseEvent &WXUNUSED(event))
{
	//empty to avoid flashing
}

void MyDxPanel::updateScene()
{
	rot += .05f;
	if (rot > 6.26f)
		rot = 0.0f;

	DirectX::XMVECTOR rotaxis = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
	Rotation = DirectX::XMMatrixRotationAxis(rotaxis, -rot);

	mesh_world = DirectX::XMMatrixIdentity();
}

void MyDxPanel::render()
{
	//Clear our backbuffer
	float bgColor[4] = {0.0f, 0.6f, 0.4f, 1.0f };
	d3d11DevCon->ClearRenderTargetView(renderTargetView, bgColor);

	//Refresh the Depth/Stencil view
	d3d11DevCon->ClearDepthStencilView(depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);

	WVP = mesh_world * camView * camProjection;
	cbPerObj.WVP = DirectX::XMMatrixTranspose(WVP);
	d3d11DevCon->UpdateSubresource(cbPerObjectBuffer, 0, NULL, &cbPerObj, 0, 0);
	d3d11DevCon->VSSetConstantBuffers(0, 1, &cbPerObjectBuffer);

	d3d11DevCon->PSSetShaderResources(0, 1, &fbx_rc_view);
	d3d11DevCon->PSSetSamplers(0, 1, &fbx_sampler_state);

	d3d11DevCon->DrawIndexed(meshList[0].indices.size(), 0, 0);

	//Present the backbuffer to the screen
	SwapChain->Present(0, 0);
}

void MyDxPanel::OnPaint(wxPaintEvent& event)
{
	wxPaintDC dc(this);

	updateScene();
	render();
}


void MyDxPanel::initDx(HWND wnd)
{
	//Describe our SwapChain Buffer
	DXGI_MODE_DESC bufferDesc;

	ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC));

	bufferDesc.Width = Width;
	bufferDesc.Height = Height;
	bufferDesc.RefreshRate.Numerator = 60;
	bufferDesc.RefreshRate.Denominator = 1;
	bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
	bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

	//Describe our SwapChain
	DXGI_SWAP_CHAIN_DESC swapChainDesc;

	ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));

	swapChainDesc.BufferDesc = bufferDesc;
	swapChainDesc.SampleDesc.Count = 1;
	swapChainDesc.SampleDesc.Quality = 0;
	swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	swapChainDesc.BufferCount = 1;
	swapChainDesc.OutputWindow = wnd;
	swapChainDesc.Windowed = TRUE;
	swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

	//Create our SwapChain
	hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL,
		D3D11_SDK_VERSION, &swapChainDesc, &SwapChain, &d3d11Device, NULL, &d3d11DevCon);

	//Create our BackBuffer
	ID3D11Texture2D* BackBuffer;
	hr = SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&BackBuffer);

	d3d11Device->CreateRenderTargetView(BackBuffer, NULL, &renderTargetView);

	//Describe our Depth/Stencil Buffer
	D3D11_TEXTURE2D_DESC depthStencilDesc;

	depthStencilDesc.Width = Width;
	depthStencilDesc.Height = Height;
	depthStencilDesc.MipLevels = 1;
	depthStencilDesc.ArraySize = 1;
	depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
	depthStencilDesc.SampleDesc.Count = 1;
	depthStencilDesc.SampleDesc.Quality = 0;
	depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
	depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
	depthStencilDesc.CPUAccessFlags = 0;
	depthStencilDesc.MiscFlags = 0;

	//Create the Depth/Stencil View
	d3d11Device->CreateTexture2D(&depthStencilDesc, NULL, &depthStencilBuffer);
	d3d11Device->CreateDepthStencilView(depthStencilBuffer, NULL, &depthStencilView);

	//Set our Render Target
	d3d11DevCon->OMSetRenderTargets(1, &renderTargetView, depthStencilView);
}

void MyDxPanel::initScene()
{
	shaders();
	generateBuffers();
	setBuffers(0);
	setInputLayoutAndTopology();
	setViewport();
	setCameraInfo();
	createConstantBuffer();
	loadModelTexture("C:\\Models\\tex.DDS");
	createSamplerState();
	setRSState();
}

void MyDxPanel::shaders()
{
	//Compile Shaders from shader file
	HR(D3DCompileFromFile(L"Effects.fx", 0, 0, "VS", "vs_5_0", 0, 0, &VS_Blob, 0));
	HR(D3DCompileFromFile(L"Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, &PS_Blob, 0));

	//Create the Shader Objects
	HR(d3d11Device->CreateVertexShader(VS_Blob->GetBufferPointer(), VS_Blob->GetBufferSize(), NULL, &VS));
	HR(d3d11Device->CreatePixelShader(PS_Blob->GetBufferPointer(), PS_Blob->GetBufferSize(), NULL, &PS));

	//Set Vertex and Pixel Shaders
	d3d11DevCon->VSSetShader(VS, 0, 0);
	d3d11DevCon->PSSetShader(PS, 0, 0);
}

void MyDxPanel::generateBuffers()
{
		D3D11_BUFFER_DESC indexBufferDesc;
		ZeroMemory(&indexBufferDesc, sizeof(indexBufferDesc));

		indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
		indexBufferDesc.ByteWidth = meshList[0].indices.size() * sizeof(DWORD);
		indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
		indexBufferDesc.CPUAccessFlags = 0;
		indexBufferDesc.MiscFlags = 0;

		D3D11_SUBRESOURCE_DATA iinitData;

		iinitData.pSysMem = &meshList[0].indices[0];
		HR(d3d11Device->CreateBuffer(&indexBufferDesc, &iinitData, &meshList[0].indexBuffer));


		D3D11_BUFFER_DESC vertexBufferDesc;
		ZeroMemory(&vertexBufferDesc, sizeof(vertexBufferDesc));

		vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
		vertexBufferDesc.ByteWidth = meshList[0].vertices.size() * sizeof(Vertex);
		vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
		vertexBufferDesc.CPUAccessFlags = 0;
		vertexBufferDesc.MiscFlags = 0;

		D3D11_SUBRESOURCE_DATA vertexBufferData;

		ZeroMemory(&vertexBufferData, sizeof(vertexBufferData));
		vertexBufferData.pSysMem = &meshList[0].vertices[0];
		HR(d3d11Device->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &meshList[0].vertexBuffer));
}

void MyDxPanel::setBuffers(int i)
{
	d3d11DevCon->IASetIndexBuffer(meshList[i].indexBuffer, DXGI_FORMAT_R32_UINT, 0);

	UINT stride = sizeof(Vertex);
	UINT offset = 0;
	d3d11DevCon->IASetVertexBuffers(0, 1, &meshList[i].vertexBuffer, &stride, &offset);
}

void MyDxPanel::setInputLayoutAndTopology()
{
	HR(d3d11Device->CreateInputLayout(layout, numElements, VS_Blob->GetBufferPointer(), VS_Blob->GetBufferSize(), &vertLayout));

	d3d11DevCon->IASetInputLayout(vertLayout);

	d3d11DevCon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
}

void MyDxPanel::setViewport()
{
	//Create the Viewport
	D3D11_VIEWPORT viewport;
	ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));

	viewport.TopLeftX = 0;
	viewport.TopLeftY = 0;
	viewport.Width = Width;
	viewport.Height = Height;
	viewport.MinDepth = 0.0f;
	viewport.MaxDepth = 1.0f;

	//Set the Viewport
	d3d11DevCon->RSSetViewports(1, &viewport);
}

void MyDxPanel::createConstantBuffer()
{
	//Create the buffer to send to the cbuffer in effect file
	D3D11_BUFFER_DESC cbbd;
	ZeroMemory(&cbbd, sizeof(D3D11_BUFFER_DESC));

	cbbd.Usage = D3D11_USAGE_DEFAULT;
	cbbd.ByteWidth = sizeof(cbPerObject);
	cbbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	cbbd.CPUAccessFlags = 0;
	cbbd.MiscFlags = 0;

	cbPerObj.WVP = DirectX::XMMatrixTranspose(mesh_world * camView * camProjection);

	D3D11_SUBRESOURCE_DATA initData;
	initData.pSysMem = &cbPerObj;

	HR(d3d11Device->CreateBuffer(&cbbd, &initData , &cbPerObjectBuffer));
}

void MyDxPanel::setCameraInfo()
{
	camPosition = DirectX::XMVectorSet(-0.5f, -0.5f, 4.0f, 0.0f);
	camTarget = DirectX::XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);
	camUp = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);

	//Set the View matrix
	camView = DirectX::XMMatrixLookAtLH(camPosition, camTarget, camUp);

	//Set the Projection matrix
	camProjection = DirectX::XMMatrixPerspectiveFovLH(0.4f*3.14f, (float)Width / Height, 1.0f, 1000.0f);
}

void MyDxPanel::loadModelTexture(std::string path)
{
	HR(DirectX::CreateDDSTextureFromFile(d3d11Device, L"C:\\Models\\tex.DDS", &tex, &fbx_rc_view));
}

void MyDxPanel::createSamplerState()
{
	D3D11_SAMPLER_DESC sampDesc;
	ZeroMemory(&sampDesc, sizeof(sampDesc));
	sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
	sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
	sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
	sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
	sampDesc.MinLOD = 0;
	sampDesc.MaxLOD = D3D11_FLOAT32_MAX;

	//Create the Sample State
	HR(d3d11Device->CreateSamplerState(&sampDesc, &fbx_sampler_state));
}

void MyDxPanel::setRSState()
{
	D3D11_RASTERIZER_DESC rasterizerState;
	rasterizerState.FillMode = D3D11_FILL_SOLID;
	rasterizerState.CullMode = D3D11_CULL_NONE;
	rasterizerState.FrontCounterClockwise = true;
	rasterizerState.DepthBias = false;
	rasterizerState.DepthBiasClamp = 0;
	rasterizerState.SlopeScaledDepthBias = 0;
	rasterizerState.DepthClipEnable = true;
	rasterizerState.ScissorEnable = true;
	rasterizerState.MultisampleEnable = false;
	rasterizerState.AntialiasedLineEnable = false;
	d3d11Device->CreateRasterizerState(&rasterizerState, &rasterState);

	d3d11DevCon->RSSetState(rasterState);
}

RenderTimer::RenderTimer() : wxTimer()
{

}

void RenderTimer::Notify()
{
	dxPanel->Refresh();
}

void RenderTimer::start()
{
	wxTimer::Start(10);
}

cbuffer cbPerObject
{
	float4x4 WVP;
};

Texture2D ObjTexture;
SamplerState ObjSamplerState;

struct VS_OUTPUT
{
	float4 Pos : SV_POSITION;
	float2 TexCoord : TEXCOORD;
};

VS_OUTPUT VS(float4 inPos : POSITION, float2 inTexCoord : TEXCOORD)
{
	VS_OUTPUT output;

	output.Pos = mul(inPos, WVP);
	output.TexCoord = inTexCoord;

	return output;
}

float4 PS(VS_OUTPUT input) : SV_TARGET
{
	return ObjTexture.Sample(ObjSamplerState, input.TexCoord);
}

 

Untitled-2.png

Advertisement

For me, the next step is usually to rule out depth/stencil/backface issues. I'd go over to the "Texture Viewer" tab, select the color/depth output textures, and check these "Overlay" visualizations:

  • Highlight drawcall. It should show something since your mesh is visible in the VS Output window.
  • Depth test + Stencil Test (if you're using stencil). It should be green. If it's red, then you have something wrong with your depth buffer or depth test settings.
  • Backface Cull. It should be green. Red means it's being culled.

This topic is closed to new replies.

Advertisement