Stick the effect of the first figure below
The second picture is a PNG image, in the middle of the blank is transparent, the edge is from transparent gradient to opaque below
Want to achieve the ideal effect is the third picture like this:
There are two solutions, 1: after the first figure, open, draw the second PNG texture, it can achieve the effect of the above, but the size of the mold shape and direction of change, also want to change the second PNG texture at the same time, it's so trouble,
By this time there is a second solution: use multiple textures,
Float4 PS_Main2 (PS_Input frag) : SV_TARGET
{
Float4 col=texture_. Sample (samplerState_, frag. Tex0);
Float4 col2=texture_filter. Sample (samplerState_, frag. Tex0);
Return col * col2;
}
This is the inside of the shader code of two textures mixed sampling, can this time in the first picture shown on the second picture, but not a transparent channel, so the effect of the ,
This time is not open the door of mixed state, open after mixed state, open after mixed state, the first texture show not to come out, only show the second texture,
Mixing parameters are as follows:
D3D11_BLEND_DESC blendDesc;
ZeroMemory (& amp; BlendDesc, sizeof (blendDesc));
BlendDesc. AlphaToCoverageEnable=FALSE;
BlendDesc. IndependentBlendEnable=FALSE;
BlendDesc. RenderTarget [0]. BlendEnable=TRUE;
BlendDesc. RenderTarget [0]. SrcBlend=D3D11_BLEND_SRC_ALPHA;
BlendDesc. RenderTarget [0]. DestBlend=D3D11_BLEND_INV_SRC_ALPHA;
BlendDesc. RenderTarget [0]. BlendOp=D3D11_BLEND_OP_ADD;
BlendDesc. RenderTarget [0]. SrcBlendAlpha=D3D11_BLEND_ONE;
BlendDesc. RenderTarget [0]. DestBlendAlpha=D3D11_BLEND_ZERO;
BlendDesc. RenderTarget [0]. BlendOpAlpha=D3D11_BLEND_OP_ADD;
BlendDesc. RenderTarget [0]. RenderTargetWriteMask=D3D11_COLOR_WRITE_ENABLE_ALL;
CodePudding user response:
To do such two don't need to open the fusion image fusion, write directly shader is quite good of,If your figure is black and white figure, shader code should be the same as you write;
If your figure is transparent figure, shader code should look like this:
Float4 PS_Main2 (PS_Input frag) : SV_TARGET
{
Float4 col=texture_. Sample (samplerState_, frag. Tex0);
Float4 col2=texture_filter. Sample (samplerState_, frag. Tex0);
Float4 ret=col * (1 - col2. A) + col2 * col2. A;
Return ret.
}