Shader Issue
Posted: Sat Apr 04, 2015 1:37 am
I'm trying to create a shader that will warp my output by by scaling the x axis based on the y position of the pixel. It's working but the sides of the output image are curved instead of straight? Any ideas what I'm doing wrong? Here is the shader and the input and output images are attached.
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords )
{
// We need to calculate the pixel that will end up "here" after the transformation
// so we need to find the pixel that when scaled by x will end up here.
// Note: Texture Y is inverted so 1,1 is upper right
// We have a linear scale in as Y changes. Scale goes from 2 to 1
float x_scale = (2.0 - (texture_coords.y));
texture_coords.x = ((texture_coords.x - .5) * x_scale) + .5;
// If the pixel is off the screen just use black
if(texture_coords.x < 0 || texture_coords.x >= 1){
return vec4(0.0,0.0,0.0,1.0);
}
else
{
return Texel(texture,texture_coords);//This is the current pixel
}
}
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords )
{
// We need to calculate the pixel that will end up "here" after the transformation
// so we need to find the pixel that when scaled by x will end up here.
// Note: Texture Y is inverted so 1,1 is upper right
// We have a linear scale in as Y changes. Scale goes from 2 to 1
float x_scale = (2.0 - (texture_coords.y));
texture_coords.x = ((texture_coords.x - .5) * x_scale) + .5;
// If the pixel is off the screen just use black
if(texture_coords.x < 0 || texture_coords.x >= 1){
return vec4(0.0,0.0,0.0,1.0);
}
else
{
return Texel(texture,texture_coords);//This is the current pixel
}
}