• Advertisement
Sign in to follow this  

Blending two images together.

This topic is 1083 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im trying to Subtract a image with blending. I made a image(brick wall) with a alpha channel(black and white image..vines)

so it is one image. Is this right. ?

Here is my code

D3D11_BLEND_DESC myBlend = { 0 };

	myBlend.AlphaToCoverageEnable = false;
	myBlend.ransparentDesc.IndependentBlendEnable = false;

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

The alpha channel is not being subtracted from the image image. It should be a brick wall with vines.

 

What is wrong with my code?

Edited by terryeverlast

Share this post


Link to post
Share on other sites
Advertisement

You want to render a wall and on top of it vines which are masked by the alpha channel ?

Then you need to first render the wall (solid) and alpha-blend (not substract) the vines. Try something like this:

	myBlend.RenderTarget[0].BlendEnable = true;
	myBlend.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
	myBlend.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
	myBlendRenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
	myBlend.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
	myBlendRenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
	myBlend.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
	myBlend.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
	HR(md3dDevice->CreateBlendState(&myBlend &BLENDTEST));

Share this post


Link to post
Share on other sites

That blend makes the image transparent. The alpha(vines) is the transparent part.

 

I need something like this in the image.

 

 

2e5tpiv.jpg

 

 

 

One of my question is. Do I load the brick wall with that alpha into one image?

 

I loaded the brick wall as the rgb, and the vines as the alpha channel with the DxTex.exe.

 

My book says this.

 

Suppose that we want to Subtract the source pixels with the destination pixels. To do this, set the source blend factor to D3D11_BLEND_ONE, the destination blend factor to D3D11_BLEND_ONE, and the blend operator to D3D11_BLEND_OP_SUBTRACT.
 

 

 

Share this post


Link to post
Share on other sites

I combined the brick with the vines with the tool "DirectX Texture Tool" and changed the surface format to "Four CC 8-bit DXT5"  and loaded the alpha onto the the texture.

 

This is right?

Share this post


Link to post
Share on other sites

Your problem is, that your vine value is in the alpha channel solely, because you cannot use only the alpha channel as all color components in fixed-function blending.

 

I can think of these solutions:

- Actually put vines into (grayscale) separate texture. Then, render the brick tex in a first pass and the vines in a second one with the same geometry and blendOp=BLEND_OP_REV_SUBTRACT, srcBlend=BLEND_ONE, dstBlend=BLEND_ONE

 

- Do blending in the Pixel Shader instead. There you can extract the alpha channel and subtract it from the other color components. If you have to render the vines in an extra pass, just use BLEND_OP_REV_SUBTRACT and output (a, a, a) in the Pixel shader, where a is the alpha value of the texture.

 

Hope i could help.

Edited by iSmokiieZz

Share this post


Link to post
Share on other sites

I really don't want to use the pixel shader to do this. I want to use the first option.(Multipass texturing)

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

				
		// Restore default blend state
		
		// 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);
		Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV6);
		
		md3dImmediateContext->OMSetBlendState(TransparentBS, blendFactor, 0xffffffff);
		activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV7);
		activeTech->GetPassByIndex(p)->Apply(1, md3dImmediateContext);
		md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset);
		md3dImmediateContext->OMSetBlendState(0, blendFactor, 0xffffffff);
		
				
    }

	HR(mSwapChain->Present(0, 0));
}

I tried that, but not working

Edited by terryeverlast

Share this post


Link to post
Share on other sites

Well the principle of multipass rendering is that you set some drawing information (blend state, texture maps/DiffuseMap, Transformation), render a geometry (DrawIndexed), set some other draw information and render the geometry again.

You don't really need Effect passes for that. Just set a different texture and blendstate, then render the geometry. Do this twice.

0. Set transformation, VBs and IBs. (Btw: 16Bit / R16 Index Bufers are often enough and save half of the data)

