I am going through the Book of Shaders tutorial on GLSL and I attempt to use the smoothstep
function but I get this error. You can see it happen when I changed the step
to the smoothstep
function below.
// Author @patriciogv - 2015
// http://patriciogonzalezvivo.com
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
void main(){
vec2 st = gl_FragCoord.xy/u_resolution.xy;
vec3 color = vec3(0.0);
// bottom-left
vec2 bl = smoothstep(vec2(0.1),st);
float pct = bl.x * bl.y;
// top-right
// vec2 tr = step(vec2(0.1),1.0-st);
// pct *= tr.x * tr.y;
color = vec3(pct);
gl_FragColor = vec4(color,1.0);
}
Any ideas how to fix this?
step
and smootstep
are 2 functions with a different signature and behavior.
While step
generates a hard transition from 0 to 1 at an edge, smoothstep
smoothly interpolates between 2 values.
As specified in the Khronos reference, smoothstep
has 3 parameters:
genType smoothstep( genType edge0, genType edge1, genType x );
edge0
Specifies the value of the lower edge of the Hermite function.edge1
Specifies the value of the upper edge of the Hermite function.x
Specifies the source value for interpolation.smoothstep performs smooth Hermite interpolation between 0 and 1 when
edge0 < x < edge1
. This is useful in cases where a threshold function with a smooth transition is desired.
In comparison, step
has 2 parameters:
genType step( genType edge, genType x);
edge
Specifies the location of the edge of the step function.x
Specify the value to be used to generate the step function.
step
generates a step function by comparing x to edge.
For elementi
of the return value, 0.0 is returnedif x[i] < edge[i]
, and 1.0 is returned otherwise.