i have shader draws particles solid colors. enable shader sample fbo texture each particle can act upon color "behind" it. seems should pretty simple, no.
i've simplified code such expect fbo drawn on face of every particle, scaled down. ugly, @ least prove particles can sample texture. instead, each particle solid color. i'm using openframeworks, there few abstractions. have verified tex.bind()
binds first texture location, , i'm able apply shaders fbo without gl_points.
here's setup shader, draw fbo, , render particles:
void particles::draw(ofxfbotexture &tex){ glenable(gl_blend); glblendfunc(gl_src_alpha, gl_one); ofenablesmoothing(); glenable(gl_point_sprite_arb); glenable(gl_vertex_program_point_size_arb); gltexenvi(gl_point_sprite_arb, gl_coord_replace, gl_true); shader.begin(); shader.setuniform("winwidth", (float) width); shader.setuniform("winheight", (float) height); tex.draw(0,0); // i've tried tex.bind() here for(int = 0; < lastdead; i++){ allparticles[i]->draw(this->shader); } shader.end(); gldisable(gl_vertex_program_point_size_arb); gldisable(gl_point_sprite_arb); ofdisablesmoothing(); gldisable(gl_blend); } // <snip> void particle::draw(ofxshader &shader){ if(dead) return; // must go outside glbegin shader.setattribute("size", size); shader.setattribute("velocity", xvel, yvel, 0.0); glbegin(gl_points); glcolor4f(r, g, b, multiplier * 0.8); glvertex3f(x, y, 0); glend(); }
here's vertex shader:
#version 120 attribute float size; attribute vec3 velocity; varying vec3 vel; uniform float winwidth; uniform float winheight; void main() { gl_pointsize = size; gl_frontcolor = gl_color; gl_position = gl_modelviewprojectionmatrix * gl_vertex; gl_texcoord[0] = gl_texturematrix[0] * gl_multitexcoord0; vel = velocity; }
... , relevant excerpt fragment shader, simplified debugging:
#version 120 #extension gl_arb_texture_rectangle : enable varying vec3 vel; uniform sampler2drect tex; uniform float winwidth; uniform float winheight; void main() { vec4 texcolor = texture2drect(tex, gl_texcoord[0].st); gl_fragcolor = texcolor; }
instead of gl_texcoord[0].st
need gl_pointcoord.st.
Comments
Post a Comment