ios - Smooth textured line with OpenGL ES 2.0 shaders -


we have ios drawing app. currently, drawing implemented opengl es 1.1. use algorithms smooth lines such bezier curves. so, when touch events occur, set of points out of touch event points (based on algorithms) , draw these points. use brush texture points have more natural look.

i wonder if it's possible implement these algorithms in opengl es 2.0 shaders. call opengl function draw lines made of touch points , on output have smoothed brush-textured curve rendered.

enter image description here

points p0, p1, ... p4 here touch events , points on red curve - output points, such step t distance between 2 neighbor points on curve not greater 1 pixel.

and here link bezier algorithm explanation: bézier curve - wikipedia, free encyclopedia

any appreciated. thanks.

you cannot generate new vertices inside vertex shader (you can in geometry shader, es doesn't have). number of output vertices same number of input vertices, can change positions (and ohter attributes of course).

so have draw line strip made out of enough vertices guarantee smooth enough curve. can put in same line strip, having curve parameter values t 1d vertex positions. in shader use input position (the parameter value) compute actual 2d/3d position on curve using decasteljau algorithm (or whatever) , points p0 p4 put shader constants (uniform variables in glsl terms).

but i'm not sure if buy on computing points on cpu , putting them dynamic vbo. save copying of curve points cpu gpu , computation on cpu, on other hand vertex shader more complex. needs evaluated better approach. if need compute curve points each frame (because control points change each frame) , curve rather high detail, might not bad idea. otherwise don't think pays. , shader won't adaptable changing number of control points/curve degree @ runtime.

but once again, cannot put in 5 control points , generate n curve points on gpu. vertex shader works on single vertex , results in single vertex, same fragment shader works on single fragment (say pixel, though isn't 1 yet) , result in single (or no) fragment.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -