Jump to content

  • Log In with Google      Sign In   
  • Create Account

jchmack

Member Since 29 Apr 2004
Offline Last Active Mar 02 2013 02:23 PM

Posts I've Made

In Topic: [D3D11] Alpha Transparency Trouble

04 March 2011 - 12:55 AM

Have you tried taking a frame capture with PIX and then debugged the pixel? Maybe your state isn't really getting set or something like that - you can check what is coming out of the pixel shader and the contents of the render target before and after the rendering operation has completed, which might give you some insight into what is going on.

Ok i tried Pix. I honestly dont know how to use it very well. But i did a single frame capture. I captured with f12. And in that list in the middle where it shows all my dx objects It seems that i dont have a blend state at all in the frame. Am I not creating the blend state right? Maybe its something in my device setup:



void RenderSystem::InitializeRenderSystem()
{
	mRenderSystemPTR = this;

	JCoutSetup
	JCout << L"Initializing RenderSystem" << endl;
	DisplayConsole(JCoutSend);

	HRESULT hr = S_OK;

    RECT rc;
    GetClientRect( GameWindowManager::PrimaryGameWindow->g_hWnd, &rc );
    UINT width = rc.right - rc.left;
    UINT height = rc.bottom - rc.top;

    UINT createDeviceFlags = 0;
#ifdef _DEBUG
    createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

    D3D_DRIVER_TYPE driverTypes[] =
    {
        D3D_DRIVER_TYPE_HARDWARE,
        D3D_DRIVER_TYPE_WARP,
        D3D_DRIVER_TYPE_REFERENCE,
    };
    UINT numDriverTypes = ARRAYSIZE( driverTypes );

    D3D_FEATURE_LEVEL featureLevels[] =
    {
        D3D_FEATURE_LEVEL_11_0,
        D3D_FEATURE_LEVEL_10_1,
        D3D_FEATURE_LEVEL_10_0,
    };
	UINT numFeatureLevels = ARRAYSIZE( featureLevels );

    DXGI_SWAP_CHAIN_DESC sd;
    ZeroMemory( &sd, sizeof( sd ) );
    sd.BufferCount = 1;
    sd.BufferDesc.Width = width;
    sd.BufferDesc.Height = height;
    sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    sd.BufferDesc.RefreshRate.Numerator = 60;
    sd.BufferDesc.RefreshRate.Denominator = 1;
    sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    sd.OutputWindow = GameWindowManager::PrimaryGameWindow->g_hWnd;
    sd.SampleDesc.Count = 1;
    sd.SampleDesc.Quality = 0;
    sd.Windowed = TRUE;

    for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
    {
        g_driverType = driverTypes[driverTypeIndex];
        hr = D3D11CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels,
                                            D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
        
		ManagerBase::g_pd3dDevice			= g_pd3dDevice;
		ManagerBase::g_pImmediateContext	= g_pImmediateContext;
		Mesh::g_pImmediateContext			= g_pImmediateContext;
		
		if( SUCCEEDED( hr ) )
            break;
    }

    if( FAILED( hr ) )
	{
		JAssert(false,L"Failed To Run D3D11CreateDeviceAndSwapChain");
	}

    // Create a render target view
    //ID3D11Texture2D* pBackBuffer = NULL;
    hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&mBackBuffer );
    if( FAILED( hr ) )
	{
        JAssert(false,L"Failed To Run g_pSwapChain->GetBuffer");
	}

    hr = g_pd3dDevice->CreateRenderTargetView( mBackBuffer, NULL, &g_pRenderTargetView );
    mBackBuffer->Release();
    if( FAILED( hr ) )
    {
        JAssert(false,L"Failed To Run g_pd3dDevice->CreateRenderTargetView(");
	}

	// Create depth stencil texture
    D3D11_TEXTURE2D_DESC descDepth;
    ZeroMemory( &descDepth, sizeof(descDepth) );
    descDepth.Width = width;
    descDepth.Height = height;
    descDepth.MipLevels = 1;
    descDepth.ArraySize = 1;
    descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
    descDepth.SampleDesc.Count = 1;
    descDepth.SampleDesc.Quality = 0;
    descDepth.Usage = D3D11_USAGE_DEFAULT;
    descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
    descDepth.CPUAccessFlags = 0;
    descDepth.MiscFlags = 0;
    hr = g_pd3dDevice->CreateTexture2D( &descDepth, NULL, &mDepthStencil );
    if( FAILED( hr ) )
    {
        JAssert(false,L"Failed To Create depth stencil Texture");
	}

    // Create the depth stencil view
    D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
    ZeroMemory( &descDSV, sizeof(descDSV) );
    descDSV.Format = descDepth.Format;
    descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
    descDSV.Texture2D.MipSlice = 0;
    hr = g_pd3dDevice->CreateDepthStencilView( mDepthStencil, &descDSV, &mDepthStencilView );
    if( FAILED( hr ) )
    {
        JAssert(false,L"Failed To Create depth stencil View");
	}
    g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, mDepthStencilView );

	//Setup Rasterizer
	D3D11_RASTERIZER_DESC rasterDesc;
	rasterDesc.AntialiasedLineEnable = false;
	rasterDesc.CullMode = D3D11_CULL_BACK;//D3D11_CULL_BACK D3D11_CULL_NONE
	rasterDesc.DepthBias = 0;
	rasterDesc.DepthBiasClamp = 0.0f;
	rasterDesc.DepthClipEnable = true;
	rasterDesc.FillMode = D3D11_FILL_SOLID;
	rasterDesc.FrontCounterClockwise = false;
	rasterDesc.MultisampleEnable = false;
	rasterDesc.ScissorEnable = false;
	rasterDesc.SlopeScaledDepthBias = 0.0f;

	hr = g_pd3dDevice->CreateRasterizerState(&rasterDesc, &mRasterizerState);
	if(FAILED(hr))
	{
		JAssert(false,L"Failed To Create Rasterizer");
	}
	g_pImmediateContext->RSSetState(mRasterizerState);

    // Setup the viewport
    D3D11_VIEWPORT vp;
    vp.Width = (FLOAT)width;
    vp.Height = (FLOAT)height;
    vp.MinDepth = 0.0f;
    vp.MaxDepth = 1.0f;
    vp.TopLeftX = 0;
    vp.TopLeftY = 0;
    g_pImmediateContext->RSSetViewports( 1, &vp );

	//Setup Depth Stencil State
		
		D3D11_DEPTH_STENCIL_DESC depthStencilDesc;

		// Set up the description of the stencil state.
		depthStencilDesc.DepthEnable = true;
		depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
		depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;//D3D11_COMPARISON_LESS_EQUAL

		depthStencilDesc.StencilEnable = true;
		depthStencilDesc.StencilReadMask = 0xFF;
		depthStencilDesc.StencilWriteMask = 0xFF;

		// Stencil operations if pixel is front-facing.
		depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
		depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
		depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
		depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

		// Stencil operations if pixel is back-facing.
		depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
		depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
		depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
		depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

		mDepthStencilState = NULL;
		g_pd3dDevice->CreateDepthStencilState(&depthStencilDesc,&mDepthStencilState);
		g_pImmediateContext->OMSetDepthStencilState(mDepthStencilState,1);

	//Setup Blend State
	D3D11_BLEND_DESC BlendStateDescription;
	ZeroMemory(&BlendStateDescription, sizeof(D3D11_BLEND_DESC));

	//BlendStateDescription.AlphaToCoverageEnable = TRUE;
	//BlendStateDescription.IndependentBlendEnable = TRUE;
	BlendStateDescription.RenderTarget[0].BlendEnable = TRUE;

	//D3D11_BLEND_ONE
	//D3D11_BLEND_ZERO
	//D3D11_BLEND_SRC_ALPHA 
	//D3D11_BLEND_DEST_ALPHA
	//D3D11_BLEND_SRC_COLOR
	//D3D11_BLEND_DEST_COLOR
	//D3D11_BLEND_INV_SRC_ALPHA
	//D3D11_BLEND_INV_DEST_ALPHA

	BlendStateDescription.RenderTarget[0].SrcBlend			= D3D11_BLEND_SRC_ALPHA;		
	BlendStateDescription.RenderTarget[0].DestBlend			= D3D11_BLEND_INV_SRC_ALPHA;	
	BlendStateDescription.RenderTarget[0].SrcBlendAlpha		= D3D11_BLEND_ONE;				
	BlendStateDescription.RenderTarget[0].DestBlendAlpha	= D3D11_BLEND_ONE;		

	//D3D11_BLEND_OP_ADD
	//D3D11_BLEND_OP_SUBTRACT
	//D3D11_BLEND_OP_REV_SUBTRACT

	BlendStateDescription.RenderTarget[0].BlendOp			= D3D11_BLEND_OP_ADD;
	//BlendStateDescription.RenderTarget[0].BlendOpAlpha		= D3D11_BLEND_OP_ADD;
	BlendStateDescription.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;

	mBlendState = NULL;
	g_pd3dDevice->CreateBlendState(&BlendStateDescription,&mBlendState);
	//g_pd3dDevice->CreateBlendState(&BlendStateDescription,&mBlendState);
		
	if(FAILED(hr))
	{
		JAssert(false,L"Failed To Create BlendState");
	}

	float blendFactor[] = {0,0, 0, 0};
	UINT sampleMask   = 0xffffffff;
	g_pImmediateContext->OMSetBlendState(mBlendState,blendFactor, sampleMask);

	//	Managers
	mMeshManager.InitializeMeshManager();
	mShaderManager.InitializeShaderManager();
 }

