Jump to content
  • Advertisement
DividedByZero

3D Blending textures question

Recommended Posts

Hi Guys,

I am playing with projective texturing which I now have working well.

However, I am having troubles figuring out how to blend the original texture with the projective texture. I am trying to make it so the projective texture is painted on top of the original texture.

I have come close with this

textureColor = TextureStandard.Sample(SamplerWrap, input.textureCoord);
				
float4 texMixed = (projectionColor * projectionColor.a + textureColor * (1 - projectionColor.a));
				
color *= texMixed;

 

But this is giving me the following output;

rYMPnRe.png

The skull should be a solid black, and the greens are a bit washed out outside of the projected area.

Any advice on how to cleanly project the skull on to the body would be truly appreciated.

Thanks in advance :)

Share this post


Link to post
Share on other sites
Advertisement

What you have there is the typical "over" blending operator, commonly used for transparent rendering or for combining layers in photoshop. It's essentially a linear interpolation of the two colors based on an alpha value, in fact you can re-write it as this:

float3 texMixed = lerp(textureColor.xyz, projectionColor.xyz, projectionColor.a);



This blend operation will result in only your projected texture color being visible when alpha is 1.0, so I'm guessing the alpha isn't actually 1 in your cases. I would double-check the value of the alpha channel in your texture (RenderDoc is great for this), and perhaps try hard-coding the alpha value to 1 in your shader to see what happens.

Share this post


Link to post
Share on other sites

Hi MJP, thanks for the reply.

I just tried that snippet and it gave me the same result unfortunately.

float3 texMixed = lerp(textureColor.xyz, projectionColor.xyz, projectionColor.a);

float4 texOverlay = float4(texMixed, 1.0f);

color *= texOverlay;

Checked with the VS graphical debugger and the skull image has an alpha of 1.0 in the black areas and 0.0 in the transparent area. So the desired area is fully opaque.

3brVc82.png

Thanks again for your help so far :)

Share this post


Link to post
Share on other sites

So you still do not set proper blending operation

 

https://www.google.com/m?q=dx11+set+blending+operation

 

https://www.braynzarsoft.net/viewtutorial/q16390-13-blending

Share this post


Link to post
Share on other sites

Hi _WeirdCat_ This is my blend state here.

	ID3D11BlendState* d3dBlendState = NULL;
	D3D11_BLEND_DESC omDesc;
	ZeroMemory(&omDesc, sizeof(D3D11_BLEND_DESC));
	omDesc.RenderTarget[0].BlendEnable = true;
	omDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
	omDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
	omDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
	omDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
	omDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
	omDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
	omDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;

 

Share this post


Link to post
Share on other sites

This is what I have now, but it isn't quite there. The colours are now correct, with the exception of the darker green areas.

6MwE9AI.png

 

textureColor = TextureStandard.Sample(SamplerWrap, input.textureCoord);
float4 texOverlay = (projectionColor * projectionColor.a + textureColor * (1.0f - projectionColor.a));

color *= textureColor;
color += (diffuseColor * diffuseIntensity);
color *= saturate(textureColor * texOverlay);

return color;

 

Edited by DividedByZero

Share this post


Link to post
Share on other sites
3 hours ago, DividedByZero said:

color *= textureColor; color += (diffuseColor * diffuseIntensity); color *= saturate(textureColor * texOverlay);

This seems odd to me..

You multiply by texturecolor, add diffuse - and then multiply again by texturecolor * texoverlay(?!) ...

Shouldn't you just multiply color by texturecolor once??

Share this post


Link to post
Share on other sites
21 hours ago, vinterberg said:

This seems odd to me..

You multiply by texturecolor, add diffuse - and then multiply again by texturecolor * texoverlay(?!) ...

Shouldn't you just multiply color by texturecolor once??

Probably, but if I do the image becomes washed out and along with that the same symptom remains.

Seems that it probably is a blend mode issue, but I can't seem to figure out, for the life of me, what parameters I need to put in to get a 'normal' (using Photoshop terminology) blend. I.e. The new image gets pasted over the original image.

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!