UPBGE! I totally forgot that existed! I should be using that.
In regular BGE, it does not work, even with GLSL enabled. Hereâs the console output:
Blender Game Engine Started
2D Filter GLSL Shader: compile error:
1 uniform sampler2D bgl_RenderedTexture;
2 uniform float bgl_RenderedTextureWidth;
3 uniform float bgl_RenderedTextureHeight;
4 uniform float sunX;
5 uniform float sunY;
6 uniform float timer;
7 uniform float sundirect;
8
9 const float sunScale = 0.2; // Normalized sun size between 0.001 and 1.0
10
11 float noise1( float n )
12 {
13 return fract(sin(n));
14 }
15
16 float noise2(vec2 co){
17 return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
18 }
19
20 vec3 lensflare(vec2 uv,vec2 pos,float sunscale)
21 {
22 vec2 main = uv-pos;
23 vec2 uvd = uv*(length(uv));
24
25 float ang = atan(main.y, main.x);
26 float dist=length(main); dist = pow(dist,.1);
27 float n = noise(vec2((ang-timer/9.0)*16.0,dist*32.0));
28
29 float f0 = 1.0/(length(uv-pos)/sunscale+1.0);
30
31 f0 = f0+f0*(sin((ang+timer/18.0 + noise(abs(ang)+n/2.0)*2.0)*12.0)*.1+dist*.1+.8);
32
33 float f2 = max(1.0/(1.0+32.0*pow(length(uvd+0.8*pos),2.0)),.0)*00.25;
34 float f22 = max(1.0/(1.0+32.0*pow(length(uvd+0.85*pos),2.0)),.0)*00.23;
35 float f23 = max(1.0/(1.0+32.0*pow(length(uvd+0.9*pos),2.0)),.0)*00.21;
36
37 vec2 uvx = mix(uv,uvd,-0.5);
38
39 float f4 = max(0.01-pow(length(uvx+0.4*pos),2.4),.0)*6.0;
40 float f42 = max(0.01-pow(length(uvx+0.45*pos),2.4),.0)*5.0;
41 float f43 = max(0.01-pow(length(uvx+0.5*pos),2.4),.0)*3.0;
42
43 uvx = mix(uv,uvd,-.4);
44
45 float f5 = max(0.01-pow(length(uvx+0.2*pos),5.5),.0)*2.0;
46 float f52 = max(0.01-pow(length(uvx+0.4*pos),5.5),.0)*2.0;
47 float f53 = max(0.01-pow(length(uvx+0.6*pos),5.5),.0)*2.0;
48
49 uvx = mix(uv,uvd,-0.5);
50
51 float f6 = max(0.01-pow(length(uvx-0.3*pos),1.6),.0)*6.0;
52 float f62 = max(0.01-pow(length(uvx-0.325*pos),1.6),.0)*3.0;
53 float f63 = max(0.01-pow(length(uvx-0.35*pos),1.6),.0)*5.0;
54
55 vec3 c = vec3(.0);
56
57 c.r+=f2+f4+f5+f6; c.g+=f22+f42+f52+f62; c.b+=f23+f43+f53+f63;
58 c+=vec3(f0);
59
60 return c;
61 }
62
63 void main()
64 {
65 vec4 renderedTex = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st);
66 float xconv = bgl_RenderedTextureWidth / bgl_RenderedTextureHeight;
67 vec2 sunPos = vec2((sunX - 0.5) * xconv, sunY - 0.5);
68 vec2 uv = vec2((gl_TexCoord[0].s - 0.5) * xconv, gl_TexCoord[0].t - 0.5);
69 vec3 lens = lensflare(uv, sunPos, sunScale);
70 renderedTex.rgb += lens * sundirect;
71 gl_FragColor = renderedTex;
72 }
WARNING: 0:2: '' : #version directive missing
ERROR: 0:16: 'float' : overloaded functions must have the same return type
ERROR: 0:27: 'noise' : undeclared identifier
ERROR: 0:28: 'noise' : function name expected
ERROR: 0:31: 'noise' : function name expected
Blender Game Engine Finished
EDIT: Same error in UPBGE