I do something like this
for(int i = 0; i < renderPath->GetNumCommands(); ++i){
RenderPathCommand *command = renderPath->GetCommand(i);
if(command->type_ == CMD_CLEAR) {
command->clearColor_ = Color(0, 0, 0, 0);
}
for(int outputIndex = 0; outputIndex < command->GetNumOutputs(); ++outputIndex){
if(command->GetOutputName(outputIndex) == "viewport" || command->GetOutputName(outputIndex) == "") {
command->SetOutputName(outputIndex, mViewportTexture->GetName());
}
}
static_assert(TU_DIFFUSE == 0, "diffuse is not first texture");
for(TextureUnit inputIndex = TU_DIFFUSE; inputIndex < MAX_TEXTURE_UNITS; inputIndex = (TextureUnit)((int)inputIndex+1)){
if(command->GetTextureName(inputIndex) == "viewport") {
command->SetTextureName(inputIndex, mViewportTexture->GetName());
}
}
}
to draw everything to mViewportTexture which is created like this
mViewportTexture->SetSize(
width,
height,
GL_RGBA, TEXTURE_RENDERTARGET);
this is my final RenderPathCommand which takes the special viewport texture and sends to the viewport which already has the camera background.
command = RenderPathCommand();
command.tag_ = "InterestingCommand";
command.enabled_ = true;
command.textureNames_[TU_DIFFUSE] = mViewportTexture->GetName();
command.type_ = CMD_QUAD;
command.pixelShaderDefines_ = "DIFFMAP";
command.vertexShaderDefines_ = "DIFFMAP";
command.vertexShaderName_ = "InterestingPass";
command.pixelShaderName_ = "InterestingPass";
command.SetNumOutputs(1);
command.SetOutputName(0, "viewport");
command.shaderParameters_["InterestingParam"] = 3.0f;
command.blendMode_ = BLEND_PREMULALPHA;
renderPath->AddCommand(command);
The problem the background is all black. My issue is that in mViewportTexture alpha is 1.0 (fully opaque) everywhere. I did specify GL_RGBA. I have a background texture that is updated based on camera and want to apply a shader that only applies on the final rendered scene and not the background texture. Checking for black pixels in the shader is no good because then everything has a black bolder as it alpha blends into the background. Is there something I’m missing?
Thank you.