I am seeking the simplest working example of a two pass HLSL pixel shader.
It can do anything really, but the main idea is to perform "ping ponging" to take the output of the first pass and then send it for the second pass.
In my example I want to draw to the R channel and then draw to the G channel and produce a simple Venn Diagram in the shader, but need to detect overlap. I can currently detect one or the other but not overlap. There are a red and green circle overlapping, and I want to put a dynamic texture map in the overlap region. I can currently put it in either or.
Below is how it looks in the shader.
--------------------------------
Texture2D shaderTexture;
SamplerState SampleType;
//////////////
// TYPEDEFS //
//////////////
struct PixelInputType
{
float4 position : SV_POSITION;
float2 tex0 : TEXCOORD0;
float2 tex1 : TEXCOORD1;
float4 color : COLOR;
};
////////////////////////////////////////////////////////////////////////////////
// Pixel Shader
////////////////////////////////////////////////////////////////////////////////
float4 main(PixelInputType input) : SV_TARGET
{
float4 textureColor0;
float4 textureColor1;
// Sample the pixel color from the texture using the sampler at this texture coordinate location.
textureColor0 = shaderTexture.Sample(SampleType, input.tex0);
textureColor1 = shaderTexture.Sample(SampleType, input.tex1);
if (input.color[0]==1.0f && input.color[1]==1.0f) // Requires multi-pass
textureColor0 = textureColor1;
return textureColor0;
}
Here is the calling code (that needs to be modified)
m_d3dContext->IASetVertexBuffers(0, 2, vbs, strides, offsets);
m_d3dContext->IASetIndexBuffer(m_indexBuffer.Get(), DXGI_FORMAT_R32_UINT,0);
m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_d3dContext->IASetInputLayout(m_inputLayout.Get());
m_d3dContext->VSSetShader(m_vertexShader.Get(), nullptr, 0);
m_d3dContext->VSSetConstantBuffers(0, 1, m_constantBuffer.GetAddressOf());
m_d3dContext->PSSetShader(m_pixelShader.Get(), nullptr, 0);
m_d3dContext->PSSetShaderResources(0, 1, m_SRV.GetAddressOf());
m_d3dContext->PSSetSamplers(0, 1, m_QuadsTexSamplerState.GetAddressOf());