¿Cómo implementar esta espiral giratoria en WebGL? [cerrado]

Could somebody try to implement given animation into WebGL shader example? It would be great for people learing WebGL like myself.

texto alternativo

Fuente: http://dvdp.tumblr.com/post/2664387637/110109

preguntado el 09 de enero de 11 a las 08:01

Here are some HTML Canvas experiments in this direction to help you. The key is to work in polar coordinates: Espiral 1, Espiral 2, Espiral 3, Espiral 4. -

Y también debes Espiral 5, slightly closer to this design. -

We expect you to have attempted to solve this problem by yourself rather than asking the community to arrive at a complete solution for you. When you've got some code to show us that demonstrates some effort by you (even if it's wrong) please update your question and flag to re-open. Thanks. -

1 Respuestas

I've implemented your animation at http://www.brainjam.ca/stackoverflow/webglspiral.html. It will give you a "WebGL not supported" message if your browser does not support WebGL. It is adapted from a sandbox created by mrdoob. The basic idea is to show a rectangular surface (consisting of two triangles) and to apply the shader to the surface.

The actual shader code is as follows:

uniform float time;
uniform vec2 resolution;
uniform vec2 aspect;

void main( void ) {

    vec2 position = -aspect.xy + 2.0 * gl_FragCoord.xy / resolution.xy * aspect.xy;
    float angle = 0.0 ;
    float radius = length(position) ;
    if (position.x != 0.0 && position.y != 0.0){
        angle = degrees(atan(position.y,position.x)) ;
    float amod = mod(angle+30.0*time-120.0*log(radius), 30.0) ;
    if (amod<15.0){
        gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
    } else{
        gl_FragColor = vec4( 1.0, 1.0, 1.0, 1.0 );                    

The spiral resizes with the browser window, but you could easily opt for a fixed size canvas instead.

Actualizar: Just for fun, here's the exact same implementation in a jsfiddle: http://jsfiddle.net/z9EmN/

Respondido 12 Abr '11, 06:04

ah yes. i saw the shadertoy version and thought. hey years ago i asked about it on stackoverflow. and here it is. :) - zproxy

now looking an anwser for stackoverflow.com/questions/33277825/… - zproxy

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.