1

我正在尝试将 opengl 的 glsl 转换为 opengl es 的 glsl。

这是我要翻译的 glsl 代码。

  • 对于顶点着色器

    varying vec2 texcoord0;
    varying vec2 texcoord1;
    varying vec2 texcoord2;
    varying vec2 texcoord3;
    varying vec2 texcoord4;
    varying vec2 texdim0;
    
    varying vec2 texcoordLUT;
    
    uniform float sharpness;
    
    void main()
    {
        gl_Position = ftransform();
    
        texcoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
        texcoordLUT = vec2(gl_TextureMatrix[1] * gl_MultiTexCoord1);
        texdim0 = vec2 (abs(gl_TextureMatrix[0][0][0]),abs(gl_TextureMatrix[0][1][1]));
    
        texcoord1 = texcoord0 + vec2(-sharpness, -sharpness);
        texcoord2 = texcoord0 + vec2(+sharpness, -sharpness);
        texcoord3 = texcoord0 + vec2(+sharpness, +sharpness);
        texcoord4 = texcoord0 + vec2(-sharpness, +sharpness);
    
    }
    
  • 对于片段着色器

    uniform float amount;
    uniform float vignette;
    
    uniform sampler4DRect tex0;
    uniform sampler1D tex1;
    
    varying vec2 texcoord0;
    varying vec2 texcoord1;
    varying vec2 texcoord2;
    varying vec2 texcoord3;
    varying vec2 texcoord4;
    
    varying vec2 texdim0;
    
    varying vec2 texcoordLUT;
    
    const vec4 one = vec4(1.0); 
    const vec4 two = vec4(2.0);
    const vec4 lumcoeff = vec4(0.299,0.587,0.114, 0.);
    
    vec4 vignetteFucntion(vec2 normalizedTexcoord)
    {
        normalizedTexcoord = 2.0 * normalizedTexcoord - 1.0;
        float r = length(normalizedTexcoord);
        return 1.0 - vec4(smoothstep(0.5,1.0,r)) + 0.5;
    }
    
    vec4 hardlight(vec4 a, vec4 b, float amount)
    {
        vec4 result;
        vec4 branch1;
        vec4 branch2;
        float luminance = dot(b,lumcoeff);
        float mixamount;
    
        mixamount = clamp((luminance - 0.45) * 10., 0., 1.);
        branch1 = two * a * b;
        branch2 = one - (two * (one - a) * (one - b));
    
        result =  mix(branch1,branch2, vec4(mixamount));
    
        return mix(a,result, amount);
    }
    
    void main (void) 
    {       
        vec2 normcoord = texcoord0/texdim0;
    
        vec4 vignetteResult = vignetteFucntion(normcoord);
    
        vec4 input0 = texture2DRect(tex0, texcoord0);
        vec4 input1 = texture2DRect(tex0, texcoord1);
        vec4 input2 = texture2DRect(tex0, texcoord2);
        vec4 input3 = texture2DRect(tex0, texcoord3);
        vec4 input4 = texture2DRect(tex0, texcoord4);
    
        vec4 sharpened = 5.0 * input0 - (input1 + input2 + input3 + input4);
    
        vec4 hardlighted = hardlight(sharpened,input0, .5);
    
        vec4 saturated = mix(vec4(dot(hardlighted,lumcoeff)), hardlighted, 0.75);
    
        vec4 result;
    
        result.r = texture1D(tex1, saturated.r).r;
        result.g = texture1D(tex1, saturated.g).g;
        result.b = texture1D(tex1, saturated.b).b;
        result.a = saturated.a;
    
        gl_FragColor = mix(input0, result *  (mix(vec4(1.0),vignetteResult, vignette)),amount);
    }
    

我想知道如何翻译 gl_TextureMatrix[0]、gl_TextureMatrix[1] 和 gl_TextureMatrix[0][0][0]。他们的意思是什么?

4

1 回答 1

2

gl_TextureMatrix 是一个变换纹理坐标的变换矩阵(例如,如果您想在静态形状上旋转或缩放纹理。

它是标准 OpenGL 中已弃用的内置变量。在现代 OpenGL/OpenGLES 中处理这个问题的正确方法是声明你自己的统一矩阵而不是使用内置gl_TextureMatrixGL_TEXTURE_MATRIX.

于 2012-09-28T19:30:03.450 回答