webgl - Using sample2D as position in vertex shader -
i'm learning how manipulate particles fbo in webgl, tried store position texture , use position reference, nothing came on stage.
fragment shaders
precision mediump float; void main() { gl_fragcolor = vec4(vec3(1.0), 1.0); } </script>
vertex render shader script
attribute vec2 atextureuv; uniform sampler2d utexture; void main() { vec4 texture = texture2d( utexture, atextureuv ); gl_position = vec4( texture.rgb, 1.0 ); gl_pointsize = 3; } </script>
js script
// determine uvs var uvs = new float32array([ 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0 ]) var uvbuffer = gl.createbuffer(); gl.bindbuffer( gl.array_buffer, uvbuffer ); gl.bufferdata( gl.array_buffer, uvs, gl.static_draw ); gl.enablevertexattribarray( defaultprogram.atextureuvloc ); gl.vertexattribpointer( defaultprogram.atextureuvloc, 2, gl.float, false, 0, 0); // texture initialization for(var = 0; < particlecount; i++) { initialdata.push( math.random(), math.random(), math.random(), 0 ); } var texture = gl.createtexture(); gl.activetexture( gl.texture0 ); gl.bindtexture( gl.texture_2d, texture ); gl.pixelstorei( gl.unpack_alignment, 1 ); gl.teximage2d( gl.texture_2d, 0, gl.rgba, fbowidth, fbowidth, 0, gl.rgba, gl.float, new float32array(initialdata) ); gl.texparameteri(gl.texture_2d, gl.texture_min_filter, gl.nearest); gl.texparameteri(gl.texture_2d, gl.texture_mag_filter, gl.nearest); ..... function draw() { requestanimationframe( draw ); gl.viewport( 0, 0, gl.drawingbufferwidth, gl.drawingbufferheight ); gl.clear( gl.color_buffer_bit | gl.depth_buffer_bit); gl.drawarrays( gl.points, 0, particlecount ); }
can't comment yet, desktop gl remark, can see 1) there no actual draw calls in script i.e. gldrawelements
/gldrawarrays
(unless you've left parts of out), , 2) you're missing fragment shader. refer e.g. this.
Comments
Post a Comment