2016-10-10 5 views
-2

버텍스 쉐이더 "uIsTeapot"에 변수가 있습니다.두 셰이더 모두에서 균일 한 변수를 표시하는 방법은 무엇입니까?

uniform float uIsTeapot; 

꼭지점 셰이더는 매우 잘 작동하지만 조각 셰이더에는 표시되지 않습니다. 그때

if (uIsTeapot == 0.0) 

를 사용하는 경우 오류가
"uIsTeapot": undeclared identifier 

을 발생하지만 버텍스 쉐이더에 정의했다. 나는 유니폼 등 모두 쉐이더에 uIsTeapot를 정의 할 경우, 프로그램은 프로그램이

if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) { 
     alert("Could not initialise shaders"); 
} 

편집 veryfication 통과하지 않기 때문에 "쉐이더를 초기화 할 수 없습니다"라고 : 내가 오류없이 컴파일 이제 변수와 프로그램에 mediump을 추가 할 수 있지만 결과 화면에 하나의 객체이지만 두 개의 객체를 그립니다.

버텍스 쉐이더

attribute vec3 aVertexPosition; 
attribute vec3 aVertexNormal; 
attribute vec2 aTextureCoord; 

attribute vec4 aVertexColor; 

uniform mat4 uMVMatrix; 
uniform mat4 uPMatrix; 
uniform mat3 uNMatrix; 

uniform vec3 uAmbientColor; 
uniform vec3 uPointLightingLocation; 
uniform vec3 uPointLightingColor; 

uniform mediump float uIsTeapot; 
//varying float vIsTeapot; 

varying vec2 vTextureCoord; 
varying vec3 vLightWeighting; 

varying vec4 vColor; 

void main(void) { 

    if (uIsTeapot == 1.0) { 
     vec4 mvPosition = uMVMatrix * vec4(aVertexPosition, 1.0); 
     gl_Position = uPMatrix * mvPosition; 

     vec3 lightDirection = normalize(uPointLightingLocation - mvPosition.xyz); 
     vec3 transformedNormal = uNMatrix * aVertexNormal; 
     float directionalLightWeighting = max(dot(transformedNormal, lightDirection), 0.0); 
     directionalLightWeighting = 100.0; 
     vLightWeighting = uAmbientColor + uPointLightingColor * directionalLightWeighting; 
     vTextureCoord = aTextureCoord; 
    } 
    if (uIsTeapot == 0.0) { 
     gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0); 
     vColor = aVertexColor; 
    } } 

조각 쉐이더 같은 정밀, 모두 쉐이더에서 선언 할 필요

precision mediump float; 

varying vec2 vTextureCoord; 
varying vec3 vLightWeighting; 

varying vec4 vColor; 

uniform sampler2D uSampler; 

uniform mediump float uIsTeapot; 
//varying float vIsTeapot; 

void main(void) { 

    if (uIsTeapot == 1.0) { 
     vec4 textureColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t)); 
     gl_FragColor = vec4(textureColor.rgb * vLightWeighting, textureColor.a); 
    } else { 
     gl_FragColor = vColor; 
    } 


} 
+0

"프로그램이 올바르게 작동하지 않습니다"는 정보가 충분하지 않습니다. 어떤 오류 메시지가 나타 납니까? [셰이더가 컴파일되거나 링크되지 않을 때 셰이더 정보 로그와 프로그램 정보 로그를 출력합니까?] (http://webglfundamentals.org/webgl/lessons/webgl-boilerplate.html)? – gman

+0

오류가 발생한 위치 정보를 추가했습니다 – Log

+0

코드에'if (! gl.getProgramParameter (shaderProgram, gl.LINK_STATUS)) { 경고 (gl.getProgramInfoLog (shaderProgram)); }''및'gl.getShaderInfoLog (shader)'와'gl.getShaderParameter (shader, gl.COMPILE_STATUS) '를 호출하는 경우를 제외하고는 쉐이더를 컴파일 할 때도 비슷한 * 코드를 가지고 있어야합니다. – gman

답변

1

.

당신이 의미하는 무엇을 :

다음 프로그램이 잘 작동하지 않습니다.

+0

"initShaders"부분의 오류 – Log

+0

질문에 대한 정보를 추가합니다. – Log

1

버텍스 쉐이더와 프래그먼트 쉐이더를 게시 할 수 있습니까?

uniform mediump float uIsTeapot;

... 모두 :

사용해보십시오 난 당신이 기본 정밀도에 의존 의심, 그것을 당신이 조각 쉐이더의 버텍스 쉐이더와 mediump에 highp 사용하는 것 같다 버텍스 쉐이더 및 프래그먼트 쉐이더.

+0

감사합니다. initShaders의 오류는 사라졌지만 두 개의 객체를 그렸지만 화면에는 하나의 객체 만 있습니다. 왜 단지 하나의 물건을 알고 있니? – Log