在片段着色器中通过对uv进行多重变换实现丰富的纹理表现效果(GLSL源码)示例

请见demo:http://www.artvily.com/renderCase?sample=uvMultCalc

//  着色器glsl代码示例(由自研编辑器生成)

// ** vshd_str: 
precision mediump float;
precision mediump int;
layout(location = 0) in vec3 a_vs;
layout(location = 1) in vec2 a_uvs;
uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat4 projectMatrix;
out vec2 v_uvs;

void main()
{
vec4 result4_0 = vec4(0.0);
vec4 vtxVec4;
vtxVec4 = vec4(a_vs.xyz,1.0);
mat4 mModelMat = modelMatrix;
vtxVec4 = mModelMat * vtxVec4;
mat4 mViewMat = viewMatrix;
vtxVec4 = mViewMat * vtxVec4;
mat4 mProjMat = projectMatrix;
vtxVec4 = mProjMat * vtxVec4;
result4_0 = vtxVec4;
gl_Position = result4_0;
v_uvs = a_uvs;

}


// ** fshd_str: 

precision mediump float;
precision mediump int;
uniform sampler2D u_sampler0;
uniform sampler2D u_sampler1;
uniform sampler2D u_sampler2;
in vec2 v_uvs;
layout(location = 0) out vec4 fragOutput0;
const float MATH_PI = 3.1415926;
const float MATH_2PI = 2.0 * MATH_PI;
const float MATH_1PER2PI = 0.5 * MATH_PI;
const float MATH_3PER2PI = 3.0 * MATH_PI * 0.5;
float getRadianByXY(float dx,float dy)
{
    if(abs(dx) < 0.00001)
    {
        if(dy >= 0.0) return MATH_1PER2PI;
        else return MATH_3PER2PI;
    }
    float rad = atan(dy/dx);
    if(dx >= 0.0)
    {
        return rad;
    }
    rad = MATH_PI + rad;
    return rad;
}

void main()
{
vec4 result4_1 = vec4(0.0);
vec4 color4;
color4 = texture(u_sampler0, v_uvs.xy);
result4_1 = color4;
vec4 tex_48_color4 = texture(u_sampler1, v_uvs.xy);
color4 = tex_48_color4;
tex_48_color4.xyz = tex_48_color4.xyz * 2.5;
result4_1.xyz = (result4_1.xyz + tex_48_color4.xyz);
color4 = texture(u_sampler2, v_uvs.xy);
result4_1.xyz = result4_1.xyz * color4.xyz;
vec4 texUV4;
texUV4.xy = (getRadianByXY(v_uvs.x - 0.5, v_uvs.y - 0.5) + abs(v_uvs.xy - vec2(0.5,0.5))) * 2.0;
tex_48_color4 = texture(u_sampler1, texUV4.xy);
color4 = tex_48_color4;
tex_48_color4.xyz = tex_48_color4.xyz * 0.5;
result4_1.xyz = (result4_1.xyz + tex_48_color4.xyz);
vec2 temp_0_RDV2 = vec2(v_uvs.x - 0.5, v_uvs.y - 0.5);
temp_0_RDV2.xy = 0.1 * result4_1.xy + vec2(0.5 + length(temp_0_RDV2) * 0.707);
texUV4.xy = temp_0_RDV2 * 3.0;
tex_48_color4 = texture(u_sampler1, texUV4.xy);
color4 = tex_48_color4;
result4_1.xyz = (result4_1.xyz + tex_48_color4.xyz);
fragOutput0 = result4_1;

}

//

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值