Quantcast
Channel: openFrameworks - Latest posts
Viewing all articles
Browse latest Browse all 40524

Varying vec2 surfacePosition

$
0
0

Hi,
I am pretty new with shaders and gl. I know something close to nothing. I am trying to include some code from glsandbox into an OF project.
I managed to make some example working but I am trying now passing a varying vec2 surfacePosition.
It seems to understand this is a value of the texture coordinates.
I tried this in the vert

# version 120
varying vec2 surfacePosition;

void main()
{
    	gl_Position = ftransform();
    surfacePosition = gl_TexCoord[0].xy-0.5;
}

and this in the frag

#ifdef GL_ES
precision mediump float;
#endif

uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
varying vec2 surfacePosition;
#define MAX_ITER 10
void main( void ) {
    vec2 p = surfacePosition*3.0- vec2(15.0);
    vec2 i = p;
    float c = 1.0;
    float inten = .05;
    
    for (int n = 0; n < MAX_ITER; n++)
    {
        float t = time * (1.0 - (3.0 / float(n+1)));
        i = p + vec2(cos(t - i.x) + sin(t + i.y), sin(t - i.y) + cos(t + i.x));
        c += 1.0/length(vec2(p.x / (2.*sin(i.x+t)/inten),p.y / (cos(i.y+t)/inten)));
    }
    c /= float(MAX_ITER);
    c = 1.5-sqrt(pow(c,3.+ 0.5));
    gl_FragColor = vec4(vec3(c*c*c*c*0.3,c*c*c*c*0.3,c*c*c*c*0.3), 1.0);
    
}

this is in draw()


void ofApp::draw(){

    ofBackground(100, 0, 0);
    
    time = ofGetElapsedTimef();
    mouse = ofPoint(ofMap(ofGetMouseX(), 0, ofGetWidth(), 0, 1), ofMap(ofGetMouseY(), 0, ofGetHeight(), 0, 1) );
    if( useShader ){
        shader.begin();
        shader.setUniform1f("time",time );
        shader.setUniform2f("mouse",mouse.x, mouse.y );
        shader.setUniform2f("resolution", ofGetWidth(), ofGetHeight());
    }
    
    ofFill();
    ofSetColor(0, 0, 0);
    ofRect(0, 0, ofGetWindowWidth(), ofGetWindowHeight()); ///resolution of the frame in which the shader is drawn
    
    if( useShader ){
        shader.end();
    }

}

It doesn't work. And I don't understand how should I work with the varying vec2 surfacePosition.

ANy help would be much appreciated.

thanks smile


Viewing all articles
Browse latest Browse all 40524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>