膨胀:取一个像素周围的点,取最亮的点为当前的点颜色,为膨胀效果
腐蚀:取一个像素周围的点,取最暗的点为当前的点颜色,为腐蚀效果
膨胀Fragment Shader
varying vec2 M_coord; varying vec3 M_normal; varying vec3 M_WordPos; uniform sampler2D U_MainTexture; uniform sampler2D U_SubTexture; void main() { vec4 maxValue=vec4(0.0); int coreSize=3; int halfCoreSize=coreSize/2; float texelOffset=1/200.0; for(int y=0;y<coreSize;y++) { for(int x=0;x<coreSize;x++) { vec4 color=texture2D(U_MainTexture, M_coord+vec2((-halfCoreSize+x)*texelOffset, (-halfCoreSize+y)*texelOffset)); maxValue=max(maxValue,color); } } gl_FragColor=maxValue; }
腐蚀Fragment Shader
varying vec2 M_coord; varying vec3 M_normal; varying vec3 M_WordPos; uniform sampler2D U_MainTexture; uniform sampler2D U_SubTexture; void main() { vec4 minValue=vec4(1.0); int coreSize=3; int halfCoreSize=coreSize/2; float texelOffset=1/100.0; for(int y=0;y<coreSize;y++) { for(int x=0;x<coreSize;x++) { vec4 color=texture2D(U_MainTexture, M_coord+vec2((-halfCoreSize+x)*texelOffset, (-halfCoreSize+y)*texelOffset)); minValue=min(minValue,color); } } gl_FragColor=minValue; }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。