After I run my engine I get a list of all the objects. No matter how many blend states i create there is only one in this list. I believe that this one is created by DX by default.

Even If i just set a null blend state and set it I dont get an error from DX:



mBlendState = NULL;
	//g_pd3dDevice->CreateBlendState(&BlendStateDescription,&mBlendState);
	//g_pd3dDevice->CreateBlendState(&BlendStateDescription,&mBlendState);
		
	if(FAILED(hr))
	{
		JAssert(false,L"Failed To Create BlendState");
	}

	float blendFactor[] = {0,0, 0, 0};
	UINT sampleMask   = 0xffffffff;
	g_pImmediateContext->OMSetBlendState(mBlendState,blendFactor, sampleMask);




In Topic: [D3D11] Alpha Transparency Trouble

03 March 2011 - 04:23 AM

Thank you for your quick reply haegarr.

I tried all of the configurations you suggested and nothing seems to change. Even when i set all the src/dest to D3D11_BLEND_ONE or D3D11_BLEND_ZERO nothing even changes as if im never even setting a blend mode. Ive been trying quite a few configurations(with the BlendStateDescription) and i dont even get any noticable change.





In Topic: Length of a Generalized Quadratic Bezier Curve in 3d

08 November 2009 - 05:29 AM

Thank you again Dave :)

