Blending two images together.

Started by
24 comments, last by terryeverlast 9 years, 1 month ago


in his post of 05 March 2015 - 03:15 Pm, I do see the vines (the second texture). This let's me assume that all of the second geometry pixels are drawn.

You have me at a disadvantage. I can't find a post with that timestamp. In any case, "assuming" is certainly your prerogative. I (personally) see no reason to call any image he's posted a "second" texture rendered with a "second" geometry.

E.g., before he posted any image of "results," the OP stated.


I combined the brick with the vines with the tool "DirectX Texture Tool"

As a result, I also see "vines" in some of the images which may, in fact, be the texture he's using, but I still don't have enough information to assume when or how or what image may have been rendered.

He's also changing his rendering code intermittently, changing context culling and blend states (which he doesn't appear to change thereafter), so (for me personally) I can make no assumptions relating an image to the code and data that produced it.

What I do assume is, if results are not as expected, the code is incorrect, the data is incorrect, or both.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Advertisement

So my code should be


 for(UINT p = 0; p < techDesc.Passes; ++p)
    {
		md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset);
		md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0);

		// Draw the grid.
		XMMATRIX world = XMLoadFloat4x4(&mGridWorld);
		XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
		XMMATRIX worldViewProj = world*view*proj;

		// Draw the box.
		world = XMLoadFloat4x4(&mBoxWorld);
		worldInvTranspose = MathHelper::InverseTranspose(world);
		worldViewProj = world*view*proj;
		Effects::BasicFX->SetWorld(world);
		Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
		Effects::BasicFX->SetWorldViewProj(worldViewProj);
		Effects::BasicFX->SetTexTransform(XMMatrixIdentity());
		Effects::BasicFX->SetMaterial(mBoxMat);
		
		activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
	
		Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV); // brick wall image
	
		md3dImmediateContext->OMSetBlendState(0, 0, 0xffffffff); 
		
		md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset);


		Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV2); // alpha texture
		md3dImmediateContext->OMSetBlendState(mb, blendFactor, 0xffffffff);
		

		md3dImmediateContext->OMSetDepthStencilState(myds, 0); // set to  D3D11_COMPARISON_LESS_EQUAL



		md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset);

		md3dImmediateContext->OMSetBlendState(0, 0, 0xffffffff);

md3dImmediateContext->OMSetDepthStencilState(myds2, 0); // set to LESS_EQUAL
		
		
    }

and my depth func should be


D3D11_DEPTH_STENCIL_DESC dsDesc;

	dsDesc.DepthEnable = false;
	dsDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
	dsDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
	dsDesc.StencilEnable = TRUE;
	dsDesc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
	dsDesc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
	dsDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
	dsDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
	dsDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
	dsDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
	dsDesc.BackFace = dsDesc.FrontFace;

	md3dDevice->CreateDepthStencilState(&dsDesc, &myds);

?Does it look right Buckeye?

?

?


Does it look right Buckeye?

Some of it doesn't look right. For the rest, unfortunately, I can't really say. I.e., I don't know about your rendering code because I'm not familiar with that effect interface, or what the shader itself does. ( Just as a general comment, you don't seem to check for errors anywhere. That's bad practice. Check the error indication for every function that provides one. )

Clearing the blend state to default is probably okay (my personal style is to set things to a defined values, but that's me.) You then set the blend state to mb. Don't know what that is - no comment.

With regard to the depth state myds, why are you disabling depth testing? The DepthFunc value is as suggested, however. The intent of my previous post (#19) was to indicate that the depth func should be modified, not disabled.

With regard to depth state myds2 (" // Set to LESS_EQUAL "), without knowing what that state is, or what the comment means ... no comment.

Just a suggestion: naming variables with something meaningful can be helpful to you as a programmer, and to others who look at your code. E.g., mb, myds, myds2 don't convey anything useful. Something like "m_blendOff" or "m_depthOnLessEqual" or "m_depthOnLess" would help indicate your intent, whether they're created correctly or not. wink.png

EDIT: are you creating your device with the D3D11_CREATE_DEVICE_DEBUG flag? If not, do that NOW. There are several D3D11 functions which do not have error code return values, and you'll have to watch the debug output for information.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Alright, thx to all the guys that helped me out, I got it working

Here it is

2q2k3l1.png

You should pay forward - post your working code to help others who may now or in future be looking to do what you're done.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

The code does:

2e5tpiv.jpg

In the draw scene function:


for(UINT p = 0; p < techDesc.Passes; ++p)
    {
		md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset);
		md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0);

		

		// Draw the box.
		XMMATRIX world = XMLoadFloat4x4(&mBoxWorld);
		XMMATRIX worldInvTranspose = MathHelper::InverseTranspose(world);
		XMMATRIX worldViewProj = world*view*proj;
		Effects::BasicFX->SetWorld(world);
		Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
		Effects::BasicFX->SetWorldViewProj(worldViewProj);
		Effects::BasicFX->SetTexTransform(XMMatrixIdentity());
		Effects::BasicFX->SetMaterial(mBoxMat);
		activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV); 
		md3dImmediateContext->OMSetBlendState(defaultblend, 0, 0xffffffff);
		md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset);
		activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV2); // alpha texture
		md3dImmediateContext->OMSetBlendState(subtractblend, blendFactor, 0xffffffff);
		md3dImmediateContext->OMSetDepthStencilState(mydepth, 0); // set to  D3D11_COMPARISON_LESS_EQUAL
		md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset);


}

and the Init function



	D3D11_BLEND_DESC myblend2 = { 0 };
	myblend2.AlphaToCoverageEnable = false;
	myblend2.IndependentBlendEnable = false;

	myblend2.RenderTarget[0].BlendEnable = true;
	myblend2.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
	myblend2.RenderTarget[0].DestBlend = D3D11_BLEND_ONE;
	myblend2.RenderTarget[0].BlendOp = D3D11_BLEND_OP_SUBTRACT;
	myblend2.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
	myblend2.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
	myblend2.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
	myblend2.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
	HR(md3dDevice->CreateBlendState(&myblend2, &subtractblend));

	myblend2.RenderTarget[0].BlendEnable = FALSE;

	HR(md3dDevice->CreateBlendState(&myblend2, &defaultblend));
	
	


	D3D11_DEPTH_STENCIL_DESC dsDesc2;

	dsDesc2.DepthEnable = true;
	dsDesc2.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
	dsDesc2.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
	dsDesc2.StencilEnable = false;
	dsDesc2.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
	dsDesc2.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
	dsDesc2.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
	dsDesc2.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
	dsDesc2.FrontFace.StencilPassOp = D3D11_STENCIL_OP_REPLACE;
	dsDesc2.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
	dsDesc2.BackFace = dsDesc.FrontFace;

	md3dDevice->CreateDepthStencilState(&dsDesc2, &mydepth);

This topic is closed to new replies.

Advertisement