Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float3 LensDistortionPass(float2 tex){
- // lens distortion coefficient (between
- float k = -0.15;
- // cubic distortion value
- float kcube = 0.5;
- float r2 = (tex.x-0.5) * (tex.x-0.5) + (tex.y-0.5) * (tex.y-0.5);
- float f = 0.0;
- //only compute the cubic distortion if necessary
- if (kcube == 0.0){
- f = 1 + r2 * k;
- }
- else {
- f = 1 + r2 * (k + kcube * sqrt(r2));
- };
- // get the right pixel for the current position
- float x = f*(tex.x-0.5)+0.5;
- float y = f*(tex.y-0.5)+0.5;
- float3 inputDistord = tex2D(tDiffuse,float2(x,y)).rgb;
- return inputDistord;
- }
- float3 LensDistortionShader(float4 position : SV_Position, float2 texcoord : TEXCOORD0) : SV_Target {
- float3 color = LensDistortionPass(texcoord).rgb;
- return color.rgb;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement