I have a scene rendered entirely with objects with additive blend mode. I have a value that is oscillating from 0, to 1. When it is 1 the object is supposed to be invisible, 0 should be entirely visible.

However I have noticed that something seems off about it, specifically it stays dark for too long. It is not my oscillating function, I suspect it having something to do with light using a logarithmic scale.

How would I convert my linear 0->1 value into a properly scaled value between 0->1

Fragment:

precision highp float;

uniform sampler2D s_texture;

varying vec2 v_texcoord;
varying float alpha;

void main()
{
vec4 col = texture2D(s_texture, v_texcoord);
gl_FragColor = vec4( col.rgba  - alpha);

if (col.a < 0.001)
{
}
//gl_FragColor = vec4(0.4);

}


Vertex:

precision highp float;

attribute vec2 pos;
attribute vec2 tc;

uniform mat4 matrix;
uniform float time;
uniform float maxLeafs;
uniform vec2 position;
uniform float instance;
uniform vec2 anchorPoint;

varying vec2 v_texcoord;
varying float alpha;

vec4 finalTranslate(vec3 pos)
{
return vec4(pos + vec3(position, 0.0), 1.0);
}
vec3 rotate(vec3 pos, float angle)
{
float s = sin(-angle);
float c = cos(-angle);
return vec3(c * pos.x - s * pos.y, s * pos.x + c * pos.y, 0.0);
}
vec3 translate(vec2 pos)
{
return vec3(pos - anchorPoint, 0.0);
}
vec3 scale(vec3 pos, float amm)
{
return pos * amm;
}
void main()
{

float v = log((time * 0.9) + 0.1);
alpha = 0.0;

float leafCoverage = (3.14149 * 2.0);
float goal = ((instance) / (maxLeafs + 1.0)) * leafCoverage;
float timeFactor = smoothstep(0.0, 1.0, time);
float calculation1 = goal * timeFactor;
float calculation2 = clamp(timeFactor * leafCoverage, 0.0, goal);

float scaleFactor = clamp(smoothstep(0.0, 1.0, time * 1.2), 0.0, 1.0);

gl_Position = matrix * finalTranslate(rotate( scale(translate(pos) ,scaleFactor) ,  calculation1));
v_texcoord = tc;
}


Right now I am just taking the oscillating float time and passing it in directly, but eventually I will put it on a function so it fades in, temporarily is extra bright, then goes to the source texture.

Edit: I solved my problem, to my surprise the GLSL log function is in base e rather then 10.

• Are you using $sine/cosine$ as the oscillating function ?
– user3437
Jun 1, 2016 at 17:30
• Yes technically. However as you can see by the value v I am going to map it differently. Jun 1, 2016 at 17:37
• If you solved your own problem, you can also post an answer for anyone who sees the same problem in future. This is actively encouraged. Jun 1, 2016 at 21:28