2013-01-31 5 views
0

텍스처를 하나씩 그릴 패턴을 찾을 수 없습니다. 내가해야 결과 조각의 색상과 같은 :OpenGL 셰이더 - 여러 텍스처 겹침 ​​

tex1 + (1-tex1alpha) * tex2 + (1-tex1alpha-tex2alpha) * tex3

텍스처를 혼합 할 수 있지만, 층 같은 다른 이상을 배치 할 수 없음 이미지 편집기에서.

+0

시나리오가 다른 텍스처로 여러 번 그리기를 허용합니까? –

+0

이것을 버텍스 쉐이더에 쓰면 어떻게됩니까? –

+0

셰이더에서 조각 색상을 계산해야합니다. 내 최고의 텍스처는 검은 색과 투명성을 가지고 있으므로 color1 + color2를 사용할 때 검정색이 선명하지 않습니다. – user1993006

답변

0

저는 OpenGL을 사용하지 않기 때문에 GLSL 코드가 완전히 유효하지 않을 수 있습니다. 그러나 찾고있는 쉐이더는 이와 같이 보일 것입니다. 실수를 수정하십시오.

vec4 col; 
col = texture2D(tex3, uv) 
if(col.a == 1) { gl_FragColor = col; return; } 
col = texture2D(tex2, uv) 
if(col.a == 1) { gl_FragColor = col; return; } 
col = texture2D(tex1, uv) 
if(col.a == 1) { gl_FragColor = col; return; } 

즉 텍스처 수가 고정되어있는 경우입니다. 당신은 쉐이더에 직접 게시 된 공식을 쓸 수

vec4 col; 
for(int i = nTextures - 1; i >= 0; --i) 
{ 
    col = texture2DArray(textures, vec3(uv, i)); 
    if(col.a == 1) 
    { 
     gl_FragColor = col; 
     return; 
    } 
} 
0

: 당신이 텍스처의 변수 번호가있는 경우, 당신은 텍스처 배열에 넣어 뭔가를 할 수 있습니다. 다음은 작동합니다 :

uniform sampler2D sampler1; 
uniform sampler2D sampler2; 
uniform sampler2D sampler3; 

varying vec2 texCoords; 

void main() 
{ 
    vec4 tex1 = texture(sampler1, texCoords); 
    vec4 tex2 = texture(sampler2, texCoords); 
    vec4 tex3 = texture(sampler3, texCoords); 
    gl_FragColor = tex1 + (1 - tex1.a) * tex2 + (1 - tex1.a - tex2.a) * tex3; 
}; 

그러나 세 번째 인수는 바람직하지 않은 결과를 초래할 수 있습니다.

gl_FragColor = tex1 + (1 - tex1.a) * tex2 + max(1 - tex1.a - tex2.a, 0) * tex3;