OpenGL2: Don't use initialized arrays in glsl shaders.

Unsupported in GLSL 1.20 (Mac OS X 10.6)
This commit is contained in:
SmileTheory 2017-07-24 16:29:04 -07:00
parent 67dace6c20
commit 356ae10ef6
3 changed files with 38 additions and 3 deletions

View File

@ -11,7 +11,15 @@ void main()
vec2 tc;
#if 0
float c[7] = float[7](1.0, 0.9659258263, 0.8660254038, 0.7071067812, 0.5, 0.2588190451, 0.0);
float c[7];
c[0] = 1.0;
c[1] = 0.9659258263;
c[2] = 0.8660254038;
c[3] = 0.7071067812;
c[4] = 0.5;
c[5] = 0.2588190451;
c[6] = 0.0;
tc = var_TexCoords + u_InvTexRes * vec2( c[0], c[6]); color = texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[1], c[5]); color += texture2D(u_TextureMap, tc);
@ -44,7 +52,13 @@ void main()
gl_FragColor = color * 0.04166667 * u_Color;
#endif
float c[5] = float[5](1.0, 0.9238795325, 0.7071067812, 0.3826834324, 0.0);
float c[5];
c[0] = 1.0;
c[1] = 0.9238795325;
c[2] = 0.7071067812;
c[3] = 0.3826834324;
c[4] = 0.0;
tc = var_TexCoords + u_InvTexRes * vec2( c[0], c[4]); color = texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[1], c[3]); color += texture2D(u_TextureMap, tc);

View File

@ -6,7 +6,7 @@ varying vec2 var_ScreenTex;
//float gauss[8] = float[8](0.17, 0.17, 0.16, 0.14, 0.12, 0.1, 0.08, 0.06);
//float gauss[5] = float[5](0.30, 0.23, 0.097, 0.024, 0.0033);
float gauss[4] = float[4](0.40, 0.24, 0.054, 0.0044);
//float gauss[4] = float[4](0.40, 0.24, 0.054, 0.0044);
//float gauss[3] = float[3](0.60, 0.19, 0.0066);
#define BLUR_SIZE 4
@ -22,6 +22,12 @@ float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNea
vec4 depthGaussian1D(sampler2D imageMap, sampler2D depthMap, vec2 tex, float zFarDivZNear, float zFar, vec2 scale)
{
float gauss[4];
gauss[0] = 0.40;
gauss[1] = 0.24;
gauss[2] = 0.054;
gauss[3] = 0.0044;
#if defined(USE_DEPTH)
float depthCenter = getLinearDepth(depthMap, tex, zFarDivZNear);

View File

@ -4,6 +4,7 @@ uniform vec4 u_ViewInfo; // zfar / znear, zfar, 1/width, 1/height
varying vec2 var_ScreenTex;
#if 0
vec2 poissonDisc[9] = vec2[9](
vec2(-0.7055767, 0.196515), vec2(0.3524343, -0.7791386),
vec2(0.2391056, 0.9189604), vec2(-0.07580382, -0.09224417),
@ -11,6 +12,8 @@ vec2(0.5784913, -0.002528916), vec2(0.192888, 0.4064181),
vec2(-0.6335801, -0.5247476), vec2(-0.5579782, 0.7491854),
vec2(0.7320465, 0.6317794)
);
#endif
#define NUM_SAMPLES 3
// Input: It uses texture coords as the random number seed.
@ -46,6 +49,18 @@ float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNea
float ambientOcclusion(sampler2D depthMap, const vec2 tex, const float zFarDivZNear, const float zFar, const vec2 scale)
{
vec2 poissonDisc[9];
poissonDisc[0] = vec2(-0.7055767, 0.196515);
poissonDisc[1] = vec2(0.3524343, -0.7791386);
poissonDisc[2] = vec2(0.2391056, 0.9189604);
poissonDisc[3] = vec2(-0.07580382, -0.09224417);
poissonDisc[4] = vec2(0.5784913, -0.002528916);
poissonDisc[5] = vec2(0.192888, 0.4064181);
poissonDisc[6] = vec2(-0.6335801, -0.5247476);
poissonDisc[7] = vec2(-0.5579782, 0.7491854);
poissonDisc[8] = vec2(0.7320465, 0.6317794);
float result = 0;
float sampleZ = getLinearDepth(depthMap, tex, zFarDivZNear);