Jump to content

  • Log In with Google      Sign In   
  • Create Account


Hawkblood

Member Since 21 Jan 2013
Offline Last Active Yesterday, 09:31 PM
-----

Topics I've Started

DX11 HDR implementation

17 April 2014 - 02:44 PM

I want to implement HDR in my engine but I'm not sure how and documentation appears to be scarce. I think I need to use format DXGI_FORMAT_R32G32B32A32_FLOAT when creating the device and swap chain:

	// Initialize the swap chain description.
	ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));

	// Set to a single back buffer.
	swapChainDesc.BufferCount = 1;

	// Set the width and height of the back buffer.
	swapChainDesc.BufferDesc.Width = (UINT)SCREEN_WIDTH;
	swapChainDesc.BufferDesc.Height = (UINT)SCREEN_HEIGHT;

	// Set regular 32-bit surface for the back buffer.
	swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;

	// Set the refresh rate of the back buffer.
	if(m_vsync_enabled)
	{
		swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
		swapChainDesc.BufferDesc.RefreshRate.Denominator = denominator;
	}
	else
	{
		swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
		swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
	}

	// Set the usage of the back buffer.
	swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;

	// Set the handle for the window to render to.
	swapChainDesc.OutputWindow = hWnd;

	// Turn multisampling off.
	swapChainDesc.SampleDesc.Count = 1;
	swapChainDesc.SampleDesc.Quality = 0;

	// Set to full screen or windowed mode.
	swapChainDesc.Windowed = true;//*********************** will be full screen windowed

	// Set the scan line ordering and scaling to unspecified.
	swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
	swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

	// Discard the back buffer contents after presenting.
	swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

	// Don't set the advanced flags.
	swapChainDesc.Flags = 0;

	// Set the feature level to DirectX 11.
	featureLevel = D3D_FEATURE_LEVEL_11_0;

	// Create the swap chain, Direct3D device, and Direct3D device context.
	result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1, 
					       D3D11_SDK_VERSION, &swapChainDesc, &swapchain, &dev, NULL, &devcon);
	if(FAILED(result))
	{
		return false;
	}

This fails. I must have another setting wrong or I can't use that format.....


DX11 creating a texture with mips

14 April 2014 - 03:16 PM

I'm trying to create a texture with mips, but it keeps failing. I've been searching the internet for an answer, but I'm not having any luck. Here is what I have:

	D3D11_TEXTURE2D_DESC desc;
	ZeroMemory(&desc,sizeof(desc));
	desc.Width = sx;
	desc.Height = sy;
	desc.MipLevels = 1;
	desc.ArraySize = 1;
	desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	desc.SampleDesc.Count = 1;
	desc.Usage = D3D11_USAGE_DYNAMIC;
	desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
	desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	desc.MiscFlags = 0;

	ID3D11Texture2D *pTexture = NULL;
	HRESULT result=GE->dev->CreateTexture2D( &desc, NULL, &pTexture );//this works. doesn't fail
	if(FAILED(result)) tp1=12345;
	result=GE->dev->CreateShaderResourceView(pTexture,NULL,&m_texture);
	if(FAILED(result)) tp1=2;

sx and sy are defined already as 256. This works fine as long as I don't try to change the "desc.MipLevels" to anything but 1. I can't find an example of creating the texture with anything but 1 mip level......

 

Does anyone know how to do it?


Rendering a subset in DX11

11 April 2014 - 03:21 PM

How do I render only a select subset of a mesh in DX11?

I'm setting up the render like this:

void EFFECTMESH::Render(void){
	unsigned int stride;
	unsigned int offset;


	// Set vertex buffer stride and offset.
	stride = sizeof(NMVertex); 
	offset = 0;
    
	// Set the vertex buffer to active in the input assembler so it can be rendered.
	GE->devcon->IASetVertexBuffers(0, 1, &VB, &stride, &offset);

	// Set the index buffer to active in the input assembler so it can be rendered.
	GE->devcon->IASetIndexBuffer(IB, DXGI_FORMAT_R32_UINT, 0);

	// Set the type of primitive that should be rendered from this vertex buffer, in this case triangles.
	GE->devcon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
}

and then I'm calling the shader. The entire mesh renders fine, but I want to render different parts with different shaders......


Linked List vs std::vector

06 April 2014 - 08:42 AM

What is it about std::vector that makes it so much faster than a linked list? This question was asked by someone else in an earlier post but not stated quite like this and I don't think a solution/reason was actually concluded. Here is what I used to test this out:

 

The declaration:

vector <int> testingVector;
struct LLTEST{
	LLTEST(){last=start=NULL;}
	struct LINKLIST{
		LINKLIST(int v,LINKLIST*p){val=v;next=NULL;if (p!=NULL) p->next=this;}
		LINKLIST *prev,*next;
		int val;
		void Destroy(void){
			if (next!=NULL) next->Destroy();
			delete this;
		}
	};
	LINKLIST *start,*last;
	void Append(int val);
	void LLDestroy(void);
}LLtest;
void LLTEST::Append(int val){
	if (last==NULL){//it's the first one
		start=new LINKLIST(val,NULL);
		last=start;
	}
	else{
		LINKLIST *tmp=new LINKLIST(val,last);
		last=tmp;
	}
}
void LLTEST::LLDestroy(void){
	start->Destroy();
}

first test with Linked List:

	GE->Timer.Update();
	__int64 ct=GE->Timer.TotalTime;

	for (int q=0;q<100000;q++){
		LLtest.Append(q);
	}
	LLtest.LLDestroy();
	GE->Timer.Update();
	tp1=float(GE->Timer.TotalTime-ct);

tp1 gives me roughly 26500 in total time.

 

Now for the std::vector:

	GE->Timer.Update();
	__int64 ct=GE->Timer.TotalTime;
	for (int q=0;q<100000;q++){
		testingVector.push_back(q);
	}
	testingVector.clear();

	GE->Timer.Update();
	tp1=float(GE->Timer.TotalTime-ct);

tp1 gives me around 2700.... That's an order of magnitude 10 difference!!!! What in my LL is wrong enough to cause this much of a difference?

 


DX11 Hardware Voxel Terrain (your opinion)

05 April 2014 - 07:35 AM

Now that I'm learning DX11, there are a few new options open to me using hardware (video card). I've been eyeing http://http.developer.nvidia.com/GPUGems3/gpugems3_ch01.html and was wondering what experienced programmers think and know. My concerns are as follows:

-- how much control would I have during generation? What kinds of controls are there?

-- when the terrain is generated, how would I get info about the "height" of a specific location on the terrain?

-- could I implement LOD to this terrain? How?

 

Remember, I'm asking about DX11, not DX9.......


PARTNERS