Hey ladies and gentleman,

I’m trying to undistort a webcam by using a shader and I already have the specific parameters for the camera. I never used shader before and I’m also not using unity, but the only bit of code that i found which could be useful for me was this, which was written for CG in Unity:

i.imgur.com/4tN8Pg4.png (shown as text below)

So I want to know how you translate that bit of code to a GLSL shader so i can use it (namely in x3d) I already tried several programs to automaticly do it, but they always failed.

I hope somebody can help me out!

[HR][/HR]

uniform sampler2D _MainTex;

uniform float _F1;

uniform float _F2;

uniform float _OX;

uniform float _OY;

uniform float _K1;

uniform float _K2;

uniform float _K3;

uniform float _K4;

fixed4 frag (v2f_img i) : COLOR {

```
float2 ff = {_F1,_F2};
float2 xy = (i.uv - float2(_OX,_OY) / _ScreenParams.xy) / ff;
float r = sqrt(dot(xy,xy));
float r2 = r*r;
float r4 = r2 * r2;
float coeff = (_K1 * r2 + _K2 * r4);
float dx = _K3 * 2.0 * xy.x*xy.y + _K4*(r2+2.0*xy.x*xy.x);
float dy = _K3*(r2+2.0*xy.y*xy.y) + _K4*2.0*xy.x * xy.y;
xy = (((xy + xy * coeff.xx + float2(dx,dy)) * ff) + float2(_OX,_OY)) / _ScreenParams.xy;
fixed4 main = tex2D(_MainTex, xy);
return main;
```

}