在片段着色器中通過對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;

}

/////////////////////////////////

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章