2011-11-19 2 views
0

프로젝트 초반에을 코드로 채우기 위해 간단한 String을 사용했습니다. 이 모양은 다음과 같습니다.잘못된 조각 셰이더입니다. 링크를 진행할 수 없습니다.

public final static String chunkDefaultVertexInit = "" 
    +constantParameters 
    +"precision mediump float;" 

    +"uniform mat4 mPMatrix;" 
    +"uniform mat4 mVMatrix;" 
    +"uniform mat4 mMMatrix;" 
    +"uniform mat4 mMVMatrix;" 

    +"attribute vec4 Vertex;" 
    +"attribute vec3 Normal;" 
    +"attribute vec2 TexCoord;" 

    +"varying vec3 normal;" 
    +"varying vec2 uv;" 
    +"varying vec4 positionM;" 
    +"varying vec4 positionMV;"; 
    etc.... 

이것은 나를 위해 일했지만 실제로는 분명하지 않았습니다. 그래서 저는 제 코드를 어떻게하면 누구나 깨끗하고 분명하게 만들 수 있을지 생각했습니다. 내 생각은 내 모든 코드 묶음을 실제 .cc - 파일에두고 res/raw 폴더로 옮기는 것이 었습니다. 더 빨리 말한 것보다. Inputstreams를 통해 코드를 읽고 String으로 저장하려고했습니다. 그것도 잘 작동했기 때문에 셰이더에 String 소스를 제공했습니다.

그래서 ... 문제가 생겨서 내가 말했듯이 나는 아직 이해하지 못했습니다. 나는 나 자신에 대해 조금 화가났다. 나는 그것을 고칠 쉬운 방법을 생각했기 때문에 나는 그것을 보지 못했다.

나는 심지어 내 소스 코드를 보여 주었다. 그러나 그것은 바르게 보인다!

Vertexshader :

//vertexshader 
precision mediump float; 

uniform mat4 mPMatrix; 
uniform mat4 mVMatrix; 
uniform mat4 mMMatrix; 
uniform mat4 mMVMatrix; 

attribute vec4 aVertex; 
attribute vec3 aNormal; 
attribute vec2 aTexCoord; 

varying vec2 vecTexCoord; 
varying vec3 vecNormal; 
varying vec4 vecVertex[2]; 

void main() { 
    gl_Position = mPMatrix * mMVMatrix * aVertex; 
    vecVertex[0] = mMMatrix * aVertex; 
    vecVertex[1] = mMVMatrix * aVertex; 
    vecTexCoord = aTexCoord; 
    vecNormal = normalize(vec3(mMMatrix * -vec4(aNormal,0.0))); 
} 
OO

Log.i("Llama3D Shader",shaderCode); 

는 (이상한 대해 걱정하지 마십시오 "디버그 ID,"그것의 프로젝트 이름) 여기

은 쉐이더의 소스 코드입니다

프래그먼트 셰이더 :

#define MAX_POINT_LIGHTS 4 
precision mediump float; 

varying vec2 vecTexCoord; 
varying vec3 vecNormal; 
varying vec4 vecVertex[2]; 

uniform vec3 uVecEye; 
uniform vec3 uPointLightPosition[MAX_POINT_LIGHTS]; 
uniform vec3 uPointLightColor[MAX_POINT_LIGHTS]; 
uniform sampler2D textureHandle; 

vec3 V = normalize(uVecEye.xyz-vecVertex[1].xyz); 
vec3 N = vNormal; 

vec3 vecLight[MAX_POINT_LIGHTS]; 
vec4 pointDiffuse = vec4(0.0); 
vec4 pointSpecular = vec4(0.0); 

vec4 ambient = vec4(0.2,0.2,0.2,1.0); 
vec4 color = vec4(1.0,1.0,1.0,1.0); 
vec4 matSpec = vec4(1.0,1.0,1.0,1.0); 
vec4 lightSpec = vec4(1.0,1.0,1.0,1.0); 
vec4 spec = matSpec * lightSpec; 

float shininess = 20.0; 

