Help With Shaders?
I'm trying to make a barrel distortion shader for my current game project (in Game Maker), and I can't seem to figure out what's causing those giant pixels.
Vertex:
```
//
// Simple passthrough vertex shader
//
attribute vec3 inPosition; // (x,y,z)
//attribute vec3 inNormal; // (x,y,z) unused in this shader.
attribute vec4 inColour; // (r,g,b,a)
attribute vec2 inTextureCoord; // (u,v)
varying vec2 vvTexcoord; varying vec4 vvColour; varying vec2 v_vPosition;
uniform float BarrelPower; uniform vec4 u_uSource;
void main() { vec4 objectspacepos = vec4( inPosition.x, inPosition.y, inPosition.z, 1.0); glPosition = gmMatrices[MATRIXWORLDVIEWPROJECTION] * objectspacepos;
v_vColour = in_Colour;
v_vTexcoord = in_TextureCoord;
v_vPosition = in_Position.xy;
}
Fragment:
//
// Simple passthrough fragment shader
//
varying vec2 vvTexcoord;
varying vec4 vvColour;
uniform vec4 uuSource;
varying vec2 vvPosition;
uniform float BarrelPower;
float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); }
vec2 Distort(vec2 p) { float theta = atan(p.y, p.x); float radius = length(p); radius = pow(radius, BarrelPower); p.x = radius * cos(theta); p.y = radius * sin(theta); return 0.5 * (p + 1.0); }
void main() {
//float xx = v_vTexcoord.x;
//float yy = v_vTexcoord.y;
float xx = v_vPosition.x;
float yy = v_vPosition.y;
vec2 point = vec2(xx - u_uSource.x, (yy - u_uSource.y));
float len = length(point);
float ran = 24.0*rand(vec2(u_uSource.w+xx,yy));
if(len+ran>u_uSource.z) gl_FragColor.rgb = vec3(0.,0.,0.);
else {
vec2 cord = 2.0 * v_vTexcoord.xy - 1.0;
vec2 uv;
float d = length(cord);
if ( d < 1.5 ){
uv = Distort(cord);
} else {
uv = v_vTexcoord.xy;
}
vec4 c = texture2D( gm_BaseTexture, uv);
gl_FragColor = v_vColour * c;
}
} ```