cocos2d iphone - How to prevent blur from using colors outside of the texture? -


i'm trying create shader blurs, , i've done that. however, theres 1 problem. around texture there black background, , when shader runs grabbing color background , ends darkening entire image (but still blurs image fine, if lowering brightness). sure thats thought going on, set background white, , sure enough made image duller. don't know how prevent this, suppose grabbing them outside because blur size reaching outside texture boundary, there way prevent texture ups occuring outside of texture i'm dealing with?

frag:

precision mediump float;  uniform sampler2d cc_texture0;   uniform float u_time;  const lowp int samples = 9; varying vec2 v_texcoord;         varying highp vec2 transcord[samples];  void main() {       vec4 sum = vec4(0.0);      sum += texture2d(cc_texture0, transcord[0]) * 0.05;     sum += texture2d(cc_texture0, transcord[1]) * 0.09;     sum += texture2d(cc_texture0, transcord[2]) * 0.12;     sum += texture2d(cc_texture0, transcord[3]) * 0.15;     sum += texture2d(cc_texture0, transcord[4]) * 0.16;     sum += texture2d(cc_texture0, transcord[5]) * 0.15;     sum += texture2d(cc_texture0, transcord[6]) * 0.12;     sum += texture2d(cc_texture0, transcord[7]) * 0.09;     sum += texture2d(cc_texture0, transcord[8]) * 0.05;        gl_fragcolor = sum; } 

vertex shader

precision mediump float;  attribute vec4 a_position; attribute vec2 a_texcoord;  const lowp int samples = 9;  uniform highp float texelwidthoffset; uniform highp float texelheightoffset; uniform highp float blursize; uniform float u_time;  varying vec2 v_texcoord;         varying highp vec2 transcord[samples];  void main() {       gl_position = cc_mvpmatrix * a_position;     v_texcoord = a_texcoord;         highp vec2 offset = vec2(texelwidthoffset, texelheightoffset) * (u_time * blursize);      transcord[0] = a_texcoord - offset * 4.0;     transcord[1] = a_texcoord - offset * 3.0;     transcord[2] = a_texcoord - offset * 2.0;     transcord[3] = a_texcoord - offset * 1.0;     transcord[4] = a_texcoord;     transcord[5] = a_texcoord + offset * 1.0;     transcord[6] = a_texcoord + offset * 2.0;     transcord[7] = a_texcoord + offset * 3.0;     transcord[8] = a_texcoord + offset * 4.0; } 

update: appears issue when rendering on ccrendertexture. i'm not sure why though.

set wrap modes of texture, in both s , t, gl_clamp_to_edge -- mean out-of-range uv coordinate vales return more-sensible results


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -