Shader Trouble Shotting - zzragida/UnityDocs GitHub Wiki

Issue 1. Compilation Failure BloomOptimized Effect

  • Device: Nexus 5
  • GPU : Adreno 330

๋ฉ”์„ธ์ง€

11-04 13:15:23.520 21792 21899 D Unity : GLES: Const arrays detected in a shader, these will crash Adreno 3xx shader compiler. Failing compilation. 11-04 13:15:23.520 21792 21899 D Unity : Note: Creation of internal variant of shader 'Hidden/FastBloom' failed.

์ƒ์„ธ๋‚ด์šฉ

  • Standard Asset์˜ BloomOptimzed Image Effect๋ฅผ Camera์— ์ ์šฉ

  • BloomOptimzed์— ์‚ฌ์šฉ์ค‘์ธ Hidden/FastBloom.shader๊ฐ€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰์‹œ์ ์— ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•จ

  • ์›์ธ

    • Qualcomm Adreno Shader ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ์…ฐ์ด๋” ์ฝ”๋“œ๋ฅผ ์ตœ์ ํ™”ํ• ๋•Œ Const Array๋ฅผ ์ปดํŒŒ์ผํ•˜์ง€ ๋ชปํ•˜๋Š” ์ƒํ™ฉ์ž„
    • ์˜ˆ์‹œ) static const half4 curve4[7] = { half4(0,0,0,0), half4(1,1,1,1) ...};
  • ํ•ด๊ฒฐ๊ณผ์ •

    • Unity์—์„œ ํ•ด๋‹น ์…ฐ์ด๋”๋ฅผ OpenGLES Core๋กœ ์ปดํŒŒ์ผํ•ด์„œ ์ปดํŒŒ์ผ๋œ ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•ด ๋ด„
    • ๋‹คํ–‰ํžˆ ์œ ๋‹ˆํ‹ฐ์—์„œ // XXX ADRENOCONSTARRAYBUG <= ์ด๋Ÿฐ ์ฃผ์„์„ ๋‚จ๊ฒจ์คŒ
  • ํ•ด๊ฒฐ์ฑ…

  • Const Array๋กœ ์ ‘๊ทผํ•ด์„œ ์‚ฌ์šฉ๋˜๋˜ Loop ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•จ

// Before: Adreno Const Array Bug
static const half4 curve4[7] = { half4(0.0205,0.0205,0.0205,0),
                                 half4(0.0855,0.0855,0.0855,0),
                                 half4(0.232,0.232,0.232,0),
                                 half4(0.324,0.324,0.324,1),
                                 half4(0.232,0.232,0.232,0),
                                 half4(0.0855,0.0855,0.0855,0),
                                 half4(0.0205,0.0205,0.0205,0) };
 
void func()
{
  // ...
  for( int l = 0; l < 7; l++ ) 
  {  
    half4 tap = tex2D(_MainTex, coords);
    half4 temp = curve4[l];
    color += tap * temp;
    coords += netFilterWidth;
  }
}
 
 
// After : Adreno Const Array Bug Fix
static const half4 curve4_0 = half4(0.0205, 0.0205, 0.0205, 0);
static const half4 curve4_1 = half4(0.0855, 0.0855, 0.0855, 0);
static const half4 curve4_2 = half4(0.232, 0.232, 0.232, 0);
static const half4 curve4_3 = half4(0.324, 0.324, 0.324, 1);
static const half4 curve4_4 = half4(0.232, 0.232, 0.232, 0);
static const half4 curve4_5 = half4(0.0855, 0.0855, 0.0855, 0);
static const half4 curve4_6 = half4(0.0205, 0.0205, 0.0205, 0);
 
half4 color = 0;
half4 tap = tex2D(_MainTex, coords);
color += tap * curve4_0;
coords += netFilterWidth;
tap = tex2D(_MainTex, coords);
color += tap * curve4_1;
coords += netFilterWidth;
tap = tex2D(_MainTex, coords);
color += tap * curve4_2;
coords += netFilterWidth;
tap = tex2D(_MainTex, coords);
color += tap * curve4_3;
coords += netFilterWidth;
tap = tex2D(_MainTex, coords);
color += tap * curve4_4;
coords += netFilterWidth;
tap = tex2D(_MainTex, coords);
color += tap * curve4_5;
coords += netFilterWidth;
tap = tex2D(_MainTex, coords);
color += tap * curve4_6;
coords += netFilterWidth;