prince_polka

03-11-2017, 05:25 PM

Hello, I'm new here. I posted in GLSL but it seems it's not getting accepted.

Don't know if mod is slow or if they rejected it...

Anyways not intending to spam but anyways...

I have a bit unusual goal with learning GLSL, I wan't to eventually do things like this...

https://www.youtube.com/watch?v=cd-ZNymt6Ko

But I decided to start with something simpler to learn from, a post-processing anti-aliasing.

But even that is too hard.

I wan't to read from and write to a couple "persistent" textures aswell as gl_FragColor,

so that I can do multiple passes, but just one pass each frame.

Maybe buffer objects is what I need?

Here's what I came up with, which isn't much...

#ifdef GL_ES

precision mediump float;

#endif

uniform sampler2D texture;

uniform vec2 u_resolution;

uniform vec3 u_mouse;

uniform float u_time;

float x;

float y;

float p; // pixel

vec4 me;

vec4 n1;

vec4 n2;

vec4 n3;

vec4 merge;

void main () {

x = gl_FragCoord.x/u_resolution.x;

y = 1.0 - gl_FragCoord.y/u_resolution.y ; // flipping texture upside down

p = 1.0/256.0;

// i get error if I don't use u_time and u_mouse,

// but I don't wan't to use them thus min(0.0,max(0.0 ...

p+= min(0.0,max(0.0,u_time+u_mouse.x));

me =texture2D( texture , vec2( x+p , y ) );

n1 = texture2D( texture , vec2( x-p , y ) );

n2 = texture2D( texture , vec2( x , y+p ) );

n3 = texture2D( texture , vec2( x , y-p ) );

merge = (me+n1+n2+n3)/4.0;

gl_FragColor = merge;

}

Don't know if mod is slow or if they rejected it...

Anyways not intending to spam but anyways...

I have a bit unusual goal with learning GLSL, I wan't to eventually do things like this...

https://www.youtube.com/watch?v=cd-ZNymt6Ko

But I decided to start with something simpler to learn from, a post-processing anti-aliasing.

But even that is too hard.

I wan't to read from and write to a couple "persistent" textures aswell as gl_FragColor,

so that I can do multiple passes, but just one pass each frame.

Maybe buffer objects is what I need?

Here's what I came up with, which isn't much...

#ifdef GL_ES

precision mediump float;

#endif

uniform sampler2D texture;

uniform vec2 u_resolution;

uniform vec3 u_mouse;

uniform float u_time;

float x;

float y;

float p; // pixel

vec4 me;

vec4 n1;

vec4 n2;

vec4 n3;

vec4 merge;

void main () {

x = gl_FragCoord.x/u_resolution.x;

y = 1.0 - gl_FragCoord.y/u_resolution.y ; // flipping texture upside down

p = 1.0/256.0;

// i get error if I don't use u_time and u_mouse,

// but I don't wan't to use them thus min(0.0,max(0.0 ...

p+= min(0.0,max(0.0,u_time+u_mouse.x));

me =texture2D( texture , vec2( x+p , y ) );

n1 = texture2D( texture , vec2( x-p , y ) );

n2 = texture2D( texture , vec2( x , y+p ) );

n3 = texture2D( texture , vec2( x , y-p ) );

merge = (me+n1+n2+n3)/4.0;

gl_FragColor = merge;

}