Sign in to follow this  
bluepig.man

DX11 D3D11 Shader Compile error x3116 :flags parameter is invalid.

Recommended Posts

bluepig.man    424

Hi,l'm learning Direct 11 by <Introduction to 3D Game Programming with Direct 11>. 

An trouble error break out.

The Info is : error x3116:Flags parameter is invalid.This info break out when calling D3DX11CompileFromFile.

This happend may because the D3DX11CompileFromFile function's  wrong caling.l try to change the fx file and

 the code file,but the error still happend.

The file is here:

#include <windows.h>
#include <xnamath.h>
#include <cassert>
#include <d3dx11.h>
#include <dxerr.h>
#include "d3dx11Effect.h"

//---- Global Variable  ------------------------------------------------------------------------------------
	
	//Windows
	HINSTANCE				g_hinst				 = 0;
	HWND					g_hWnd				 = 0;
	LONG					g_ClientWidth		 = 800;
	LONG					g_ClientHeight		 = 600;

	//D3D
	ID3D11Device		   *g_D3dDevice			 = NULL;
	ID3D11DeviceContext	   *g_D3dDeviceContext   = NULL;
	IDXGISwapChain		   *g_SwapChain			 = NULL;
	ID3D11DepthStencilView *g_DepthStencilView   = NULL;
	ID3D11RenderTargetView *g_RenderTargetView   = NULL;
	ID3D11Texture2D        *g_DepthStencilBuffer = NULL;
	D3D11_VIEWPORT		   g_Vp;

	//Space
	XMMATRIX g_WorldViewProj;

	//Effect
	ID3DX11EffectTechnique *g_EffectTechnique	 = 0;
	ID3DX11Effect		   *g_Effect			 = 0;
	ID3D11InputLayout	   *g_InputLayout		 = 0;
	ID3D11Buffer		   *g_VertexBuffer		 = 0;
	ID3D11Buffer		   *g_IndexBuffer		 = 0;
	
	struct Vertex
	{
		XMFLOAT3 pos;
		XMFLOAT4 color;
	};


