2013-02-12 1 views
0

아래는 성능이 좋지 않은 프래그먼트 쉐이더입니다. 조건 분기를 제거하지 않으면 성능이 향상되지 않습니다. 150 개의 폴리곤으로 킨들 파이어에서 10fps, 갤럭시 S3에서 20fps를 얻습니다. 모든 것을 최적화하는 최선의 방법에 대한 생각? iPad 2의 비슷한 셰이더는 30 + fps를 실행합니다.8 텍스처 단위를 가진 opengl 및 multitexture 쉐이더에 대한 생각

아래 코드에서 texture1 ~ texture8은 8 개의 텍스처에 바인딩됩니다. VertexTexturesOut1과 VertexTexturesOut2는 버텍스 쉐이더에서 전달되며 쉐이딩 양을 나타 내기 위해 0.0에서 1.0까지의 값을 갖습니다. 아이디어는 가로 질감을 혼합하는 것입니다, 그래서 잔디 조각 쉐이더를 설계 할 때

uniform sampler2D texture1; 
uniform sampler2D texture2; 
uniform sampler2D texture3; 
uniform sampler2D texture4; 
uniform sampler2D texture5; 
uniform sampler2D texture6; 
uniform sampler2D texture7; 
uniform sampler2D texture8; 

varying mediump vec2 TextureCoordOut; 
varying lowp vec4 VertexTexturesOut1; 
varying lowp vec4 VertexTexturesOut2; 

... 

    lowp vec4 Color = vec4(0.0, 0.0, 0.0, 0.0); 

    if (VertexTexturesOut1.x != 0.0) Color = Color + texture2D (texture1, TextureCoordOut) * VertexTexturesOut1.x; 
    if (VertexTexturesOut1.y != 0.0) Color = Color + texture2D (texture2, TextureCoordOut) * VertexTexturesOut1.y; 
    if (VertexTexturesOut1.z != 0.0) Color = Color + texture2D (texture3, TextureCoordOut) * VertexTexturesOut1.z; 
    if (VertexTexturesOut1.w != 0.0) Color = Color + texture2D (texture4, TextureCoordOut) * VertexTexturesOut1.w; 

    if (VertexTexturesOut2.x != 0.0) Color = Color + texture2D (texture5, TextureCoordOut) * VertexTexturesOut2.x; 
    if (VertexTexturesOut2.y != 0.0) Color = Color + texture2D (texture6, TextureCoordOut) * VertexTexturesOut2.y; 
    if (VertexTexturesOut2.z != 0.0) Color = Color + texture2D (texture7, TextureCoordOut) * VertexTexturesOut2.z; 
    if (VertexTexturesOut2.w != 0.0) Color = Color + texture2D (texture8, TextureCoordOut) * VertexTexturesOut2.w; 

    gl_FragColor = Color;  
+0

1. if 문을 사용하는 이유는 무엇입니까? 이것은 곱셈을하는 것보다 실제로 빠릅니까? 2. 어둠을 찌르기 : 아마도 같은 변수에 대한 다중 할당이 최적이 아닌 것일까? 'Color1'과'Color2'를 가지고 추가하는 것은 어떨까요? –

답변

2

당신 쉐이더가 DONT의 많은이 균등 등 먼지, 바위, 모래로 조화를 이루고 있습니다. 모든 스레드가 워프 (또는 배치)의 다른 모든 스레드를 항상 기다릴 필요가 있도록 많은 조건문이 있습니다. 8 텍스쳐에 접근하고 있습니다. 즉, 모든 텍스쳐 룩업 (메모리 대역폭을 죽이기)을 기다려야합니다. Adreno SDK, Mali SDK 또는 임의의 공급 업체와 같은 최적화 도구를 사용하고 최적화 도구에서 쉐이더를 실행하여 GPU가 더 많은 시간을 보내고 있는지 파악하십시오.

전체 RGB888 텍스처를 사용하고 있습니까? A

어쩌면 우리가 무엇을 아카이브하려고하는지 알려주면 8 개의 텍스처 조회를 사용하지 않고도 다른 솔루션에서 생각할 수 있습니다.