2012-04-21 4 views
0

shininess 요소를 내 범프 매핑 셰이더에 보내는 데 문제가 있습니다. 결과는 항상 다음과 같습니다 : http://i.imgur.com/unzdx.jpgfloat를 GLSL 셰이더에 전달하면 아무 일도하지 않습니다

그러나 셰이더 내부의 값을 0.0으로 하드 코딩하면 괜찮습니다. 셰이더에 0.0을 보내면 위 그림과 같이됩니다.

아이디어가 있으십니까?

void MyClass::sendToShader(const OBJ::StelModel* pStelModel, Effect cur, bool& tangEnabled, int& tangLocation) 
{ 
    int location; 
    tangEnabled = false; 

    if(cur != No) 
    { 
     location = curShader->uniformLocation("fTransparencyThresh"); 
     curShader->setUniform(location, fTransparencyThresh); 

     location = curShader->uniformLocation("alpha"); 
     curShader->setUniform(location, pStelModel->pMaterial->alpha); 

     location = curShader->uniformLocation("fShininess"); 
     curShader->setUniform(location, 0.0f); 

... 

이 편집 : 비록이 실 거예요 작업 :

은 여기 내 쉐이더

#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); 
} 

편집, OpenGL은 코드의

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

OpenGL 코드도 함께 표시하십시오. – Tim

+0

그것을 편집했습니다, 죄송합니다 그것에 대해 잊어 버렸습니다 :) – Lngly

답변

1

pow (0, 0)는 정의되지 않았습니다. 즉, dot(r, e) == 0fShininess == 0 인 경우 spec은 정의되지 않습니다.

+0

이것이 문제입니다. 나는 나중에 그것을 조사 할 것이다. 고마워요. – Lngly

+0

그래도 셰이더 안의 fshininess를 0.0으로 하드 코딩하면 문제가 없습니다. 0.0을 셰이더 -> 검은 색 점으로 보내면. – Lngly

+0

셰이더 내부에서 '0.0f'로 설정하면 어떨까요? 나는 모른다. UB와 복잡한 지식의 부족 사이에서, 이것은 추측하기가 어렵습니다. – aib

0

당신이 있는지 확인 마십시오는 프로그램이 적극적으로 결합 될 때 너 glUniform이라고? 어디에서나 glGetError를 확인합니까?

+0

아니,하지만 다른 값은 괜찮을 것 같습니다. 내가 거울 부분을 가져 가거나 0.0으로 설정하면 조명이 정상적으로 작동합니다. 프로그램이 묶여 있지 않다면 그렇지 않을거야, 그렇지? – Lngly

+0

glGetError와 glGetUniformLocation의 반환 값을 수동으로 확인하십시오. 확실히 알 수 있도록 많은 디버깅 시간을 절약 할 수 있습니다. – Tim

+0

오류는 항상 0입니다. 위치는 3입니다. 이것은 GLint loc = ... 코드에서 위의 – Lngly

관련 문제