davidedc / raspberry-pi-autoVj

automatic motion graphics for raspberry pi using pi3d framework
13 stars 2 forks source link

material alpha fixes from paddywwoof #1

Open davidedc opened 10 years ago

davidedc commented 10 years ago

(see https://github.com/tipam/pi3d/issues/168#issuecomment-35239756 comment from @paddywwoof )

After a quick glance through the code I noticed a comment about the material alpha not working. It's a slightly convoluted history and I can't remember the exact details but basically the material shade is held per Buffer and is just RGB, if you pass a longer list it just slices the first 3! There is an alpha value held in Shape.unif[17] with a method Shape.set_alpha(). When draw() is called there is a check to see if any Textures have blend=True or alpha<1.0 (or fog alpha<1.0) in which case gl blending is enabled, otherwise it's disabled. Then in your fragment shader you need change the hard-coding of alpha=1.0 to unif[5][2] Incidentally, in the gl shader language you can generally do 3 or 4 things in the same time as doing 1 i.e. you can replace (looking at mat_stripe_color.fs) vec4 texc = vec4(f_ri + (1.0-f)rf,fgi + (1.0-f)gf,fbi + (1.0-f)_bf,1.0); with vec4 texc = vec4(mix(unif[16], unfi[17], f), 1.0); (but by setting alpha to 1.0 you can effectively take out lines 23-28 which would be even quicker!) and later gl_FragColor = vec4(unif[16], unif[5][2]); i.e. you can generally work with 3 or 4 component vectors all the way through: rgbi = unif[16]; rgbf = unif[17];