glLinkProgram崩溃即使glCompileShader不返回任何错误 [英] glLinkProgram crashes even though glCompileShader does not return any error

查看:2189
本文介绍了glLinkProgram崩溃即使glCompileShader不返回任何错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从的https://software.intel.com/sites/default/files/managed/79/e5/OpenGL%20ES%20Tessellation.zip我的三星Galaxy S5工作。我在code禁用的Tessellation。

我也改变了code使用OpenGLS ES 3.0。

该程序运行,并成功地编译连接着色器,但该程序编译着色器调用glLinkProgram时,glLinkProgram崩溃。编译着色器并没有在那个时候没有错误当程序调用glError。

有人可以帮助我如何调试呢?

  // ------------------------------------ --------------------------------------------------
//版权所有2014年,英特尔公司
// 版权所有
//
//被授权使用,复制,分发和prepare这个衍生作品
//软件用于任何目的,不收取费用,但前提条件是以上版权声明
//及本声明出现在所有副本。英特尔做对没有重新presentations
//这个软件用于任何用途的适用性。本软件提供的原样。
// Intel专门不作任何担保,EX $ P $干燥综合征或暗示的保证,和所有责任,
//包括后果等间接损失,本软件的使用,
//包括责任不侵犯任何专有权利,并包括
//适销性和针对特定用途的担保。英特尔不
//承担任何错误,这可能出现在该软件也没有任何承担任何责任
//负责更新它。
// ------------------------------------------------ --------------------------------------
//通过ShaderGenerator.exe版本0.13生成
// ------------------------------------------------ --------------------------------------在这两个着色器//雾的颜色
// Skybox的常量浮TessellationHeight = 5500.0; //在高度地图1.0(高度图* TessellationHeight)的高度const int的NumLights = 2;
常量VEC3 LightDirections [NumLights] = VEC3 [](VEC3(-1.0,-1.0,-1.0)
                                                VEC3(0.5,-1.0,1.0));
常量VEC3 LightColors [NumLights] = VEC3 [](VEC3(0.362,0.526,0.575),
                                            VEC3(0.630,0.914,1.0));// -------------------------------------
