Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Migi0027

Member Since 02 Jul 2012
Offline Last Active Today, 06:47 AM

Posts I've Made

In Topic: directx 11 texture object Help

15 December 2014 - 08:08 AM

Buckeye Is right, its a really good skill to be able to follow the data as he suggests!

 

When running it on my pc, the shaders compile fine, however this does fail:

//set up the description of the dynamic constant buffer that is in the vertex shader
	matrixBufferDesc.Usage = D3D11_USAGE_DEFAULT;
	matrixBufferDesc.ByteWidth = sizeof(MatrixBufferType);
	matrixBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	matrixBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	matrixBufferDesc.MiscFlags = 0;
	matrixBufferDesc.StructureByteStride = 0;

	//create the constant buffer pointer so we can acess the vertex shader constant buffer from within this class
	result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer);
	if (FAILED(result))
	{
		return false;
	}

 
Error message:

D3D11 ERROR: ID3D11Device::CreateBuffer: A D3D11_USAGE_DEFAULT Resource cannot have any CPUAccessFlags set. The flags are currently set to: D3D11_CPU_ACCESS_READ (0), D3D11_CPU_ACCESS_WRITE (1). [ STATE_CREATION ERROR #63: CREATEBUFFER_INVALIDCPUACCESSFLAGS]

 
And actually from his tutorial rastertek writes it like this, if Im looking at the same:

// Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
matrixBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
matrixBufferDesc.ByteWidth = sizeof(MatrixBufferType);
matrixBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
matrixBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
matrixBufferDesc.MiscFlags = 0;
matrixBufferDesc.StructureByteStride = 0;

// Create the constant buffer pointer so we can access the vertex shader constant buffer from within this class.
result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer);
if(FAILED(result))
{
	return false;
}

 
Notice how rastertek sets .Usage to D3D11_USAGE_DYNAMIC? This is what Direct3d is bugging you about. You cant allow the CPU to write (D3D11_CPU_ACCESS_WRITE) if the buffer is set to a default usage.

 

You have one more bug:

 

When you render the frame you accidentally release the texture: ( Close to the middle where m_Model->Render is called )

bool GraphicsClass::Render()
{
	D3DXMATRIX viewMatrix, projectionMatrix, worldMatrix;
	bool result;

	//clear the buffers to begin the scene
	m_D3D->BeginScene(1.0f, 0.2f,0.2f,1.0f);

	//generate the view matrix based on the cameras position
	m_Camera->Render();

	//get the world view and projection matrices from the camera and D3D objects
	m_Camera->GetViewMatrix(viewMatrix);
	m_D3D->GetWorldMatrix(worldMatrix);
	m_D3D->GetProjectionMatrix(projectionMatrix);

	//put the model vertex and index buffers on the graphics pipeline to prepare them for drawing
	m_Model->Render(m_D3D->GetDeviceContext()); <-----------

	//render the model using the texture shader
	result = m_TextureShader->Render(m_D3D->GetDeviceContext(), m_Model->GetIndexCount(),
	worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture());
	if (!result)
	{
		return false;
	}

	//present the rendered scene to the screen
	m_D3D->EndScene();
	return true;
}
void ModelClass::Render(ID3D11DeviceContext* deviceContext)
{
	//release the model texture
	ReleaseTexture(); <--------

	//put the vertex and index buffers on the graphics pipeline to prepare them for drawing
	RenderBuffers(deviceContext);

}

I'm not sure why, but its probably just a copy paste error or something similar.

 

With those things fixed the program runs fine in my windows: ( Interesting window name happy.png )

 

DXmDDAq.png

 

Im still not sure about the shader error, it might be encoding as everyone else is saying.

 

EDIT: Another error: 

D3D11 WARNING: ID3D11DeviceContext::DrawIndexed: The Pixel Shader unit expects a Sampler to be set at Slot 0, but none is bound. This is perfectly valid, as a NULL Sampler maps to default Sampler state. However, the developer may not want to rely on the defaults.  [ EXECUTION WARNING #352: DEVICE_DRAW_SAMPLER_NOT_SET]

 
You create the sampler state but you never set it anywhere, so Direct3d just sets the default sampler, which might not behave as you expected. So simply set it, Example in how this could be done with your code:

bool TextureShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext,
D3DXMATRIX worldMatrix, D3DXMATRIX viewMatrix, D3DXMATRIX projectionMatrix, ID3D11ShaderResourceView* texture)
{
	... Removed code ...

	//now set the constant buffer in the vertex shader with the updated values
	deviceContext->VSSetConstantBuffers(bufferNumber, 1, &m_matrixBuffer);

	//set the shader texture resource in the pixel shader
	deviceContext->PSSetShaderResources(0, 1, &texture);

	// Set the sampler state , New Line
	deviceContext->PSSetSamplers(0, 1, &m_sampleState);

	return true;
}

EDIT: I see where you tried to set the sampler state, however you called PSGetSamplers, not PSSetSamplers:

void TextureShaderClass::RenderShader(ID3D11DeviceContext* deviceContext, int indexCount)
{
	//set the vertex input layout
	deviceContext->IASetInputLayout(m_layout);

	//set the vertex and pixel shaders that will be used to render this triangle
	deviceContext->VSSetShader(m_vertexShader, NULL, 0);
	deviceContext->PSSetShader(m_pixelShader, NULL, 0);

	//set the sampler state in the pixel shader, use Set not Get
	deviceContext->PSGetSamplers(0, 1, &m_sampleState);

	//render the triangle
	deviceContext->DrawIndexed(indexCount, 0, 0);

}

Another Edit about the encoding:

 

Looking at the shader files, they dont seem to be compiled in ANSI, instead in UTF-8, Im not sure if this is a problem, however better safe than sorry. ( Using Notepad++, I really recommend it )

 

BxQCapd.png

 

Now Direct3d doesnt complain anymore, happy coding!


In Topic: Limit Theory update #21

15 December 2014 - 07:53 AM

Ahh, I meant he! I wasnt aware that he wrote the music himself though, pretty impressive!


In Topic: Limit Theory update #21

14 December 2014 - 02:57 AM

Its pretty amazing what they've been doing throughout the years, and also the amount of quality that they put into each single detail.

 

Thanks for showing the update, havnt been following for a short while.


In Topic: Physical Based Models

11 December 2014 - 12:42 AM

Alright, I see the consistency issue and why it is.

 

Thank you.


In Topic: Physical Based Models

10 December 2014 - 03:03 PM

What exactly do you mean by physical based models ?  Physical based rendering has to do with lighting models and material properties and is a separate from a model. I have never heard the term physical based models unless you are talking about an exact replica of a real word object which again is somewhat separate from illumination. Unless you are talking about the the model source of reflectance data ( diffuse/albedo maps, specular maps ) which approximate the BRDF of the material the artist is trying to represent..again that is a different concept from lighting since you can still have a physical based renderer without using these maps ( reflectance data will have to come from other sources ).

 

Ahh sorry, my terminology isnt that good. I meant physical based rendering. Where the model usually comes with the reflectance data.


PARTNERS