//---- Macro Define  ------------------------------------------------------------------------------------
	//HR define
	#if defined(DEBUG) | defined(_DEBUG)
	#ifndef HR
	#define HR(x)                                              \
	{                                                          \
		HRESULT hr = (x);                                      \
		if(FAILED(hr))                                         \
		{                                                      \
			DXTrace(__FILE__, (DWORD)__LINE__, hr, L#x, true); \
		}                                                      \
	}
	#endif

	#else
	#ifndef HR
	#define HR(x) (x)
	#endif
	#endif

	#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
	#define KEYUP(vk_code)   ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
	#define ReleaseCOM(x)    { if(x){ x->Release(); x = 0;} }

//----Forward Declaration------------------------------------------------------------------------------------

	LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
	void onResizeAndInit();
	void BuildInputLayout();
	void BuildBuffer();
	void BuildFx();
	void DrawScreen();
	void ReleaseAll();
	bool Init_Window();
	bool Init_DX();
	bool Init();

//----Forward Implementation---------------------------------------------------------------------------------

	int WINAPI WinMain( _In_ HINSTANCE hInstance, 
						_In_opt_ HINSTANCE hPrevInstance, 
						_In_ LPSTR lpCmdLine, 
			 			_In_ int nShowCmd )
	{
		MSG msg = {0};
		g_hinst = hInstance;

		if( !Init() )
		{
			return FALSE;
		}

		while(msg.message != WM_QUIT)
		{
			// If there are Window messages then process them.
			if(PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
			{
				TranslateMessage( &msg );
				DispatchMessage( &msg );
			}
			// Otherwise, do animation/game stuff.	
			else
			{
				if( KEYDOWN(VK_ESCAPE) )
				{
					SendMessage(g_hWnd,WM_CLOSE,0,0);
					break;
				}
				DrawScreen();
			}
		}

		return (msg.wParam);
	}

	bool Init_Window( )
	{
		WNDCLASS wc;
		wc.style = CS_HREDRAW | CS_VREDRAW;
		wc.lpfnWndProc = WndProc;
		wc.cbClsExtra = 0;
		wc.cbWndExtra = 0;
		wc.hInstance = g_hinst;
		wc.hIcon = LoadIcon(0, IDI_APPLICATION);
		wc.hCursor = LoadCursor(0,IDC_ARROW);
		wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
		wc.lpszMenuName = 0;
		wc.lpszClassName = L"D3DWndClassName";

		if( !RegisterClass(&wc) )
		{
			MessageBox( 0, L"ResiterClass Failed.", 0, 0 );
			return false;
		}

		RECT R = { 0, 0, g_ClientWidth, g_ClientHeight };
		AdjustWindowRect( &R, WS_OVERLAPPEDWINDOW, false );

		int width = R.right - R.left;
		int height = R.bottom - R.top;

		g_hWnd = CreateWindow( L"D3DWndClassName", L"createMyWindow", WS_OVERLAPPEDWINDOW, 
								  CW_USEDEFAULT, CW_USEDEFAULT, width, height, 
								  0, 0, g_hinst, 0);

		if( !g_hWnd )
		{
			MessageBox( 0, L"CreateWindow Failed! beijule", 0, 0 );
			return false;
		}

		ShowWindow( g_hWnd, SW_SHOW );
		UpdateWindow( g_hWnd );

		return true;
	}

	bool Init()
	{
		if( !Init_Window() )
		{
			return false;
		}
		if( !Init_DX() )
		{
			return false;
		}

		memset(&g_Vp, 0, sizeof(D3D11_VIEWPORT));
		g_WorldViewProj = XMMatrixIdentity();

		BuildFx();
		BuildBuffer();
		BuildInputLayout();
		return true;
	}

	bool Init_DX()
	{
		HRESULT hr;

		D3D_FEATURE_LEVEL FeatureLevelUsed;		
		HR( D3D11CreateDevice( 0, D3D_DRIVER_TYPE_HARDWARE, 0,
								D3D11_CREATE_DEVICE_DEBUG, 0,
								0, D3D11_SDK_VERSION,
								&g_D3dDevice, &FeatureLevelUsed ,&g_D3dDeviceContext));

		if( FeatureLevelUsed != D3D_FEATURE_LEVEL_11_0 )
		{
			MessageBox( NULL, L"Unsupport d3d11", NULL, NULL );
			return false;
		}

		//Now,prepare for create swapchain
		DXGI_SWAP_CHAIN_DESC sd;
		sd.BufferCount = 1;
		sd.BufferDesc.Height = g_ClientHeight;
		sd.BufferDesc.Width  = g_ClientWidth;
		sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
		sd.BufferDesc.RefreshRate.Numerator = 60;
		sd.BufferDesc.RefreshRate.Denominator = 1;
		sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
		sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
		sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
		sd.OutputWindow = g_hWnd;
		sd.Windowed = true;
		sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
		sd.SampleDesc.Count = 1;
		sd.SampleDesc.Quality = 0;
		sd.Flags = 0;

		IDXGIDevice *dxgiDevice = 0;
		hr = g_D3dDevice->QueryInterface( __uuidof( IDXGIDevice ), (void **)&dxgiDevice );
		if( FAILED(hr) )
		{
			MessageBox( NULL, L"Retrive DXGIDEVICE failed  ", NULL, NULL );
			return false;
		}

		IDXGIAdapter *dxgiAdapter = 0;
		hr = dxgiDevice->GetParent( __uuidof( IDXGIAdapter ), (void **)&dxgiAdapter );
		if( FAILED(hr) )
		{
			MessageBox( NULL, L"Retrive DXGIADAPTER failed  ", NULL, NULL );
			return false;
		}

		IDXGIFactory *dxgiFactory = 0;
		hr = dxgiAdapter->GetParent( __uuidof( IDXGIFactory ), (void **)&dxgiFactory );
		if( FAILED(hr) )
		{
			MessageBox( NULL, L"Retrive DXGIFACTORY failed  ", NULL, NULL );
			return false;
		}

		//Now it's the time to create swapchain
		hr = dxgiFactory->CreateSwapChain( g_D3dDevice, &sd, &g_SwapChain );
		dxgiFactory->MakeWindowAssociation( g_hWnd, DXGI_MWA_NO_WINDOW_CHANGES | DXGI_MWA_NO_PRINT_SCREEN);
		if( FAILED(hr) )
		{
			MessageBox( NULL, L"Create SwapChain failed  ", NULL, NULL );
			return false;
		}

		//After Create SwapChain,we should release our acquired COM interfaces
		ReleaseCOM( dxgiDevice );
		ReleaseCOM( dxgiAdapter );
		ReleaseCOM( dxgiFactory );

		onResizeAndInit();
	}

	void onResizeAndInit()
	{
		assert( g_D3dDeviceContext );
		assert( g_D3dDevice ); 
		assert( g_SwapChain );

		ReleaseCOM(g_RenderTargetView);
		ReleaseCOM(g_DepthStencilView);
		ReleaseCOM(g_DepthStencilBuffer);

		HR( g_SwapChain->ResizeBuffers( 1, g_ClientWidth, g_ClientHeight, DXGI_FORMAT_R8G8B8A8_UNORM, 0) );
		ID3D11Texture2D *backBuffer = 0;
		HR( g_SwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), reinterpret_cast<void **>(&backBuffer) )) ;
		HR( g_D3dDevice->CreateRenderTargetView( backBuffer, 0, &g_RenderTargetView ) );
		ReleaseCOM(backBuffer);

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

		HR( g_D3dDevice->CreateTexture2D( &DepthStencilDesc, 0, &g_DepthStencilBuffer) );
		HR( g_D3dDevice->CreateDepthStencilView( g_DepthStencilBuffer, 0, &g_DepthStencilView ) );
		g_D3dDeviceContext->OMSetRenderTargets( 1, &g_RenderTargetView, g_DepthStencilView );

		g_Vp.TopLeftX = 0;
		g_Vp.TopLeftY = 0;
		g_Vp.Width	= static_cast<float>(g_ClientWidth);
		g_Vp.Height	= static_cast<float>(g_ClientHeight);
		g_Vp.MinDepth = 0;
		g_Vp.MaxDepth = 1.0f;

		g_D3dDeviceContext->RSSetViewports( 1, &g_Vp );
	}

	void ReleaseAll()
	{
		ReleaseCOM(g_RenderTargetView);
		ReleaseCOM(g_DepthStencilView);
		ReleaseCOM(g_InputLayout);
		ReleaseCOM(g_SwapChain);

		if( g_D3dDeviceContext )
		{
			g_D3dDeviceContext->ClearState();
		}
		ReleaseCOM( g_VertexBuffer );
		ReleaseCOM( g_IndexBuffer );
		ReleaseCOM( g_InputLayout );
		ReleaseCOM( g_Effect );
		ReleaseCOM(g_D3dDevice);
		ReleaseCOM(g_D3dDeviceContext);
	}

	void DrawScreen()
	{
		assert( g_D3dDeviceContext );
		assert( g_SwapChain );

		ID3DX11EffectMatrixVariable *fxWorldViewProj;
		fxWorldViewProj = g_Effect->GetVariableByName("gWorldViewProj")->AsMatrix();
		fxWorldViewProj->SetMatrix( (float *)&g_WorldViewProj );

		D3DX11_TECHNIQUE_DESC techDesc;
		g_EffectTechnique->GetDesc( &techDesc );
		g_EffectTechnique->GetPassByIndex(0)->Apply( 0, g_D3dDeviceContext );

		UINT stride = sizeof(Vertex);
		g_D3dDeviceContext->IASetInputLayout( g_InputLayout );
		g_D3dDeviceContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
		g_D3dDeviceContext->IASetVertexBuffers( 0, 1, &g_VertexBuffer, &stride,  0 );
		g_D3dDeviceContext->IASetIndexBuffer( g_IndexBuffer, DXGI_FORMAT_R32_UINT, 0);

		XMVECTORF32 color = { 0.0f, 0.0f, 1.0f, 1.0f };
		g_D3dDeviceContext->ClearRenderTargetView( g_RenderTargetView, reinterpret_cast<const float*>(&color) );
		g_D3dDeviceContext->ClearDepthStencilView( g_DepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0.0f );
		g_D3dDeviceContext->DrawIndexed( 36, 0, 0 );

		HR(g_SwapChain->Present(0,0));
	}
	
	void BuildFx()
	{
		DWORD shaderFlag;
		#if  defined(DEBUG) || defined(_DEBUG)
		shaderFlag |= D3D10_SHADER_DEBUG;
		shaderFlag |= D3D10_SHADER_SKIP_OPTIMIZATION;
		#endif

		ID3D10Blob *CompiledShader;
		ID3D10Blob *CompiledError;

		 HR ( D3DX11CompileFromFile( L"FX/boxShader.fx", 0, 0, 0, "fx_5_0",
			shaderFlag, 0, 0, &CompiledShader, &CompiledError, 0 ) );

		if( CompiledError )
		{
			MessageBoxA( 0, (char *)CompiledError->GetBufferPointer(), 0, 0 );
			ReleaseCOM( CompiledError );
		}

		HR( D3DX11CreateEffectFromMemory( CompiledShader->GetBufferPointer(), CompiledShader->GetBufferSize(),
			0, g_D3dDevice, &g_Effect ) );

		ReleaseCOM(CompiledShader);		
	}

	void BuildBuffer()
	{
		Vertex BoxVertex[] = {
			{ XMFLOAT3(-0.5f,  0.5f, -0.5f), XMFLOAT4(1.0f, 0.0f, 0.0f, 0.0f) },
			{ XMFLOAT3( 0.5f,  0.5f, -0.5f), XMFLOAT4(0.0f, 1.0f, 0.0f, 0.0f) },
			{ XMFLOAT3(-0.5f, -0.5f, -0.5f), XMFLOAT4(0.0f, 0.0f, 1.0f, 0.0f) },
			{ XMFLOAT3( 0.5f, -0.5f, -0.5f), XMFLOAT4(1.0f, 1.0f, 0.0f, 0.0f) },
			{ XMFLOAT3(-0.5f,  0.5f,  0.5f), XMFLOAT4(1.0f, 0.0f, 1.0f, 0.0f) },
			{ XMFLOAT3( 0.5f,  0.5f,  0.5f), XMFLOAT4(0.0f, 1.0f, 1.0f, 0.0f) },
			{ XMFLOAT3(-0.5f, -0.5f,  0.5f), XMFLOAT4(1.0f, 1.0f, 1.0f, 0.0f) },
			{ XMFLOAT3( 0.5f, -0.5f,  0.5f), XMFLOAT4(0.5f, 0.5f, 0.5f, 0.0f) },
		};

		D3D11_BUFFER_DESC vDesc;
		//memset( &vDesc, 0, sizeof(D3D11_BUFFER_DESC) );
		vDesc.ByteWidth		 = sizeof(Vertex) * 8;
		vDesc.Usage			 = D3D11_USAGE_IMMUTABLE;
		vDesc.BindFlags		 = D3D11_BIND_VERTEX_BUFFER;
		vDesc.CPUAccessFlags = 0;
		vDesc.MiscFlags		 = 0;
		vDesc.StructureByteStride = 0;
		D3D11_SUBRESOURCE_DATA vInitData;
		vInitData.pSysMem	 = BoxVertex;
		HR( g_D3dDevice->CreateBuffer( &vDesc, &vInitData, &g_VertexBuffer) );

		UINT indices[] =
		{
			//FRONT
			0, 1, 2,
			2, 1, 3,

			//TOP
			0, 4, 5,
			0, 5, 1,

			//RIGHT
			1, 5, 3,
			3, 5, 7,

			//BACK
			4, 6, 5,
			5, 6, 7,

			//BOTTOM
			2, 7, 1,
			2, 3, 7,

			//LEFT
			0, 2, 4,
			2, 6, 4
		};

		D3D11_BUFFER_DESC bDesc;
		//memset( &bDesc, 0, sizeof( bDesc ) );
		bDesc.ByteWidth		= sizeof( UINT ) * 36;
		bDesc.Usage			= D3D11_USAGE_IMMUTABLE;
		bDesc.BindFlags		= D3D11_BIND_INDEX_BUFFER;
		bDesc.CPUAccessFlags = 0;
		bDesc.MiscFlags		= 0;
		bDesc.StructureByteStride = 0;
		D3D11_SUBRESOURCE_DATA iInitDate;
		iInitDate.pSysMem = indices;
		HR( g_D3dDevice->CreateBuffer( &bDesc, &iInitDate, &g_IndexBuffer ) );
	}
	
	void BuildInputLayout()
	{
		D3D11_INPUT_ELEMENT_DESC idesc[] = 
		{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }
		};
		UINT numElements = ARRAYSIZE( idesc );

		g_EffectTechnique = g_Effect->GetTechniqueByName( "ColorTech" );
		D3DX11_PASS_DESC passDesc;
		g_EffectTechnique->GetPassByName("p0")->GetDesc(&passDesc);
		
		HR( g_D3dDevice->CreateInputLayout( idesc, numElements, passDesc.pIAInputSignature ,
					passDesc.IAInputSignatureSize, &g_InputLayout) );
	}

	LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
	{
		switch( msg )
		{
		case WM_SIZE:
			g_ClientWidth  = LOWORD( lParam );
			g_ClientHeight = HIWORD( lParam );

			if( g_D3dDevice )
			{
				if( wParam != SIZE_MINIMIZED )
				{
					onResizeAndInit();
				}
			}
			return 0;

		case WM_DESTROY:
			ReleaseAll();
			PostQuitMessage(0);
			return 0;

		default: 
			break;
		}
		return DefWindowProc(hWnd, msg, wParam, lParam); 
	}