1. Set opaque blend state (BlendEnable=FALSE) and your brick texture

2. DrawIndexed()

3. Set "transparent" BS (srcBlend=ONE, dstBlend=ONE, blendOp=BLEND_OP_REV_SUBTRACT) and your vines texture

4. DrawIndexed()

Share this post


Link to post
Share on other sites

Got a change but not the exact thing I need

 

here is what I got

 

1073laq.jpg

 

I see the alpha with some brown from the bricks..but where is the bricks?

 

The image should be like

 

2e5tpiv.jpg

// 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);
		Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV6);
		
		md3dImmediateContext->OMSetBlendState(TransparentBS, blendFactor, 0xffffffff);
		
		md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset);
		Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV7);
		md3dImmediateContext->OMSetBlendState(TransparentBS2, blendFactor, 0xffffffff);
		activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset);

here is my blend code

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

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


	


	transparentDesc.RenderTarget[1].BlendEnable = true;
	transparentDesc.RenderTarget[1].SrcBlend = D3D11_BLEND_ONE;
	transparentDesc.RenderTarget[1].DestBlend = D3D11_BLEND_ONE;
	transparentDesc.RenderTarget[1].BlendOp = D3D11_BLEND_OP_SUBTRACT;
	transparentDesc.RenderTarget[1].SrcBlendAlpha = D3D11_BLEND_ONE;
	transparentDesc.RenderTarget[1].DestBlendAlpha = D3D11_BLEND_ZERO;
	transparentDesc.RenderTarget[1].BlendOpAlpha = D3D11_BLEND_OP_ADD;
	transparentDesc.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
	HR(md3dDevice->CreateBlendState(&transparentDesc, &TransparentBS2));
Edited by terryeverlast

Share this post


Link to post
Share on other sites

You have to create separate Blend states, not use the RenderTarget[] array in the blend desc. Also your blend desc is wrong for the second pass. See my last post. Your have to render the vines with BlendOp=BLEND_OP_REV_SUBTRACT (which is different from BLEND_OP_SUBTRACT), or render the vines first, then the bricks with BLEND_OP_SUBTRACT.

Share this post


Link to post
Share on other sites

Ok..my code

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

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


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

	

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

still the image

1073laq.jpg

Share this post


Link to post
Share on other sites

What happens if you render the bricks only? Make sure to render the Bricks in the first pass and the vines afterwards. Try inverting the grayscale vines texture.

Also, calling Apply() after the first DrawIndexed call looks not correct. 

Share this post


Link to post
Share on other sites

Ok. I rendered the first image with no blend state. The wooden crate is the first image.

The second image I converted to RGBA and put a blend on it.

 

This is what im getting

 

28hlaau.jpg

 

My code is

 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(XMLoadFloat4x4(&mTexTransform));
		Effects::BasicFX->SetMaterial(mBoxMat);
		Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV);
		md3dImmediateContext->RSSetState(NoCullRS);
		activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset);
		Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV2);
		md3dImmediateContext->OMSetBlendState(mb2, blendFactor, 0xffffffff);
		activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset);



    }

	HR(mSwapChain->Present(0, 0));

and my blend code

	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_REV_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, &mb2));

Why is it blue and not the subtracting the two images??

Edited by terryeverlast

Share this post


Link to post
Share on other sites

Am I leaving out something?

 

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

 

Is making it blue.

Edited by terryeverlast

Share this post


Link to post
Share on other sites
I don't see you setting the opaque (no-blend) blendstate. In the second frame you render your first pass with the blend shader then, which is obviously not what you want ;)

The object is blue then, because it blends with the clear color, which is blue.

Also, what ist your blendFactor?

Share this post


Link to post
Share on other sites

My blendFactor is {0.0f, 0.0f, 0.0f, 1.0f};

 

I did the opaque state with it now. Not blue anymore, just the normal first image crate withouth the second image.

 

