¿Cómo crear líneas de contorno latitudinales (horizontales) en GLSL?
Apunto a este efecto: (líneas de contorno horizontales solamente):
Encontréeste ejemplo, sin embargo, crea horizontaly Líneas de contorno verticales. No puedo entender cómo la llamada afwidth()
está generando las líneas.
uniform float gsize;//size of the grid
uniform float gwidth;//grid lines'width in pixels
varying vec3 P;
void main()
{
vec3 f = abs(fract (P * gsize)-0.5);
vec3 df = fwidth(P * gsize);
float mi=max(0.0,gwidth-1.0), ma=max(1.0,gwidth);//should be uniforms
vec3 g=clamp((f-df*mi)/(df*(ma-mi)),max(0.0,1.0-gwidth),1.0);//max(0.0,1.0-gwidth) should also be sent as uniform
float c = g.x * g.y * g.z;
gl_FragColor = vec4(c, c, c, 1.0);
gl_FragColor = gl_FragColor * gl_Color;
}
¿Cómo modificaría ese ejemplo para que sea solo líneas horizontales?
¿Hay una mejor solución?
Actualizar:
Solución del sombreador modificado a continuación. Use flotadores usando solo ely
valor.
void main() {
float f = fract (_pos.y * 15.0);
float df = fwidth(_pos.y * 15.0);
float g = smoothstep(df * 1.0, df * 2.0, f);
float c = g;
gl_FragColor = vec4(c, c, c, 1.0);
}