布局(std140,row_major)统一cbPerModelValues
{
   mat4世界;
   mat4 NormalMatrix;
   mat4 WorldViewProjection;
   mat4 InverseWorld;
   mat4 LightWorldViewProjection;
   vec4 BoundingBoxCenterWorldSpace;
   vec4 BoundingBoxHalfWorldSpace;
   vec4 BoundingBoxCenterObjectSpace;
   vec4 BoundingBoxHalfObjectSpace;
};// -------------------------------------
布局(std140,row_major)统一cbPerFrameValues
{
   mat4查看;
   mat4 InverseView;
   mat4投影;
   mat4 ViewProjection;
   vec4 AmbientColor;
   vec4 LightColor;
   vec4 LightDirection;
   vec4 EyePosition;
   vec4 MaxTessellation;
};
// -------------------------------------
统一sampler2D Texture0;
统一sampler2D Texture1;
统一sampler2D纹理2;
// -------------------------------------
#IFDEF GLSL_VERTEX_SHADER
precision highp浮动;#定义位置0
#定义师范大学1
#定义BINORMAL 2
#定义3相切
#定义颜色4
#定义TEXCOORD0 5
// -------------------------------------
在VEC3位置布局(位置=位置); //突出位置
在VEC3正常布局(位置= NORMAL);
布局(位置=角正切)在VEC3切线;
布局(位置= BINORMAL)在VEC3副法线;
在VEC2 UV0布局(位置= TEXCOORD0);
// -------------------------------------
出vec4 outPosition;
出VEC3 outNormal;
出VEC3 outTangent;
出VEC3 outBinormal;
出VEC2 outUV0;
出VEC3 outWorldPosition; //对象空间中的位置
#ENDIF // GLSL_VERTEX_SHADER
#IFDEF GLSL_FRAGMENT_SHADER
precision highp浮动;
// -------------------------------------
在vec4 outPosition;
在VEC3 outNormal;
在VEC3 outTangent;
在VEC3 outBinormal;
在VEC2 outUV0;
在VEC3 outWorldPosition; //对象空间中的位置
在VEC3 outTriDistance;
// -------------------------------------
vec4 DIFFUSETMP()
{
    返回质地(Texture0,(((outUV0))*(20.0)));
}// -------------------------------------
vec4标准()
{
    返回质地(Texture1,(((outUV0))*(1.0)))* 2.0 - 1.0;
}// -------------------------------------
vec4 AOMAP()
{
    返回质地(纹理2,(((outUV0))*(1.0)));
}// -------------------------------------
vec4漫()
{
    vec4漫= DIFFUSETMP()* AOMAP();
#IFDEF OPENGL_ES
    diffuse.rgb = POW(diffuse.rgb,VEC3(2.2));
#万一
    返回漫* vec4(2.0);
}// -------------------------------------
vec4 AMBIENT()
{
    返回漫();
}// -------------------------------------
#ENDIF // GLSL_FRAGMENT_SHADER#IFDEF GLSL_VERTEX_SHADER
// -------------------------------------
无效的主要()
{
    outPosition = vec4(位置1.0);
    outWorldPosition =(outPosition *世界)名为.xyz;
    outNormal =正常* mat3(世界);
    outTangent =切线* mat3(世界);
    outBinormal = BINORMAL * mat3(世界);
    outUV0 = UV0;
}#ENDIF // GLSL_VERTEX_SHADER
#IFDEF GLSL_TESS_CONTROL_SHADERprecision highp浮动;#IFDEF OPENGL_ES
#extension GL_INTEL_tessellation:要求
#万一布局(顶点= 3)的;在vec4 outPosition [];
在VEC3 outNormal [];
在VEC3 outTangent [];
在VEC3 outBinormal [];
在VEC2 outUV0 [];
在VEC3 outWorldPosition [];出vec4 tcPosition [3];
出VEC3 tcNormal [3];
出VEC3 tcTangent [3];
出VEC3 tcBinormal [3];
出VEC2 tcUV0 [3];
出VEC3 tcWorldPosition [3];浮球液位(浮点D)
{
    D = D / 55000.0; // D = [0..1]
    浮S =钳(1.0 *(D),0.0,1.0);
    返回混合物(MaxTessellation.x,1.0,S);
}
无效的主要()
{
    tcPosition [gl_InvocationID] = outPosition [gl_InvocationID]
    tcWorldPosition [gl_InvocationID] = outWorldPosition [gl_InvocationID]    tcNormal [gl_InvocationID] = outNormal [gl_InvocationID]
    tcBinormal [gl_InvocationID] = outBinormal [gl_InvocationID]
    tcTangent [gl_InvocationID] = outTangent [gl_InvocationID]
    tcUV0 [gl_InvocationID] = outUV0 [gl_InvocationID]    如果(gl_InvocationID == 0){
        VEC3坎波斯= EyePosition.xyz;        浮D0 =距离(坎波斯,outWorldPosition [0]);
        浮D1 =距离(坎波斯,outWorldPosition [1]);
        浮D2 =距离(坎波斯,outWorldPosition [2]);        gl_TessLevelOuter [2] =等级(混合物(D0,d1,0.5));
        gl_TessLevelOuter [0] =等级(混合物(D1,d2,0.5));
        gl_TessLevelOuter [1] =等级(混合物(D2,d0,0.5));        浮内=最大值(最大(gl_TessLevelOuter [0],gl_TessLevelOuter [1]),gl_TessLevelOuter [2]);
        gl_TessLevelInner [0] =内;
    }
}#ENDIF // GLSL_TESS_CONTROL_SHADER#IFDEF GLSL_TESS_EVALUATION_SHADERprecision highp浮动;#IFDEF OPENGL_ES
#extension GL_INTEL_tessellation:要求
#ENDIF // OPENGL_ES布局(三角形,fractional_odd_spacing,CCW)的;在vec4 tcPosition [];
在VEC3 tcNormal [];
在VEC3 tcTangent [];
在VEC3 tcBinormal [];
在VEC2 tcUV0 [];
在VEC3 tcWorldPosition [];出vec4 outPosition;
出VEC3 outNormal;
出VEC3 outTangent;
出VEC3 outBinormal;
出VEC2 outUV0;
出VEC3 outWorldPosition;VEC2插值(VEC2一,VEC2 B,VEC2 C)
{
    VEC2 P0 = VEC2(gl_TessCoord.x)* A;
    VEC2 P1 = VEC2(gl_TessCoord.y)* B;
    VEC2 P2 = VEC2(gl_TessCoord.z​​)* C;
    返回P0 + P1 + P2;
}
VEC3插值(VEC3一,VEC3 B,VEC3 C)
{
    VEC3 P0 = VEC3(gl_TessCoord.x)* A;
    VEC3 P1 = VEC3(gl_TessCoord.y)* B;
    VEC3 P2 = VEC3(gl_TessCoord.z​​)* C;
    返回P0 + P1 + P2;
}
vec4插值(vec4一,vec4 B,vec4 C)
{
    vec4 P0 = vec4(gl_TessCoord.x)* A;
    vec4 P1 = vec4(gl_TessCoord.y)* B;
    vec4 P2 = vec4(gl_TessCoord.z​​)* C;
    返回P0 + P1 + P2;
}无效的主要()
{
    outPosition =内插(tcPosition [0],tcPosition [1],tcPosition [2]);
    outUV0 =内插(tcUV0 [0],tcUV0 [1],tcUV0 [2]);
    outWorldPosition =内插(tcWorldPosition [0],tcWorldPosition [1],tcWorldPosition [2]);
    outNormal =内插(tcNormal [0],tcNormal [1],tcNormal [2]);
    outTangent =内插(tcTangent [0],tcTangent [1],tcTangent [2]);
    outBinormal =内插(tcBinormal [0],tcBinormal [1],tcBinormal [2]);    浮Y =质地(Texture1,(outUV0))A * TessellationHeight。
    outPosition.y = Y;    outPosition = outPosition * WorldViewProjection;    GL_POSITION = outPosition;
}
#ENDIF // GLSL_TESS_EVALUATION_SHADER#IFDEF GLSL_FRAGMENT_SHADER
出vec4 fragColor; // -------------------------------无效的主要()
{
    vec4结果= vec4(0.0,0.0,0.0,1.0);    VEC3正常= outNormal;
    VEC3切线= outTangent;
    VEC3副法线= outBinormal;
    mat3 tangentToWorld = mat3(切线,副法线,正常);
    正常=正常化(tangentToWorld *标准()BGR);
    浮shadowAmount = 1.0;    //环境相关的计算
    VEC3环境= AmbientColor.rgb *环境()RGB。
    result.xyz + =环境;
    VEC3 lightDirection = -LightDirection.xyz;    //弥漫相关计算
    VEC3反照率=漫()RGB。    为(中间体二= 0; II蛋白酶NumLights ++ⅱ){
        lightDirection = -LightDirections [Ⅱ];
        浮nDotL = MAX(0.0,点(正常,lightDirection));
        VEC3弥漫= LightColors [II] * nDotL * shadowAmount *反照率;
        result.xyz + =漫*(1.0 /浮点(NumLights));
    }    fragColor =结果;    常量vec4 FogColor = vec4(0.211,0.223,0.226,1.0);
    常量浮MinFogDistance = 5000.0;
    常量浮MaxFogDistance = 75000.0;
    浮DIST =距离(outWorldPosition,EyePosition.xyz);
    浮fog_factor =钳((MaxF​​ogDistance - DIST)/(MaxF​​ogDistance - MinFogDistance),0.0,1.0);
    fragColor =混合(fragColor,FogColor,1.0 fog_factor);    #IFDEF OPENGL_ES
    fragColor.rgb = POW(fragColor.rgb,VEC3(0.454545454545));
    #万一
}#ENDIF // GLSL_FRAGMENT_SHADER


