JakeCake Posted September 20, 2015 Share Posted September 20, 2015 I have a shader that I am trying to use at a specific sprite in my game, but filters seem not to be relative to the sprite, but rather world-pos 0, 0. I would like to render this filter at a different point, but also the "camera"/world may be zoomed in/out and rotated a bit. I am probably looking for a world-matrix of some sort, but can't find one, so I assume it doesn't have one. Here is my shader code for the filter:this.fragmentSrc = [ // Based on http://glslsandbox.com/e#25456.0 "#ifdef GL_ES", "precision mediump float;", "#endif", // Yuldashev Mahmud Effect took from shaderToy [email protected] "uniform float time;", "uniform vec2 mouse;", "uniform vec2 resolution;", "uniform vec2 pos;", "uniform vec2 scale;", "uniform float rotation;", "uniform vec4 atmosphereColor;", "uniform float cloudsStart;", "uniform float atmosphereEnd;", "float snoise(vec3 uv, float res)", "{", "const vec3 s = vec3(1e0, 1e2, 1e3);", "uv *= res;", "vec3 uv0 = floor(mod(uv, res))*s;", "vec3 uv1 = floor(mod(uv+vec3(1.), res))*s;", "vec3 f = fract(uv); f = f*f*(3.0-2.0*f);", "vec4 v = vec4(uv0.x+uv0.y+uv0.z, uv1.x+uv0.y+uv0.z,", "uv0.x+uv1.y+uv0.z, uv1.x+uv1.y+uv0.z);", "vec4 r = fract(sin(v*1e-1)*1e3);", "float r0 = mix(mix(r.x, r.y, f.x), mix(r.z, r.w, f.x), f.y);", "r = fract(sin((v + uv1.z - uv0.z)*1e-1)*1e3);", "float r1 = mix(mix(r.x, r.y, f.x), mix(r.z, r.w, f.x), f.y);", "return mix(r0, r1, f.z)*2.-1.;", "}", "void main( void ) {", "vec2 UV = pos.xy / resolution.xy + gl_FragCoord.xy / resolution.xy * scale.xy;", "UV.x *= resolution.x / resolution.y;", "UV /= cloudsStart;", // ATMOSPHERE "float finalAtmosphere = 1.0 - (length(UV) / atmosphereEnd);", "finalAtmosphere = max(.0, finalAtmosphere);", "gl_FragColor = vec4(finalAtmosphere);", "}", ];Do we have an expert on this subject? If I could just access the world-matrix I think everything would work out. Otherwise, maybe I can do something we a rendertexture or alike and then translate it afterwards. I'm looking for a performance effective way that solves this problem. What I have now is something that seems to work as long as the player is in 0, 0 compared to the sprite with the filter, but when moving away it starts to rotate funny and offset as well. Link to comment Share on other sites More sharing options...

## Recommended Posts