Jump to content

  • Log In with Google      Sign In   
  • Create Account


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.
		swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
		swapChainDesc.BufferDesc.RefreshRate.Denominator = denominator;
		swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
		swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;

	// Set the usage of the back buffer.

	// 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);
		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:

	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;
	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.

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{
	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);
void LLTEST::Append(int val){
	if (last==NULL){//it's the first one
		start=new LINKLIST(val,NULL);
		LINKLIST *tmp=new LINKLIST(val,last);
void LLTEST::LLDestroy(void){

first test with Linked List:

	__int64 ct=GE->Timer.TotalTime;

	for (int q=0;q<100000;q++){

tp1 gives me roughly 26500 in total time.


Now for the std::vector:

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


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.......