How would you set the code up in the code below?

 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(XMLoadFloat4x4(&mTexTransform));
		Effects::BasicFX->SetMaterial(mBoxMat);
		Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV);
		md3dImmediateContext->RSSetState(NoCullRS);
		activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset);
		Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV2);
		md3dImmediateContext->OMSetBlendState(mb2, blendFactor, 0xffffffff);
		activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset);



    }

Edited by terryeverlast

Share this post


Link to post
Share on other sites

 Assuming you have a blendstate mb with BlendEnable=FALSE:

activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV);
md3dImmediateContext->OMSetBlendState(mb, blendFactor, 0xffffffff); // <<========
md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset);
Effects::BasicFX->SetDiffuseMap(mDiffuseMapSRV2);
md3dImmediateContext->OMSetBlendState(mb2, blendFactor, 0xffffffff);
//activeTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);    not required
md3dImmediateContext->DrawIndexed(mBoxIndexCount, mBoxIndexOffset, mBoxVertexOffset); 

If you only see the brick texture with this, your second texture (mDiffuseMapSRV2) might be wrong. Either it doesn't get loaded properly or all RGB channels are empty. If you like, you may attach your second texture.

If you use a Visual Studio with Graphics Diagnostics Tools, you may also capture a frame and attach the vsglog.

Share this post


Link to post
Share on other sites

Ok. Ive been on blending two images together for awhile now and not getting any luck.

 

Will someone go to http://www.d3dcoder.net/d3d11.htm, download the SOURCE CODE SET I, and in "Chapter 9 Blending" is a blend project.

 

Make the water blend with another image. Blend the water with a grayscale image or any image you can using the OMSetBlendState

 

I need help on this. thank you

Edited by terryeverlast

Share this post


Link to post
Share on other sites

At this point in the discussion, it's not clear exactly how you're rendering the object(s). So, just a guess, you can't get your blending to work properly because you're drawing the same object twice. The second time you draw, nothing is drawn because the object is rejected due to the depth test.

 

To alpha blend two textures when drawing the same object twice:

 

1. Draw the object "normally" with the opaque texture - blending disabled.

2. Enable alpha blending as Ashaman73 provides above.

3. Set the depth stencil state DepthFunc to D3D11_COMPARISON_LESS_EQUAL.

4. Draw the object with the alpha texture - blending enabled, and depth testing set to LESS_EQUAL

 

EDIT: what that change in the depth func does is to NOT reject the second pixel drawn even though the depth is the same as the pixel at the same location.

 

You may want to set the depth stencil state func back to LESS after the second draw.

 

Just a test case I put together. Below is a box drawn first with a brick texture. Then alpha blending is enabled, depth state func is set to LESS_EQUAL, the box is drawn a second time with a png texture that's just a white texture with alpha set to 0 outside a circular area. FYI, the box is actually centered at the origin, so the lower half is "covered" by the reference ground grid.

 

[attachment=26336:captured11.png]

 

EDIT2: In general, I wouldn't rely on that method to blend textures on a surface. I'm not sure that, in some cases, you wouldn't get z-fighting. Stenciling might work better (as that appears to be what you're actually doing). Another approach might be to just combine the textures in a single pass in the pixel shader, doing your own alpha calcs to combine the colors.

 

EDIT3: If, for whatever reason, water1.dds is important to you -

 

[attachment=26337:captured11.png]

Edited by Buckeye

Share this post


Link to post
Share on other sites
You talked about blending images in the way, that the second image color is subtracted from the previous one. On that site, what is done is alpha blending. These are different things.
Sorry, but what exactly is your goal?

Pixel rejection might well be an issue, but what is strange here, is that 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.

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites

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?

?

?

Edited by terryeverlast

Share this post


Link to post
Share on other sites

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.

Edited by Buckeye

Share this post


Link to post
Share on other sites

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

 

Here it is

 

2q2k3l1.png

Edited by terryeverlast

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement