Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将OpenGL GLSL代码转换为OpenGL ES GLSL代码_Opengl_Opengl Es_Glsl - Fatal编程技术网

如何将OpenGL GLSL代码转换为OpenGL ES GLSL代码

如何将OpenGL GLSL代码转换为OpenGL ES GLSL代码,opengl,opengl-es,glsl,Opengl,Opengl Es,Glsl,我正在尝试将glsl for opengl转换为glsl for opengl es 这是我要翻译的glsl代码 对于顶点着色器 varying vec2 texcoord0; varying vec2 texcoord1; varying vec2 texcoord2; varying vec2 texcoord3; varying vec2 texcoord4; varying vec2 texdim0; varying vec2 texcoordLUT; uniform float

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

这是我要翻译的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]。
它们是什么意思?

gl_TextureMatrix是一个变换矩阵,用于变换纹理坐标(例如,如果您希望在静态形状上旋转或缩放纹理)


它是标准OpenGL中不推荐使用的内置变量。在现代OpenGL/OpenGLS中处理此问题的正确方法是声明自己的统一矩阵,而不是使用内置的
gl\u TextureMatrix
,并更新这些统一矩阵,而不是对OpenGL的
gl\u TEXTURE\u矩阵执行旋转/转换

谢谢你的回答。texcoord0=vec2(gl_TextureMatrix[0]*gl_MultiTexCoord0);texcoordLUT=vec2(gl_TextureMatrix[1]*gl_MultiTexCoord1);请你解释一下这些行好吗?我不明白。如果你不知道你已经知道了什么,我就无法解释。你不明白它的具体内容吗?如果OpenGL的某些特定方面让你感到困惑,我可以尝试帮助你,但如果你只是不想解释,我不会解释整个OpenGLo在不了解其工作原理或原因的情况下复制某人的着色器。这是将Lomo效果应用于视频帧的着色器。我将其与GPUImage一起使用。我复制了其他人的代码并试图理解。我在谷歌上搜索,但找不到gl_TextureMatrix的任何描述。据我所知,这是4x4浮点二维数组。我了解例如,浮点gl_TextureMatrix[4][4];但在这段代码中,使用了gl_TextureMatrix[0][0][0],这意味着什么?请帮助我。我相信gl_TextureMatrix实际上是一个由4x4浮点数组组成的数组,因此可以有多个矩阵(这是为了在多文本处理中可以对不同的层进行不同的转换)。因此[0][0][0]只是指索引为0的纹理矩阵的第一行、第一列。若要了解gl_TextureMatrix,您必须了解一般的变换。它只是一个典型的4x4变换矩阵,可以将坐标从一个空间更改为另一个空间。@Piao-另外,我应该补充一点,渐晕、锐化、强光混合等都是非常重要的l作为过滤器内置到GPUImage中,因此您不需要实现自己的版本。其他人通过适当链接它们来创建Lomo效果。您应该能够组装所有这些,而无需编写自己的着色器。