Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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
GLSL着色器不需要的灰度效果_Glsl_Shader_Fragment Shader_Vertex Shader_Pixel Shader - Fatal编程技术网

GLSL着色器不需要的灰度效果

GLSL着色器不需要的灰度效果,glsl,shader,fragment-shader,vertex-shader,pixel-shader,Glsl,Shader,Fragment Shader,Vertex Shader,Pixel Shader,让我先说一句,我对GLSL非常陌生 我试图使用着色器在插槽卷轴符号旋转时为其添加模糊效果。我有一个正在运行的模糊效果,为了简单和隔离这个问题,我已经把它注释掉了 顶点着色器: //Vertex Shader attribute vec4 position; attribute vec4 inColor; attribute vec2 inUV; //To be passed to the Fragment Shader "BlurShader.fsh" varying vec4 colorVa

让我先说一句,我对GLSL非常陌生

我试图使用着色器在插槽卷轴符号旋转时为其添加模糊效果。我有一个正在运行的模糊效果,为了简单和隔离这个问题,我已经把它注释掉了

顶点着色器:

//Vertex Shader
attribute vec4 position;
attribute vec4 inColor;
attribute vec2 inUV;

//To be passed to the Fragment Shader "BlurShader.fsh"
varying vec4 colorVarying;
varying vec2 uvOut;

void main()
{
    colorVarying = inColor;
    gl_Position = position;
    uvOut = inUV;
}
片段着色器:

//Fragment Shader

uniform sampler2D tex0;

//Passed from Vertex Shader "BlurShader.vsh"
varying vec4 colorVarying; //ISSUE: this is always solid white
varying vec2 uvOut;

//This is the intensity of the blur. Higher is a larger blur
//  25 is a good starting point
//  Could possibly make it a varible to be passed in to control directly from Lua
#define INTENSITY 25.0

vec4 BlurVertical(vec2 size, vec2 uv, float radius) {
    if (radius >= 1.0)
    {
        vec4 C = vec4(0.0); 
        float height = 1.0 / size.y;
        float divisor = 0.0; 

        for (float y = -radius; y <= radius; y++)
        {
            C += texture(tex0, uv + vec2(0.0, y * height));
            divisor++; 
        }
        return vec4(C.r / divisor, C.g / divisor, C.b / divisor, 1.0);
    }
    return texture2D(tex0, uv);
}

void main()
{
    //Apply blur to final output
    //gl_FragColor = BlurVertical(textureSize(tex0, 0), uvOut, INTENSITY);
    //gl_FragColor = texture2D(tex0, uvOut) * colorVarying; SAME RESULT
    gl_FragColor = texture2D(tex0, uvOut);
}
//片段着色器
均匀采样2d-tex0;
//从顶点着色器“BlurShader.vsh”传递
变化的vec4颜色变化//问题:这始终是纯白色
可变vec2输出;
//这是模糊的强度。越高,模糊度越大
//25岁是一个很好的起点
//可能会使它成为一个变量,直接从Lua传入控制
#定义强度25.0
vec4模糊垂直(vec2大小、vec2 uv、浮动半径){
如果(半径>=1.0)
{
vec4 C=vec4(0.0);
浮动高度=1.0/尺寸y;
浮点除数=0.0;

对于(float y=-radius;y找到了解决方案!我使用的纹理是用YUVA编码的,因此实际上我需要对4个纹理进行采样,然后转换为单个RGBA

uniform sampler2D tex[4];

vec4 YUVAtoRGBA() 
{
    mat4 xForm = mat4(
        1.164, 1.164, 1.164, 0.0,
        0.0, -0.391, 2.018, 0.0,
        1.596, -0.813, 0.0, 0.0,
        0.0, 0.0, 0.0, 1.0);

    vec4 yuva = vec4(
        texture2D(tex[0], (uvOut.xy / uvOut.z).x - 0.0625,
        texture2D(tex[1], (uvOut.xy / uvOut.z).x - 0.5,
        texture2D(tex[2], (uvOut.xy / uvOut.z).x - 0.5,
        texture2D(tex[3], (uvOut.xy / uvOut.z).x);

    return colorVarying * (xForm * yuva);
}

你如何将纹理加载到GPU?我不完全确定。我正在使用一个大的C++代码库,我不知道它有一个函数,它应该在某处有一个调用,哪些参数?GLTEXIGE2D(GLXTrimeRux2D,0,GLY-RGBA,宽度,高度,0,GLY-RGBA,GLU-unsiNeDd*Byter,缓冲)GLTEXMIGE2D。(GL_纹理_2D,0,GL_亮度,宽度,高度,0,GL_亮度,GL_无符号字节,tmpbuf)