2014-10-29 40 views
0

我用GL20.GL_POINTS陰影圖片。其中一點是可變的('vKind'代碼)。當屬性發生變化時,我應該同時更改紋理。以下是我的方法。但我得到了一個低fps。我該怎麼辦?任何幫助謝謝!片段着色器中的多紋理。我得到了一個低fps

 final String fragmentShader = "precision highp float;\n" 
      + "uniform sampler2D u_texture0;\n" // diffuse texture for 
      + "uniform sampler2D u_texture1;\n" // diffuse texture for 
      + "uniform sampler2D u_texture2;\n" // diffuse texture for 
      + "uniform sampler2D u_texture3;\n" // diffuse texture for 
      + "uniform sampler2D u_texture4;\n" // diffuse texture for 
      + "uniform sampler2D u_texture5;\n" // diffuse texture for 
      + "uniform sampler2D u_texture6;\n" // diffuse texture for 
      + "uniform sampler2D u_texture7;\n" // diffuse texture for 
      + "varying float vRotation;\n" 
      + "varying float vKind;\n" 
      + "varying vec4 vColor;\n" // input color from vertex shader 
      + "void main() {\n" 
      + "highp vec2 center = vec2(0.5, 0.5);\n" 
      // Translate the center of the point the origin. 
      + "highp vec2 centeredPoint = gl_PointCoord - center;\n" 
      // Create a rotation matrix using the provided angle 
      + "highp mat2 rotation = mat2(cos(vRotation), sin(vRotation),\n" 
      + "-sin(vRotation), cos(vRotation)); \n" 
      // Perform the rotation. 
      + "centeredPoint = centeredPoint*rotation ;\n" 
      // Translate the point back to its original position and use 
      // that point 
      // to get your texture color. 
      + "if(vKind==0.0)\n" 
      + "gl_FragColor = texture2D(u_texture0, centeredPoint + center);\n" 
      + "else if(vKind==1.0)\n" 
      + "gl_FragColor = texture2D(u_texture1, centeredPoint + center);\n" 
      + "else if(vKind==2.0)\n" 
      + "gl_FragColor = texture2D(u_texture2, centeredPoint + center);\n" 
      + "else if(vKind==3.0)\n" 
      + "gl_FragColor = texture2D(u_texture3, centeredPoint + center);\n" 
      + "else if(vKind==4.0)\n" 
      + "gl_FragColor = texture2D(u_texture4, centeredPoint + center);\n" 
      + "else if(vKind==5.0)\n" 
      + "gl_FragColor = texture2D(u_texture5, centeredPoint + center);\n" 
      + "else if(vKind==6.0)\n" 
      + "gl_FragColor = texture2D(u_texture6, centeredPoint + center);\n" 
      + "else\n" 
      + "gl_FragColor = texture2D(u_texture7, centeredPoint + center);\n" 
      + "gl_FragColor *= vColor;\n" 

      // + 
      // " gl_FragColor.a = (gl_FragColor.b >= 0.5) ? gl_FragColor.a : 0.0;\n" 
      + "}\n"; 
+0

如果您依次使用每個紋理對所有點進行分組並繪製所有點,則會更加緩存/發散。 – jozxyqk 2014-11-04 11:01:15

回答

1

首先,嘗試,如果紋理確實是什麼使人下來的情況來分析:註釋掉所有,但1紋理上,並且所有的if語句調用相同的紋理。然後,在確認後,考慮兩件事情:

  • 既然你是畫點你真的需要一個vKindvarying是一個uniform。您可以使用8個繪製調用,將您的點分成CPU上的8個陣列,具體取決於它們應使用的紋理,然後在片段着色器中僅使用1個紋理,並在8個繪製調用的每一個之前綁定正確的紋理。

  • 如果您真的需要所有這些紋理數據,請嘗試查看如何使用atlas(將多個紋理合併爲一個)並嘗試儘可能減少紋理計數。

+0

感謝您的建議。我有一個嘗試。 – 2014-10-30 12:02:27

相關問題