Shuvit game master repo. http://shuvit.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lensflare01.osl 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. uniform float sunScale;
  9. float noise( float n )
  10. {
  11. return fract(sin(n+timer/2.0));
  12. }
  13. //float noise2(vec2 co){
  14. //return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
  15. //}
  16. vec3 lensflare(vec2 uv,vec2 pos,float sunscale)
  17. {
  18. vec2 main = uv-pos;
  19. vec2 uvd = uv*(length(uv));
  20. float ang = atan(main.y, main.x);
  21. float dist=length(main); dist = pow(dist,.1);
  22. float n = noise1(vec2((ang-timer/9.0)*16.0,dist*32.0));
  23. float f0 = 1.0/(length(uv-pos)/sunscale+1.0);
  24. f0 = f0+f0*(sin((ang+timer/18.0 + noise1(abs(ang)+n/2.0)*2.0)*12.0)*.1+dist*.1+.8);
  25. float f2 = max(1.0/(1.0+32.0*pow(length(uvd+0.8*pos),2.0)),.0)*00.25;
  26. float f22 = max(1.0/(1.0+32.0*pow(length(uvd+0.85*pos),2.0)),.0)*00.23;
  27. float f23 = max(1.0/(1.0+32.0*pow(length(uvd+0.9*pos),2.0)),.0)*00.21;
  28. vec2 uvx = mix(uv,uvd,-0.5);
  29. float f4 = max(0.01-pow(length(uvx+0.4*pos),2.4),.0)*6.0;
  30. float f42 = max(0.01-pow(length(uvx+0.45*pos),2.4),.0)*5.0;
  31. float f43 = max(0.01-pow(length(uvx+0.5*pos),2.4),.0)*3.0;
  32. uvx = mix(uv,uvd,-.4);
  33. float f5 = max(0.01-pow(length(uvx+0.2*pos),5.5),.0)*2.0;
  34. float f52 = max(0.01-pow(length(uvx+0.4*pos),5.5),.0)*2.0;
  35. float f53 = max(0.01-pow(length(uvx+0.6*pos),5.5),.0)*2.0;
  36. uvx = mix(uv,uvd,-0.5);
  37. float f6 = max(0.01-pow(length(uvx-0.3*pos),1.6),.0)*6.0;
  38. float f62 = max(0.01-pow(length(uvx-0.325*pos),1.6),.0)*3.0;
  39. float f63 = max(0.01-pow(length(uvx-0.35*pos),1.6),.0)*5.0;
  40. vec3 c = vec3(.0);
  41. c.r+=f2+f4+f5+f6; c.g+=f22+f42+f52+f62; c.b+=f23+f43+f53+f63;
  42. c+=vec3(f0);
  43. return c;
  44. }
  45. void main()
  46. {
  47. vec4 renderedTex = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st);
  48. float xconv = bgl_RenderedTextureWidth / bgl_RenderedTextureHeight;
  49. vec2 sunPos = vec2((sunX - 0.5) * xconv, sunY - 0.5);
  50. vec2 uv = vec2((gl_TexCoord[0].s - 0.5) * xconv, gl_TexCoord[0].t - 0.5);
  51. vec3 lens = lensflare(uv, sunPos, sunScale);
  52. renderedTex.rgb += lens * sundirect;
  53. gl_FragColor = renderedTex;
  54. }