GPUImage着色器崩溃,并显示“错误:一个或多个连接的着色器未成功编译". [英] GPUImage shader crashing with "ERROR: One or more attached shaders not successfully compiled"

查看:456
本文介绍了GPUImage着色器崩溃,并显示“错误:一个或多个连接的着色器未成功编译".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试基于有人会认为我应该能够/多或少地复制粘贴着色器块:

One would think I should be able to more/less copy paste the shader block:

@interface GPUImageVibranceFilter : GPUImageFilter
{
    GLint vibranceUniform;
}

// Modifies the saturation of desaturated colors, leaving saturated colors unmodified.
// Value -1 to 1 (-1 is minimum vibrance, 0 is no change, and 1 is maximum vibrance)
@property (readwrite, nonatomic) CGFloat vibrance;

@end

GPUImageVibranceFilter.m

#import "GPUImageVibranceFilter.h"

#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
NSString *const kGPUImageVibranceFragmentShaderString = SHADER_STRING
(
    uniform sampler2D inputImageTexture;
    uniform float vibrance;
    varying highp vec2 textureCoordinate;
    void main() {
        vec4 color = texture2D(inputImageTexture, textureCoordinate);
        float average = (color.r + color.g + color.b) / 3.0;
        float mx = max(color.r, max(color.g, color.b));
        float amt = (mx - average) * (-vibrance * 3.0);
        color.rgb = mix(color.rgb, vec3(mx), amt);
        gl_FragColor = color;
    }
);
#else
NSString *const kGPUImageVibranceFragmentShaderString = SHADER_STRING
(
    uniform sampler2D inputImageTexture;
    uniform float vibrance;
    varying vec2 textureCoordinate;
    void main() {
        vec4 color = texture2D(inputImageTexture, textureCoordinate);
        float average = (color.r + color.g + color.b) / 3.0;
        float mx = max(color.r, max(color.g, color.b));
        float amt = (mx - average) * (-vibrance * 3.0);
        color.rgb = mix(color.rgb, vec3(mx), amt);
        gl_FragColor = color;
    }
);
#endif

@implementation GPUImageVibranceFilter

@synthesize vibrance = _vibrance;

#pragma mark -
#pragma mark Initialization and teardown

- (id)init;
{
    if (!(self = [super initWithFragmentShaderFromString:kGPUImageVibranceFragmentShaderString]))
    {
        return nil;
    }

    vibranceUniform = [filterProgram uniformIndex:@"vibrance"];
    self.vibrance = 0.0;

    return self;
}

#pragma mark -
#pragma mark Accessors

- (void)setVibrance:(CGFloat)vibrance;
{
    _vibrance = vibrance;

    [self setFloat:_vibrance forUniform:vibranceUniform program:filterProgram];
}

@end

但是无法编译,崩溃:

Failed to compile fragment shader
Program link log: ERROR: One or more attached shaders not successfully compiled
Fragment shader compile log: (null)
Vertex shader compile log: (null)

错误肯定很明显,但是由于对OpenGL ES着色器没有经验,所以我不知道问题出在哪里.

The error is certainly clear, but being inexperienced with OpenGL ES shaders, I have no idea what the problem actually is.

推荐答案

人们会认为我应该能够/多或少地复制粘贴着色器块.

One would think I should be able to more/less copy paste the shader block.

在桌面GLSL中可能是这种情况,但是在OpenGL ES中,您必须先设置精度,然后才能声明float变量(包括从float派生的类型,例如vec2mat4). -片段着色器中的float没有预定义的默认精度.

This might be the case in desktop GLSL, but in OpenGL ES you cannot declare a float variable (this includes types derived from float such as vec2 or mat4 as well) without first setting the precision - there is no pre-defined default precision for float in the fragment shader.

实现保证了片段着色器中对mediumplowp浮点精度的支持.但是,您必须先检查一下,然后再将highp设置为默认值.

Implementations guarantee support for mediump and lowp floating-point precision in the fragment shader. You will have to check before setting highp as the default, however.

这整个问题对我来说是缺少精度" ,但是为什么编译器没有在编译日志中告诉您这一点,我真的不知道.

This whole problem screams "missing precision" to me, but why the compiler is not telling you this in the compile log I really do not know.

      

        Brush up on 4.5.3 Default Precision Qualifiers (pp. 35-36)


请小心使用CGFloat.

根据您的编译目标(主机是32位还是64位),该类型将为单精度或双精度.如果要将声明为CGFloat的内容传递给GL,请停止该= P

Depending on your compile target (whether the host machine is 32-bit or 64-bit), that type will either be single-precision or double-precision. If you are passing something declared CGFloat to GL, stop that =P

请改用GLfloat,因为这将始终是GL要求的单精度.

Use GLfloat instead, because that will always be single-precision as GL requires.

      请参阅

       See a related answer I wrote for more details.

这篇关于GPUImage着色器崩溃,并显示“错误:一个或多个连接的着色器未成功编译".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