void main() { 
    for (int i=0;i<MAX_POINT_LIGHTS;i++) { 

     vecLight[i].xyz = vecVertex[0].xyz - uPointLightPosition[i].xyz; 
     float vecDistance = length(vecLight[i].xyz); 

     if (vecDistance<=25.0) { 

      vecDistance = 1.0 - max(0.0,vecDistance)/25.0; 
      vec3 L = normalize(vecLight[i]); 
      vec3 R = normalize(reflect(L,N)); 
      float LND = max(0.0,dot(N,L)) * vecDistance; 

      pointDiffuse += color * vec4(uPointLightColor[i].xyz,0.0) * LND; 

      if (shininess!=0.0 && spec!=0.0) { 
       pointSpecular += spec * pow(max(0.0,dot(R,V)),shininess) * LND; 
      } else { 
       pointSpecular += vec4(0.0,0.0,0.0,0.0); 
      } 
     } 
    } 
    vec4 colorTexture = texture2D(textureHandle,vec2(+vTexCoord.x,-vTexCoord.y)); 
    gl_FragColor = ambient + colorTexture * pointDiffuse + pointSpecular; 
} 

내가 프로그램을 실행하려고 할 때마다의 ShaderlogInfo 및 ProgramlogInfo 나에게 말 :

잘못된 조각 쉐이더. 링크를 진행할 수 없습니다. *

나는 미친가 아니면 그냥 눈이 멀었나요?! 나는 대답을 알고 있기를 바랍니다 ... 나는 정말로 어떤 것도 모른다 ... 제발 나를 도와주세요! :(

+0

컴파일 및 연결 로그에는 무엇이 나와 있습니까? –

+0

이 컴파일 및 링크 로그를 Eclipse에서 얻으려면 어떻게해야합니까? 분명히 나는 ​​아직 그들을 보지 못한다 :/ – TheWhiteLlama

+0

그것은 Eclipse의 책임이 아니다. 셰이더 컴파일/링크 오류는 코드에서 확인할 필요가 있습니다. 그것들은 셰이더의 런타임 컴파일의 일부입니다. 컴파일러/링커 오류가 있으면 코드를 가져와 표시해야합니다.나는 안드로이드와 자바가 어떻게 처리하는지 모르지만 [이 페이지] (http://www.opengl.org/wiki/GLSL#Error_Checking)에서는 C/C++ 코드로 어떻게하는지 설명한다. –

답변

4

당신이있어 로그 무대를 연결하는 프로그램, glGetProgramInfoLog

뭘 디버깅해야하는 것은, glGetShaderInfoLog 조각 위치 쉐이더 로그 인 출신이 라인을 따라

뭔가 :..

def _compile(self, source): 
    ptr = cast(c_char_p(source), POINTER(c_char)) 
    glShaderSource(self.id, 1, byref(ptr), None) 
    glCompileShader(self.id) 
    status = c_int(0) 
    glGetShaderiv(self.id, GL_COMPILE_STATUS, byref(status)) 
    log = self.check() 
    print(log), 
    if not status.value: 
     raise Exception(log) 

def check(self): 
    length = c_int(0) 
    glGetShaderiv(self.id, GL_INFO_LOG_LENGTH, byref(length)) 
    log = create_string_buffer(length.value) 
    glGetShaderInfoLog(self.id, length.value, None, log) 
    return log.value 

이것은 자바에서는 아니지만 파이썬에서는 셰이더가 로그를 컴파일하는 방법을 알려줍니다.

내 환경의 부하가 내게이 로그를 알려주는데 유용 할 수도 있고 유용하지 않을 수도 있습니다.

Vertex shader was successfully compiled to run on hardware. 
WARNING: 0:2: warning(#260) Keyword 'precision' is supported in GLSL 1.3 
Fragment shader failed to compile with the following errors: 
WARNING: 0:2: warning(#260) Keyword 'precision' is supported in GLSL 1.3 
ERROR: 0:14: error(#143) Undeclared identifier vNormal 
WARNING: 0:14: warning(#402) Implicit truncation of vector from size 1 to size 3. 
ERROR: 0:50: error(#143) Undeclared identifier vTexCoord 
ERROR: 0:50: error(#216) Vector field selection out of range 'y' 
ERROR: error(#273) 4 compilation errors. No code generated 
+0

정확히 내가 뭘 찾고 있었는지, 고마워! – trippedout

+0

친절하게 답변을 수락 한 것으로 표시 하시겠습니까? – Berserker

+0

내가 @ Berserker 수 있지만 나는 질문하지 않았다 :) – trippedout