解决方案

这个问题可以来自于它不受所有的实现支持的片段着色器阵列的动态索引。 (请参见 https://www.khronos.org/files/opengles_shading_language.pdf P103。请注意,这是确定的顶点着色器...)

在您的code:

 的for(int II = 0; II蛋白酶NumLights ++ II){
    lightDirection = -LightDirections [Ⅱ];
    浮nDotL = MAX(0.0,点(正常,lightDirection));
    VEC3弥漫= LightColors [II] * nDotL * shadowAmount *反照率;
    result.xyz + =漫*(1.0 /浮点(NumLights));
}

尝试用恒定的索引进行调试。由XXX更换所有XXX [II] [0]。如果按照这种方式,那么你很可能面临这样的动态索引限制。

一个的hackish办法绕过这个问题:使用浮动for循环和创建循环体的int VAR:

 浮动NumLights_f =浮动(NumLights);
为(浮动ii_f = 0; ii_f< NumLights_f ++ ii_f){
    INT II = INT(ii_f);
    lightDirection = -LightDirections [Ⅱ];
    浮nDotL = MAX(0.0,点(正常,lightDirection));
    VEC3弥漫= LightColors [II] * nDotL * shadowAmount *反照率;
    result.xyz + =漫*(1.0 /浮点(NumLights));
}

由于某些原因,它解决了我类似的错误。我不是GLSL-ES大师,我很好奇,为什么这项工作。它可能正值性能损失的代价......难道是因为循环展开? INT(ii_f)就像是一个不断展开后?

I am trying to make the native code from https://software.intel.com/sites/default/files/managed/79/e5/OpenGL%20ES%20Tessellation.zip work on my Samsung Galaxy S5. I have disabled Tessellation in the code.

I have also changed the code to use OpenGLS ES 3.0.

The program runs and successfully compiles the attached shader but when the program calls glLinkProgram with compiled shader, glLinkProgram crashes. The program calls glError when compiling the shader and there is no error at that time.

Can someone help me how to debug this?

//--------------------------------------------------------------------------------------
// Copyright 2014 Intel Corporation
// All Rights Reserved
//
// Permission is granted to use, copy, distribute and prepare derivative works of this
// software for any purpose and without fee, provided, that the above copyright notice
// and this statement appear in all copies.  Intel makes no representations about the
// suitability of this software for any purpose.  THIS SOFTWARE IS PROVIDED "AS IS."
// INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, AND ALL LIABILITY,
// INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE,
// INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  Intel does not
// assume any responsibility for any errors which may appear in this software nor any
// responsibility to update it.
//--------------------------------------------------------------------------------------
// Generated by ShaderGenerator.exe version 0.13
//--------------------------------------------------------------------------------------

// Fog color in both shaders
// Skybox

const float TessellationHeight = 5500.0; // Height of a 1.0 in the height map (height map * TessellationHeight)

const int NumLights = 2;
const vec3 LightDirections[NumLights] = vec3[]( vec3(-1.0, -1.0,  -1.0),
                                                vec3(0.5, -1.0,  1.0) );
const vec3 LightColors[NumLights] = vec3[]( vec3(0.362, 0.526, 0.575),
                                            vec3(0.630, 0.914, 1.0));

// -------------------------------------
layout (std140, row_major) uniform cbPerModelValues
{
   mat4 World;
   mat4 NormalMatrix;
   mat4 WorldViewProjection;
   mat4 InverseWorld;
   mat4 LightWorldViewProjection;
   vec4 BoundingBoxCenterWorldSpace;
   vec4 BoundingBoxHalfWorldSpace;
   vec4 BoundingBoxCenterObjectSpace;
   vec4 BoundingBoxHalfObjectSpace;
};

// -------------------------------------
layout (std140, row_major) uniform cbPerFrameValues
{
   mat4  View;
   mat4  InverseView;
   mat4  Projection;
   mat4  ViewProjection;
   vec4  AmbientColor;
   vec4  LightColor;
   vec4  LightDirection;
   vec4  EyePosition;
   vec4  MaxTessellation;
};
// -------------------------------------
uniform sampler2D Texture0;
uniform sampler2D Texture1;
uniform sampler2D Texture2;
// -------------------------------------
#ifdef GLSL_VERTEX_SHADER
precision highp float;

#define POSITION  0
#define NORMAL    1
#define BINORMAL  2
#define TANGENT   3
#define COLOR   4
#define TEXCOORD0 5
// -------------------------------------
layout (location = POSITION)  in vec3 Position; // Projected position
layout (location = NORMAL)    in vec3 Normal;
layout (location = TANGENT)   in vec3 Tangent;
layout (location = BINORMAL)  in vec3 Binormal;
layout (location = TEXCOORD0) in vec2 UV0;
// -------------------------------------
out vec4 outPosition;
out vec3 outNormal;
out vec3 outTangent;
out vec3 outBinormal;
out vec2 outUV0;
out vec3 outWorldPosition; // Object space position 
#endif //GLSL_VERTEX_SHADER
#ifdef GLSL_FRAGMENT_SHADER
precision highp float;
// -------------------------------------
in vec4 outPosition;
in vec3 outNormal;
in vec3 outTangent;
in vec3 outBinormal;
in vec2 outUV0;
in vec3 outWorldPosition; // Object space position 
in vec3 outTriDistance;
// -------------------------------------
vec4 DIFFUSETMP( )
{
    return texture(Texture0,(((outUV0)) *(20.0)) );
}

// -------------------------------------
vec4 NORMAL( )
{
    return texture(Texture1,(((outUV0)) *(1.0)) ) * 2.0 - 1.0;
}

// -------------------------------------
vec4 AOMAP( )
{
    return texture(Texture2,(((outUV0)) *(1.0)) );
}

// -------------------------------------
vec4 DIFFUSE( )
{
    vec4 diffuse = DIFFUSETMP() * AOMAP();
#ifdef OPENGL_ES
    diffuse.rgb = pow(diffuse.rgb, vec3(2.2));
#endif
    return diffuse*vec4(2.0);
}

// -------------------------------------
vec4 AMBIENT( )
{
    return DIFFUSE();
}

// -------------------------------------
#endif //GLSL_FRAGMENT_SHADER

#ifdef GLSL_VERTEX_SHADER
// -------------------------------------
void main( )
{
    outPosition = vec4( Position, 1.0);
    outWorldPosition = (outPosition * World).xyz;
    outNormal   = Normal   * mat3(World);
    outTangent  = Tangent  * mat3(World);
    outBinormal = Binormal * mat3(World);
    outUV0 = UV0;
}

#endif //GLSL_VERTEX_SHADER
#ifdef  GLSL_TESS_CONTROL_SHADER

precision highp float;

#ifdef OPENGL_ES
#extension GL_INTEL_tessellation:require
#endif

layout(vertices = 3) out;

in vec4 outPosition[];
in vec3 outNormal[];
in vec3 outTangent[];
in vec3 outBinormal[];
in vec2 outUV0[];
in vec3 outWorldPosition[];

out  vec4  tcPosition[3];
out  vec3  tcNormal[3];
out  vec3  tcTangent[3];
out  vec3  tcBinormal[3];
out  vec2  tcUV0[3];
out  vec3  tcWorldPosition[3];

float level(float d)
{
    d = d/55000.0; // d = [0..1]
    float s = clamp(1.0*(d), 0.0, 1.0);
    return mix(MaxTessellation.x,1.0, s);
}
void main()
{
    tcPosition[gl_InvocationID] = outPosition[gl_InvocationID];
    tcWorldPosition[gl_InvocationID] = outWorldPosition[gl_InvocationID];

    tcNormal[gl_InvocationID] = outNormal[gl_InvocationID];
    tcBinormal[gl_InvocationID] = outBinormal[gl_InvocationID];
    tcTangent[gl_InvocationID] = outTangent[gl_InvocationID];
    tcUV0[gl_InvocationID] = outUV0[gl_InvocationID];

    if(gl_InvocationID == 0) {
        vec3 CamPos = EyePosition.xyz;

        float d0 = distance(CamPos, outWorldPosition[0]);
        float d1 = distance(CamPos, outWorldPosition[1]);
        float d2 = distance(CamPos, outWorldPosition[2]);

        gl_TessLevelOuter[2] = level(mix(d0,d1,0.5));
        gl_TessLevelOuter[0] = level(mix(d1,d2,0.5));
        gl_TessLevelOuter[1] = level(mix(d2,d0,0.5));

        float inner = max(max(gl_TessLevelOuter[0], gl_TessLevelOuter[1]),gl_TessLevelOuter[2]);
        gl_TessLevelInner[0] = inner;
    }
}

#endif  //GLSL_TESS_CONTROL_SHADER

#ifdef GLSL_TESS_EVALUATION_SHADER

precision highp float;

#ifdef OPENGL_ES
#extension GL_INTEL_tessellation:require
#endif // OPENGL_ES

layout(triangles,fractional_odd_spacing,ccw) in;

in  vec4  tcPosition[];
in  vec3  tcNormal[];
in  vec3  tcTangent[];
in  vec3  tcBinormal[];
in  vec2  tcUV0[];
in  vec3  tcWorldPosition[];

out vec4 outPosition;
out vec3 outNormal;
out vec3 outTangent;
out vec3 outBinormal;
out vec2 outUV0;
out vec3 outWorldPosition;

vec2 interpolate(vec2 a, vec2 b, vec2 c)
{
    vec2 p0 = vec2(gl_TessCoord.x) * a;
    vec2 p1 = vec2(gl_TessCoord.y) * b;
    vec2 p2 = vec2(gl_TessCoord.z) * c;
    return p0+p1+p2;
}
vec3 interpolate(vec3 a, vec3 b, vec3 c)
{
    vec3 p0 = vec3(gl_TessCoord.x) * a;
    vec3 p1 = vec3(gl_TessCoord.y) * b;
    vec3 p2 = vec3(gl_TessCoord.z) * c;
    return p0+p1+p2;
}
vec4 interpolate(vec4 a, vec4 b, vec4 c)
{
    vec4 p0 = vec4(gl_TessCoord.x) * a;
    vec4 p1 = vec4(gl_TessCoord.y) * b;
    vec4 p2 = vec4(gl_TessCoord.z) * c;
    return p0+p1+p2;
}

void main()
{
    outPosition = interpolate(tcPosition[0],tcPosition[1],tcPosition[2]);
    outUV0 = interpolate(tcUV0[0],tcUV0[1],tcUV0[2]);
    outWorldPosition = interpolate(tcWorldPosition[0],tcWorldPosition[1],tcWorldPosition[2]);
    outNormal = interpolate(tcNormal[0],tcNormal[1],tcNormal[2]);
    outTangent = interpolate(tcTangent[0],tcTangent[1],tcTangent[2]);
    outBinormal = interpolate(tcBinormal[0],tcBinormal[1],tcBinormal[2]);

    float y = texture(Texture1,(outUV0)).a * TessellationHeight;
    outPosition.y = y;

    outPosition   = outPosition * WorldViewProjection;

    gl_Position = outPosition;
}
#endif  //GLSL_TESS_EVALUATION_SHADER

#ifdef GLSL_FRAGMENT_SHADER
out vec4 fragColor;// -------------------------------------

void main( )
{
    vec4 result = vec4(0.0,0.0,0.0,1.0);

    vec3 normal   = outNormal;
    vec3 tangent  = outTangent;
    vec3 binormal = outBinormal;
    mat3 tangentToWorld = mat3(tangent, binormal, normal);
    normal = normalize( tangentToWorld * NORMAL().bgr );
    float  shadowAmount = 1.0;

    // Ambient-related computation
    vec3 ambient = AmbientColor.rgb * AMBIENT().rgb;
    result.xyz +=  ambient;
    vec3 lightDirection = -LightDirection.xyz;

    // Diffuse-related computation
    vec3 albedo = DIFFUSE().rgb;

    for(int ii=0; ii<NumLights; ++ii) {
        lightDirection = -LightDirections[ii];
        float  nDotL = max( 0.0,dot( normal, lightDirection ) );
        vec3 diffuse = LightColors[ii] * nDotL * shadowAmount  * albedo;
        result.xyz += diffuse * (1.0/float(NumLights));
    }

    fragColor =  result;

    const vec4 FogColor = vec4(0.211,0.223,0.226,1.0);
    const float MinFogDistance = 5000.0;
    const float MaxFogDistance = 75000.0;
    float dist = distance(outWorldPosition, EyePosition.xyz);
    float fog_factor = clamp((MaxFogDistance - dist)/(MaxFogDistance - MinFogDistance),0.0,1.0);
    fragColor =  mix(fragColor,FogColor,1.0-fog_factor);

    #ifdef OPENGL_ES
    fragColor.rgb = pow(fragColor.rgb, vec3(0.454545454545));
    #endif
}

#endif //GLSL_FRAGMENT_SHADER

解决方案

The problem can come from dynamic indexing of array in a fragment Shader which is not supported by all the implementations. (see https://www.khronos.org/files/opengles_shading_language.pdf p103. Note that it's OK in vertex shaders...)

In your code :

for(int ii=0; ii<NumLights; ++ii) {
    lightDirection = -LightDirections[ii];
    float  nDotL = max( 0.0,dot( normal, lightDirection ) );
    vec3 diffuse = LightColors[ii] * nDotL * shadowAmount  * albedo;
    result.xyz += diffuse * (1.0/float(NumLights));
}

Try to debug with constant indexing. Replace all xxx[ii] by xxx[0]. If it work that way, then you're probably facing this dynamic indexing limitation.

One hackish way to bypass this issue : use float for loops and create an int var in the loop body:

float NumLights_f = float(NumLights);
for(float ii_f=0.; ii_f<NumLights_f; ++ii_f) {
    int ii = int(ii_f);
    lightDirection = -LightDirections[ii];
    float  nDotL = max( 0.0,dot( normal, lightDirection ) );
    vec3 diffuse = LightColors[ii] * nDotL * shadowAmount  * albedo;
    result.xyz += diffuse * (1.0/float(NumLights));
}

For some reason, it solved my similar bug. I'm no glsl-es guru, I'm curious about WHY this work. And it may comes at the price of performance penalty... Is it because of loops unroll ? int(ii_f) is like a constant after unrolling ?

这篇关于glLinkProgram崩溃即使glCompileShader不返回任何错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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