Mouse cursor drawn in post using texture buffer (UI!)

working_mouse_atlas.blend (968.2 KB)

import bge,bpy
from mathutils import Vector

cont = bge.logic.getCurrentController()

if cont.sensors['MouseOver'].positive:
    color = cont.sensors['MouseOver'].hitObject.color
    color = Vector([0,0,1,1])
scene = bge.logic.getCurrentScene()
filter = scene.filterManager.getFilter(0) # will only be available after the shader has been compiled after first frame
if filter is not None:
    plane = own.scene.objects['Plane']
    textureBindCode = plane.meshes[0].materials[0].textures[0].bindCode
    filter.setUniform2f("mouPos", *bge.logic.mouse.position) # where "mouPos" is the name of the uniform vec2 in the shader
    filter.setUniform4f("obColor", *color) # where "mouPos" is the name of the uniform vec2 in the shader
    filter.setTexture(0, textureBindCode, "aimBuffer") # where textureNameInShader is the uniform sampler2D name in shader
uniform sampler2D bgl_RenderedTexture;
uniform sampler2D bgl_DepthTexture;
uniform sampler2D aimBuffer;
uniform vec2 mouPos;
in vec4 bgl_TexCoord;
out vec4 fragColor;
uniform float bgl_RenderedTextureWidth;
uniform float bgl_RenderedTextureHeight;
uniform vec4 obColor;

void main(void)
  vec2 uv = bgl_TexCoord.xy;
  vec4 color = texture2D(bgl_RenderedTexture, uv);
  vec4 color2 = obColor;
  float ratio = bgl_RenderedTextureHeight/bgl_RenderedTextureWidth;
  float x = abs(bgl_TexCoord.x-mouPos.x);
  float y = abs(bgl_TexCoord.y-mouPos.y);
  vec2 cord =  bgl_TexCoord.xy;
  vec2 center = vec2(mouPos.x,1-mouPos.y);
  vec2 diff = cord-center;
  diff.x = diff.x/ratio;
  vec2 diff2 = diff + vec2(0.5625,0.5625);
  float mix_x = 1-clamp(floor(abs(diff.x)*16.5),0,1);
  float mix_y = 1-clamp(floor(abs(diff.y)*16.5),0,1);
  float mix_v = mix_x*mix_y;
  vec2 offset = vec2(obColor[0],obColor[1]);
  vec4 color3 = texture2D(aimBuffer,diff2+offset)*15;
  color = mix(color,color3,clamp(mix_v*(color3[0]+color3[1]+color3[2]),0,1));
  float mix_v2 = 1-clamp(floor(length(diff*45)),0,1);
  float mix_v3 = 1-clamp(floor(length(diff*145)),0,1);
  float final_mix  = mix_v-mix_v2+mix_v3;
  //fragColor = mix(color,color2,final_mix);
  fragColor = color;
  //fragColor =vec4(mix_v,mix_v,mix_v,1);