you may need the BoxShader.fx file:

//
//		Effect for boxdemo
//

cbuffer cbPerObject
{
	float4x4 gWorldViewProj;
};

struct VertexIn
{
	float3 PosL : POSITION;
	float4 color : COLOR;
};

struct VertexOut
{
	float4 PosH : SV_POSITION;
	float4 color : COLOR;
};

VertexOut VS( VertexIn vin )
{
	VertexOut vout;
	vout.PosH = mul( float4( vin.PosL, 1.0f ), gWorldViewProj );
	
	vout.color = vin.color;
	
	return vout;
}

float4 PS( VertexOut pin ) : SV_Target
{
	return pin.color;
}

technique11 ColorTech
{
	pass p0
	{
		SetVertexShader( CompileShader( vs_5_0, VS() ) );
		SetGeometryShader( NULL );
		SetPixelShader( CompileShader( ps_5_0, PS() ) );
	}
}

Thanks for your help.

Edited by bluepig.man

Share this post


Link to post
Share on other sites
Capoeirista    3266

Have you tried setting the shader flags to 0?

 

Also (I'm not sure if it matters) but you might want to try using "ps_5_0" instead of "fx_5_0" since that's how it's set up in the shader technique.

Share this post


Link to post
Share on other sites
bluepig.man    424

Have you tried setting the shader flags to 0?

 

Also (I'm not sure if it matters) but you might want to try using "ps_5_0" instead of "fx_5_0" since that's how it's set up in the shader technique.

 

You are right,the shader flag should set to 0.sad.png

it's so stupid mistake......

l should more careful about this mistake,thanks for your help,guys.smile.png

Share this post


Link to post
Share on other sites
ongamex92    3255

Sry... there is already an answer

DWORD shaderFlag;
        #if defined(DEBUG) || defined(_DEBUG)
        shaderFlag |= D3D10_SHADER_DEBUG;
        shaderFlag |= D3D10_SHADER_SKIP_OPTIMIZATION;
        #endif

at creation moment shaderFlag contains some random value. change line :

DWORD shaderFlag;

to : 

DWORD shaderFlag = 0;
Edited by imoogiBG

Share this post


Link to post
Share on other sites
bluepig.man    424

 

Sry... there is already an answer

DWORD shaderFlag;
        #if defined(DEBUG) || defined(_DEBUG)
        shaderFlag |= D3D10_SHADER_DEBUG;
        shaderFlag |= D3D10_SHADER_SKIP_OPTIMIZATION;
        #endif

at creation moment shaderFlag contains some random value. change line :

DWORD shaderFlag;

to : 

DWORD shaderFlag = 0;

 

Although,l got the answer before your suggestion, thanks.smile.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By lonewolff
      Hi Guys,
      I am presently trying to render a video frame to a quad in DirectX 11 using Microsoft Media Foundations. But I am having a problem with 'TransferVideoFrame'.
      m_spMediaEngine->TransferVideoFrame(texture, rect, rcTarget, &m_bkgColor); The call keeps returning 'invalid parameter'.
      Some googling revealed this - https://stackoverflow.com/questions/15711054/how-do-i-grab-frames-from-a-video-stream-on-windows-8-modern-apps
      Which explains that there is (was??) a bug with the NVidia drivers back in 2013. Other searches say this bug was fixed.
      The very odd thing is, if I run the application through Visual Studio Graphical debugger the video renders perfectly to the quad with no errors, so this would suggest that my code is sound.
      I can't do as the link suggests above and try to create the device as 9_x, as this is an extension that I am creating for GameMaker 2 and I don't have access to renderer creation (only the device handle - which is fine most of the time).
      I am presently downloading VS 2017 to see if it behaves better with more recent SDK's (as I am currently using VS 2015).
      Thanks in advance
       
       
    • By AlexWIN32
      Hello!
       
      A have an issue with my point light shadows realisation.

       
      First of all, the pixel shader path:
      //.... float3 toLight = plPosW.xyz - input.posW; float3 fromLight = -toLight; //... float depthL = abs(fromLight.x); if(depthL < abs(fromLight.y)) depthL = abs(fromLight.y); if(depthL < abs(fromLight.z)) depthL = abs(fromLight.z); float4 pH = mul(float4(0.0f, 0.0f, depthL, 1.0f), lightProj); pH /= pH.w; isVisible = lightDepthTex.SampleCmpLevelZero(lightDepthSampler, normalize(fromLight), pH.z).x;

      lightProj matrix creation
      Matrix4x4 projMat = Matrix4x4::PerspectiveFovLH(0.5f * Pi, 0.01f, 1000.0f, 1.0f);  
      thats how i create Depth cube texture
       
      viewport->TopLeftX = 0.0f; viewport->TopLeftY = 0.0f; viewport->Width = static_cast<float>(1024); viewport->Height = static_cast<float>(1024); viewport->MinDepth = 0.0f; viewport->MaxDepth = 1.0f; D3D11_TEXTURE2D_DESC textureDesc; textureDesc.Width = 1024; textureDesc.Height = 1024; textureDesc.MipLevels = 1; textureDesc.ArraySize = 6; textureDesc.Format = DXGI_FORMAT_R24G8_TYPELESS; textureDesc.SampleDesc.Count = 1; textureDesc.SampleDesc.Quality = 0; textureDesc.Usage = D3D11_USAGE_DEFAULT; textureDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE; textureDesc.CPUAccessFlags = 0; textureDesc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE; ID3D11Texture2D* texturePtr; HR(DeviceKeeper::GetDevice()->CreateTexture2D(&textureDesc, NULL, &texturePtr)); for(int i = 0; i < 6; ++i){ D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; dsvDesc.Flags = 0; dsvDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY; dsvDesc.Texture2DArray = D3D11_TEX2D_ARRAY_DSV{0, i, 1}; ID3D11DepthStencilView *outDsv; HR(DeviceKeeper::GetDevice()->CreateDepthStencilView(texturePtr, &dsvDesc, &outDsv)); edgeDsv = outDsv; } D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; srvDesc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS; srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; srvDesc.TextureCube = D3D11_TEXCUBE_SRV{0, 1}; ID3D11ShaderResourceView *outSRV; HR(DeviceKeeper::GetDevice()->CreateShaderResourceView(texturePtr, &srvDesc, &outSRV));  
      then i create six target oriented cameras and finally draw scene to cube depth according to each camera
      Cameras creation code:  
      std::vector<Vector3> camDirs = { { 1.0f, 0.0f, 0.0f}, {-1.0f, 0.0f, 0.0f}, { 0.0f, 1.0f, 0.0f}, { 0.0f, -1.0f, 0.0f}, { 0.0f, 0.0f, 1.0f}, { 0.0f, 0.0f, -1.0f}, }; std::vector<Vector3> camUps = { {0.0f, 1.0f, 0.0f}, // +X {0.0f, 1.0f, 0.0f}, // -X {0.0f, 0.0f, -1.0f}, // +Y {0.0f, 0.0f, 1.0f}, // -Y {0.0f, 1.0f, 0.0f}, // +Z {0.0f, 1.0f, 0.0f} // -Z }; for(size_t b = 0; b < camDirs.size(); b++){ edgesCameras.SetPos(pl.GetPos()); edgesCameras.SetTarget(pl.GetPos() + camDirs); edgesCameras.SetUp(camUps); edgesCameras.SetProjMatrix(projMat); }  
      I will be very gratefull for any help!
      P.s sorry for my poor English)
       
    • By isu diss
      HRESULT FBXLoader::Open(HWND hWnd, char* Filename) { HRESULT hr = S_OK; if (FBXM) { FBXIOS = FbxIOSettings::Create(FBXM, IOSROOT); FBXM->SetIOSettings(FBXIOS); FBXI = FbxImporter::Create(FBXM, ""); if (!(FBXI->Initialize(Filename, -1, FBXIOS))) MessageBox(hWnd, (wchar_t*)FBXI->GetStatus().GetErrorString(), TEXT("ALM"), MB_OK); FBXS = FbxScene::Create(FBXM, "MCS"); if (!FBXS) MessageBox(hWnd, TEXT("Failed to create the scene"), TEXT("ALM"), MB_OK); if (!(FBXI->Import(FBXS))) MessageBox(hWnd, TEXT("Failed to import fbx file content into the scene"), TEXT("ALM"), MB_OK); if (FBXI) FBXI->Destroy(); FbxNode* MainNode = FBXS->GetRootNode(); int NumKids = MainNode->GetChildCount(); FbxNode* ChildNode = NULL; for (int i=0; i<NumKids; i++) { ChildNode = MainNode->GetChild(i); FbxNodeAttribute* NodeAttribute = ChildNode->GetNodeAttribute(); if (NodeAttribute->GetAttributeType() == FbxNodeAttribute::eMesh) { FbxMesh* Mesh = ChildNode->GetMesh(); NumVertices = Mesh->GetControlPointsCount();//number of vertices MyV = new FBXVTX[NumVertices]; for (DWORD j = 0; j < NumVertices; j++) { FbxVector4 Vertex = Mesh->GetControlPointAt(j);//Gets the control point at the specified index. MyV[j].Position = XMFLOAT3((float)Vertex.mData[0], (float)Vertex.mData[1], (float)Vertex.mData[2]); } NumIndices = Mesh->GetPolygonVertexCount();//number of indices; for cube 20 MyI = new DWORD[NumIndices]; MyI = (DWORD*)Mesh->GetPolygonVertices();//index array NumFaces = Mesh->GetPolygonCount(); MyF = new FBXFACEX[NumFaces]; for (int l=0;l<NumFaces;l++) { MyF[l].Vertices[0] = MyI[4*l]; MyF[l].Vertices[1] = MyI[4*l+1]; MyF[l].Vertices[2] = MyI[4*l+2]; MyF[l].Vertices[3] = MyI[4*l+3]; } UV = new XMFLOAT2[NumIndices]; for (int i = 0; i < Mesh->GetPolygonCount(); i++)//polygon(=mostly rectangle) count { FbxLayerElementArrayTemplate<FbxVector2>* uvVertices = NULL; Mesh->GetTextureUV(&uvVertices); for (int j = 0; j < Mesh->GetPolygonSize(i); j++)//retrieves number of vertices in a polygon { FbxVector2 uv = uvVertices->GetAt(Mesh->GetTextureUVIndex(i, j)); UV[4*i+j] = XMFLOAT2((float)uv.mData[0], (float)uv.mData[1]); } } } } } else MessageBox(hWnd, TEXT("Failed to create the FBX Manager"), TEXT("ALM"), MB_OK); return hr; } I've been trying to load fbx files(cube.fbx) into my programme. but I get this. Can someone pls help me?
       

    • By lonewolff
      Hi Guys,
      I am having a bit of a problem with a dynamic texture.
      It is creating without error and I am attempting to initialize the first pixel to white to make sure I am mapping correctly. But when I draw the texture to the quad it displays the whole quad white (instead of just one pixel).
      This is how I am creating, mapping, and setting the first pixel to white. But as mentioned, when I draw the quad, the entire quad is white.
       
      // Create dynamic texture D3D11_TEXTURE2D_DESC textureDesc = { 0 }; textureDesc.Width = 2048; textureDesc.Height = 2048; textureDesc.MipLevels = 1; textureDesc.ArraySize = 1; textureDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; textureDesc.SampleDesc.Count = 1; textureDesc.Usage = D3D11_USAGE_DYNAMIC; textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; textureDesc.MiscFlags = 0; HRESULT result = d3dDevice->CreateTexture2D(&textureDesc, NULL, &textureDynamic); if (FAILED(result)) return -1; result = d3dDevice->CreateShaderResourceView(textureDynamic, 0, &textureRV); if (FAILED(result)) return -2; D3D11_MAPPED_SUBRESOURCE resource; if (FAILED(d3dContext->Map(textureDynamic, 0, D3D11_MAP_WRITE_DISCARD, 0, &resource))) return -1; memset(resource.pData, 255, 4); d3dContext->Unmap(textureDynamic, 0);  
      Hopefully I have just made an oversight somewhere.
      Any assistance would be greatly appreciated
      (If I change the 255 value to 128 the quad then turns grey, so the mapping is definitely doing something. Just can't work out why it is colouring the whole quad and not the first pixel)
    • By KaiserJohan
      Just a really quick question - is there any overhead to using DrawIndexedInstanced even for geometry you just render once vs using DrawIndexed? Or is the details obfuscated by the graphics driver?
      I would assume no but you never know  
  • Popular Now