Hello everyone,
I setup a RenderTexture today to use for a little test project I've been working on.
I apply a shader to it which darkens the original result and then I render the latest frame/draw call onto the texture.
I expected the colours to fade to black basically creating this nice sort of 'tail'.
Instead the colours stop fading at some point. This 'threshold' changes depending on the darkening amount I pick.
Draw code (The red layer is the RenderTexture.)
//Darken red layer
sf::RectangleShape fxRect;
fxRect.setPosition(0,0);
fxRect.setSize(sf::Vector2f(1280,720));
fxRect.setTexture(&redLayer.getTexture());
fxShader.setParameter("texture", sf::Shader::CurrentTexture);
redLayer.draw(fxRect, &fxShader);
//Draw red layer
redLayer.display();
sf::RectangleShape redRect;
redRect.setPosition(0,0);
redRect.setSize(sf::Vector2f(1280,720));
redRect.setTexture(&redLayer.getTexture());
appRef->GetWindow().draw(redRect);
swiz_ent_list_t::iterator iter;
for (iter = ent_list.begin(); iter != ent_list.end(); ++iter)
{
SwizEntity* ent = *iter;
int entType = ent->GetBaseType();
if((entType & ENT_DRAWABLE) != 0)
{
if(SwizDrawableEntity* drawable_ent = dynamic_cast<SwizDrawableEntity*>(ent))
{
if((entType & ENT_CRITTER) != 0)
{
redLayer.draw(drawable_ent->GetDrawable());
}
else
{
appRef->GetWindow().draw(drawable_ent->GetDrawable());
}
}
}
}
Vertex shader:
void main()
{
// transform the vertex position
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
// transform the texture coordinates
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
// forward the vertex color
gl_FrontColor = gl_Color;
}
Fragment shader:
uniform sampler2D texture;
void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
vec4 blackpixel = vec4(0.0f,0.0f,0.0f,0.01f);
// multiply it by the color
gl_FragColor = gl_Color * pixel * blackpixel;
}
PS: The circle symbol in the screenshot is the mouse cursor.