This is the shader i use:
const char VertexShader[] =
"void main()"
"{"
"gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
"gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;"
"gl_FrontColor = gl_Color;"
"}";
const char RadialGradient[] =
"uniform vec4 color;"
"uniform vec2 center;"
"uniform float radius;"
"uniform float expand;"
"uniform float windowHeight;"
"void main(void)"
"{"
"vec2 centerFromSfml = vec2(center.x, windowHeight - center.y);"
"vec2 p = (gl_FragCoord.xy - centerFromSfml) / radius;"
"float r = sqrt(dot(p, p));"
"if (r < 1.0)"
"{"
"gl_FragColor = mix(color, gl_Color, (r - expand) / (1 - expand));"
"}"
"else"
"{"
"gl_FragColor = gl_Color;"
"}"
"}";
Its from Github
https://github.com/SFML/SFML/wiki/Source:-Radial-Gradient-ShaderI think the shader is never completly transparent. But it fades out TO transparent.
When i render to the window i see the shader.
But its not rendered onto the RenderTexture
This is the part where i draw to RT:
brush.setFillColor(sf::Color::Transparent);
brush.setPosition(ML);
sf::Vector2i CTP = window.mapCoordsToPixel(ML); // ML = Mouse Local Coordinates
float multi = ZoomLevel / 100.f;
brush_shader.setUniform("color", sf::Glsl::Vec4(0, 0, 1, 1));
brush_shader.setUniform("center", sf::Vector2f(CTP.x, CTP.y)); // "center" uses Global Coordinates!!
brush_shader.setUniform("radius", brush.getRadius()* multi);
brush_shader.setUniform("expand", 0.25f);
//window.draw(brush);
//brush.setFillColor(ColorBrush);
states.shader = &brush_shader;
if (ToolNow == 0) // Eraser Brush
{
states.blendMode = sf::BlendNone;
if (LayerNR == 0) { RT_Layer0.draw(brush, states); RT_Layer0.display(); }
if (LayerNR == 1) { RT_Layer1.draw(brush, states); RT_Layer1.display(); }
if (LayerNR == 2) { RT_Layer2.draw(brush, states); RT_Layer2.display(); }
if (LayerNR == 3) { RT_Layer3.draw(brush, states); RT_Layer3.display(); }
if (LayerNR == 4) { RT_Layer4.draw(brush, states); RT_Layer4.display(); }
}
if (ToolNow != 0) // Standard Brush
{
states.blendMode = sf::BlendAlpha;
if (LayerNR == 0) { RT_Layer0.draw(brush, &brush_shader); RT_Layer0.display(); } // Shader direct
if (LayerNR == 1) { RT_Layer1.draw(brush, states); RT_Layer1.display(); }
if (LayerNR == 2) { RT_Layer2.draw(brush, states); RT_Layer2.display(); }
if (LayerNR == 3) { RT_Layer3.draw(brush, states); RT_Layer3.display(); }
if (LayerNR == 4) { RT_Layer4.draw(brush, states); RT_Layer4.display(); }
}
...
window.draw(brush, &brush_shader); // <--- This works!
For testing i dont use "states" in "RT_Layer0" but the shader directly.