I am trying to make a heatmap and in my Fragment shader i want to know the existing color value of the pixel on which the shader will write.
Based on the red color value i want to decide whether to write or not.
currently yellow color is overwriting the already existing red color.
i add points
AddPoint(glm::vec2(0.0f, 0.0f), 0.1f);
AddPoint(glm::vec2(0.2f, -0.5f), 0.2f);
AddPoint(glm::vec2(0.3f, 0.3f), 0.3f);
AddPoint(glm::vec2(0.9f, 1.0f), 1.0f);
AddPoint(glm::vec2(0.7f, 0.9f), 1.0f);
AddPoint(glm::vec2(-0.7f, 0.5f), 0.8f);
AddPoint(glm::vec2(-0.1f, -0.5f), 0.8f);
than render to vertex shader which passes the points to geomtry shader.
The geomerty shader constructs a circle.
This is my Fragment Shader.
#version 420 core
in float gValue;
in vec2 pointPos; // Receive the original position from the geometry shader
out vec4 FragColor;
uniform sampler1D colormap; // This has the color range for the Heat Map
uniform float radius;
void main()
{
// Convert gl_FragCoord to normalized device coordinates (NDC)
vec2 fragCoordNDC = (gl_FragCoord.xy / vec2(1920.0, 1080.0)) * 2.0 - 1.0;
float distance = length(fragCoordNDC - pointPos);
float normalizedDistance = distance / radius;
float intensity = 1.0 - normalizedDistance;
float finalIntensity = mix(gValue, gValue - 0.3, normalizedDistance);
// Sample color from the colormap
vec4 newColor = texture(colormap, finalIntensity);
// Check if the new color's red value is greator
if (newColor.r > FragColor.r)
{
// Update FragColor only if the new alpha is greater
FragColor = newColor;
}
}