I wish I had checked back on this post sooner. Since I only needed 3 points for my curve and you can generate a 2d plane from those 3 points. I ended up finding the 2d plane my curve exists in and then solving for the Length with the simpler 2D integral. But I implemented your method and it saves me the trouble of doing a conversion. I think its easier on the cpu as well.

I believe I will go with your method.

Ratings up (if you care for that sort of thing ;) )

In Topic: Length of a Generalized Quadratic Bezier Curve in 3d

25 October 2009 - 09:39 PM

Thank you for the replies guys :)

I believe that the suggestions that both of you have presented are for the parameterized form in 2d:

Length = integrate(0,1){ sqrt( (dx/dt)^2 + (dy/dt)^2 );

Which is where I got the foundation to do the one I have in 3d:

Length = integrate(0,1){ sqrt( (dx/dt)^2 + (dy/dt)^2 + (dz/dt)^2 );

But it is turning out to be very complicated because this doesn't integrate.

and I am looking to see if there is a simpler way ;).

edit: the reason it is so complicated is better explained here:
http://www.gamedev.net/community/forums/topic.asp?topic_id=313018&forum_id=20&gforum_id=0

I don't really understand how to implement the solution he suggests

In Topic: Customizable Characters

28 May 2009 - 02:29 PM

Quote:
Original post by Jae Hyuk Kwak
In the case of Fall out 3, they use FaceGen. I'm also curious for other parts...


Ive seen facegen but do they have it in game? Do you know if they bought/licensed the source for it?

PARTNERS