i've implemented a shader that produces a simple Radar Ping given a uniform time input. ShaderToy Proof of concept
Now i implemented this into my real Opengl GLFW GLAD C++ Core4.5Profile NVIDIA GTX960 environment and recieve only weird ouput when i use my own function call.
Why do i recieve such a weird output if i use a function call in opengl glsl?
PS: I have a feeling this has something to do with the precision and the call by value standards of glsl.
Thank you very much for any response, or even a hint where to look for help.
EDIT: The problem was as Kevin van der Velden described.
Result Images:
This is my shader Code:
#version 330 core
in vec2 v_TexCoord;
out vec4 FragColor;
uniform float u_time;
// Generates a BnW Ping on normalized 2d coordinate system
float RadarPing(in vec2 uv, in vec2 center,in float innerTail,
in float frontierBorder, in float timeResetSeconds,
in float radarPingSpeed, in float fadeDistance,
in float currentTime)
{
vec2 diff = center-uv;
float r = length(diff);
float timeMod = mod(currentTime, timeResetSeconds) * radarPingSpeed;
float circle;
circle += smoothstep(timeMod - innerTail, timeMod, r) * smoothstep(timeMod + frontierBorder,timeMod, r);
return circle;
}
void main()
{
//normalize coordinates
vec2 uv = v_TexCoord; //move coordinates to 0..1
uv = uv*2.; // translate to the center
uv += vec2(-1.0, -1.0);
//uv.x *= iResolution.x/iResolution.y; //correct the aspect ratio
float color;
// generate some radar pings
float fadeDistance = 1.0;
float resetTimeSec = 5.0;
float radarPingSpeed = 0.3;
vec2 greenPing = vec2(0.0, -1.0);
//WITHOUT FUNCTION CALL
//vec2 diff = greenPing-uv;
//float r = length(diff);
//float moduloTime = mod(u_time, resetTimeSec);
//color = smoothstep(moduloTime - 0.25, moduloTime, r) * moduloTime + 0.025, moduloTime, r);
//WITH FUNCTION CALL
color += RadarPing(uv, greenPing, 0.25, 0.025, radarPingSpeed, fadeDistance, u_time);
//OUTPUT
FragColor = vec4(color, color, color,1.0);
}