Generating Vertices in OpenGL ES 2.0 Vertex Shader -


i trying draw triangle 3 vertices a,b,c. typically, have these 3 vertex co-ordinates in array , pass attribute vertex shader.

but , possible generate these vertex co-ordinates within vertex shader rather passing attribute (i.e. per vertex co-ordinate value corresponding vertex position). if yes, sample program support ?

thanks.

you can create variables in vertex shader , pass fragment shader. example:

vertex shader

 precision highp float;  uniform float u_time; uniform float u_texturesize; uniform mat4  u_mvpmatrix;                     attribute vec4 a_position;  // passed fragment shader. varying vec2 v_texturecoordinate0;  void main()                                  {     // create texture coordinate     v_texturecoordinate0 = a_position.xy / u_texturesize;      gl_position = u_mvpmatrix * a_position; }                                               

and fragment shader:

 precision mediump float;  uniform float   u_time; uniform float   u_pixel_amount; uniform sampler2d u_texture0;     // interpolated texture coordinate per fragment. varying vec2 v_texturecoordinate0;  void main(void) {            vec2 size = vec2( 1.0 / u_pixel_amount, 1.0 / u_pixel_amount);         vec2 uv = v_texturecoordinate0 - mod(v_texturecoordinate0,size);         gl_fragcolor = texture2d( u_texture0, uv );         gl_fragcolor.a=1.0; }  

how can see, vector 2d named v_texturecoordinate0 created in vertex shader , interpolated value used in fragment shader.

i hope you.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -