您好,登錄后才能下訂單哦!
膨脹:取一個(gè)像素周圍的點(diǎn),取最亮的點(diǎn)為當(dāng)前的點(diǎn)顏色,為膨脹效果
腐蝕:取一個(gè)像素周圍的點(diǎn),取最暗的點(diǎn)為當(dāng)前的點(diǎn)顏色,為腐蝕效果
膨脹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; }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。