Opengl 将float传递给GLSL着色器不起任何作用

Opengl 将float传递给GLSL着色器不起任何作用,opengl,glsl,shader,Opengl,Glsl,Shader,我在将光泽度因子发送到凹凸贴图着色器时遇到问题。 结果总是这样: 但是如果我将着色器中的值硬编码为0.0,它就可以正常工作。 当我将0.0发送到着色器时,结果与上图类似 有什么想法吗 这是我的着色器 #version 110 uniform sampler2D tex; uniform sampler2D bmap; uniform bool boolBump; uniform vec4 vecColor; uniform bool onlyColor; uniform float fTr

我在将光泽度因子发送到凹凸贴图着色器时遇到问题。 结果总是这样:

但是如果我将着色器中的值硬编码为0.0,它就可以正常工作。 当我将0.0发送到着色器时,结果与上图类似

有什么想法吗

这是我的着色器

#version 110

uniform sampler2D tex;
uniform sampler2D bmap;

uniform bool boolBump;
uniform vec4 vecColor;
uniform bool onlyColor;

uniform float fTransparencyThresh;
uniform float fShininess;
uniform float alpha;

varying vec3 vecLight;
varying vec3 vecEye;
varying vec3 vecNormal;

vec4 getLighting()
{
    //Ambient part
    vec4 color = (gl_FrontLightModelProduct.sceneColor * gl_FrontMaterial.ambient) + (gl_LightSource[0].ambient * gl_FrontMaterial.ambient);

    //For bump mapping, the normal comes from the bump map texture lookup
    vec3 n = normalize(vecNormal);
    if(boolBump)
    {
         n = normalize(texture2D(bmap, gl_TexCoord[0].st).xyz * 2.0 - 1.0);
    }

    vec3 l = normalize(vecLight);

    //Lambert term
    float NdotL = dot(n, l);

    if(NdotL > 0.0)
    {
        //Diffuse part
        color += gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse * max(0.0, NdotL);

        //Specular part
        vec3 e = normalize(vecEye);
        vec3 r = normalize(-reflect(l,n));  

        float spec = pow(max(0.0, dot(r, e)), fShininess);

        color += gl_LightSource[0].specular * gl_FrontMaterial.specular * spec;
    }

    return color;
}

void main(void)
{
    vec4 texel = texture2D(tex, gl_TexCoord[0].st);
    if(texel.a < fTransparencyThresh)
        discard;

    //Get shading
        vec4 color = getLighting();

    //Color only mode?
    if(onlyColor)
    {
        color *= vecColor;
    }
    else
    {
        color *= texel;
    }   

    //Set fragment color, alpha comes from MTL file
    gl_FragColor = vec4(color.xyz, alpha);
}
编辑:即使这样也不行:

GLint loc = glGetUniformLocation(curShader->program, "fShininess");
glUniform1f(loc, 0.0f);

当您调用glUniform时,是否确保程序处于活动绑定状态?您是否在任何地方检查了glGetError?

请注意,pow(0,0)未定义。这意味着如果
dot(r,e)=0
fShininess==0
,则
spec
是未定义的。请同时显示opengl代码。编辑了它,很抱歉忘记了:)不,我没有,但其他值似乎没有问题。如果我去掉镜面反射部分或将其设置为0.0,则照明效果良好。如果程序未绑定,则不会出现这种情况,对吗?请手动检查glGetError和glGetUniformLocation的返回值。它可以节省大量的调试时间来确定。错误总是0位置是3这是与闪烁loc=。。。上面的代码这真的很奇怪,如果我发送0.0f,我会得到所有这些黑色的工件,但是如果我发送0.1f,看起来很好。我想这就是问题所在。我稍后再查。不过要感谢,如果我将着色器中的fshinness硬编码为0.0,效果会很好。如果我将0.0发送到着色器->黑色斑点。如果在着色器内部将其设置为
0.0f
,会怎么样?我不知道;在UB和我缺乏复杂的知识之间,这很难推测。我想你是说硬代码0.0f?e、 g.:float power=pow(max(0.0,dot(r,e)),0.0f))我做了这个,它工作得很好,这就是为什么我对这个很困惑的原因是的。
0.0
怎么样?还是双电源?在任何情况下,我建议您使用.00001(即0的近似值)或if来解决0^0问题。
GLint loc = glGetUniformLocation(curShader->program, "fShininess");
glUniform1f(loc, 0.0f);