• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

GLSL shader 磨砂玻璃效果

武飞扬头像
鱼儿-1226
帮助1

CCProgram vs %{

precision highp float;

#include <cc-global>

in vec3 a_position;

in vec2 a_uv0;

in vec4 a_color;

out vec2 v_uv0;

out vec4 v_color;

void main () {

gl_Position = cc_matViewProj * vec4(a_position, 1);

v_uv0 = a_uv0;

v_color = a_color;

}

}%

CCProgram fs %{

precision highp float;

in vec2 v_uv0;

in vec4 v_color;

uniform sampler2D texture;

uniform Properties {

vec2 size;

};

// 模糊半径

// for 循环的次数必须为常量

const float RADIUS = 20.0;

// 获取模糊颜色

vec4 getBlurColor (vec2 uv) {

vec4 color = vec4(0); // 初始颜色

float sum = 0.0; // 总权重

// 卷积过程

for (float r = -RADIUS; r <= RADIUS; r ) { // 水平方向

float x = uv.x r / size.x;

if (x < 0.0 || x > 1.0) continue;

for (float c = -RADIUS; c <= RADIUS; c ) { // 垂直方向

float y = uv.y c / size.y;

if (y < 0.0 || y > 1.0) continue;

vec2 target = vec2(x, y); // 目标纹理坐标

float weight = (RADIUS - abs(r)) * (RADIUS - abs(c)); // 计算权重

color = texture2D(texture, target) * weight; // 累加颜色

sum = weight; // 累加权重

}

}

color /= sum; // 求出平均值

return color;

}

void main () {

vec4 color = v_color;

color *= texture(texture, v_uv0);

if (color.a != 0.0) {

color = getBlurColor(v_uv0); // 获取模糊后的颜色

}

color.a *= v_color.a; // 还原透明度

gl_FragColor = color;

}

}

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfahfk
系列文章
更多 icon
同类精品
更多 icon
继续加载