<p>Turns this was not an issue with the scale of the values passed in, just that the log function in glsl is base e.  The solution was merely to do log(stuff)/log(10) and that got the result of a base 10 log.</p>

CC BY-SA 3.0
2016-06-02T01:03:53.487Z
2016-06-02T01:03:53.487Z
J.Doe
<p>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.</p>

<p>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.</p>

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

<p>Fragment:</p>

<pre><code>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 &lt; 0.001)
    {
        discard; //11.7-&gt;12.2
    }
    //gl_FragColor = vec4(0.4);

}
</code></pre>

<p>Vertex:</p>

<pre><code>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;
}
</code></pre>

<p>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.</p>

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

CC BY-SA 3.0
2016-06-01T17:37:01.890Z
Yes technically. However as you can see by the value v I am going to map it differently.
J.Doe
CC BY-SA 3.0
2016-06-01T21:28:31.180Z
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](http://computergraphics.stackexchange.com/help/self-answer).
trichoplax is on Codidact now
<color>
Fading an object in add mode with correct color math
J.Doe
# Fading an object in add mode with correct color math

(Asked by: username_0 on 2016-06-01)

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)
    {
        discard; //11.7->12.2
    }
    //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.

**Tags:** color

> **Comments:**
> **username_0**: Yes technically. However as you can see by the value v I am going to map it differently.  
> **username_1**: 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](http://computergraphics.stackexchange.com/help/self-answer).  

---

## 1 answers

### Answer by username_0 on 2016-06-02. Score: 1 | Accepted answer

Turns this was not an issue with the scale of the values passed in, just that the log function in glsl is base e. The solution was merely to do log(stuff)/log(10) and that got the result of a base 10 log.


---

