我有一個WebGL的着色器,其立即編譯感知(在Windows 7上的Chrome)時,我有這樣的:如果着色器永不改變,有沒有辦法緩存緩慢的WebGL着色器編譯?
void main(void) {
if (antialias_level == 1)
gl_FragColor = NewtonIteration((gl_FragCoord.xy + offset)/zoom);
else if (antialias_level == 2)
gl_FragColor = (NewtonIteration((gl_FragCoord.xy + offset + vec2(-0.25, -0.25))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.25, 0.25))/zoom)) * 0.5;
}
但它需要一個很長的時間(約10秒)編譯此:
void main(void) {
if (antialias_level == 1)
gl_FragColor = NewtonIteration((gl_FragCoord.xy + offset)/zoom);
else if (antialias_level == 2)
gl_FragColor = (NewtonIteration((gl_FragCoord.xy + offset + vec2(-0.25, -0.25))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.25, 0.25))/zoom)) * 0.5;
else if (antialias_level == 4)
gl_FragColor = (NewtonIteration((gl_FragCoord.xy + offset + vec2(-0.25, -0.25))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(-0.25, 0.25))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.25, -0.25))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.25, 0.25))/zoom)) * 0.25;
else if (antialias_level == 9)\
gl_FragColor = (NewtonIteration((gl_FragCoord.xy + offset + vec2(-0.33, -0.33))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.0, -0.33))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.33, -0.33))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(-0.33, 0.0))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.0, 0.0))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.33, 0.0))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(-0.33, 0.33))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.0, 0.33))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.33, 0.33))/zoom)) * 0.111111111;
else if (antialias_level == 16)\
gl_FragColor = (NewtonIteration((gl_FragCoord.xy + offset + vec2(-0.375, -0.375))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(-0.125, -0.375))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.125, -0.375))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.375, -0.375))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(-0.375, -0.125))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(-0.125, -0.125))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.125, -0.125))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.375, -0.125))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(-0.375, 0.125))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(-0.125, 0.125))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.125, 0.125))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.375, 0.125))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(-0.375, 0.375))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(-0.125, 0.375))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.125, 0.375))/zoom) + NewtonIteration((gl_FragCoord.xy + offset + vec2(0.375, 0.375))/zoom)) * 0.0625;
}
有沒有辦法將WebGL編譯的結果緩存到二進制文件並加載它,或者不會有幫助?我假設長時間的延遲與從OpenGL到DirectX的着色器轉換有關。
非常合理的建議,但要強調一點:*目前*無法預編譯WebGL着色器。如果我們確實獲得了這種能力,它可能會成爲一種解決辦法。 – Toji