Sign in to follow this  
ade-the-heat

texture rectangle in a shader

Recommended Posts

ade-the-heat    163
Suppose I use a texture rectagle in a shader, eg I've drawn it as
glBegin(GL_QUADS);
    glTexCoord2f(0.0, 0.0); 
    glVertex2f(0.0, 0.0);
    glTexCoord2f(texSize, 0.0); 
    glVertex2f(texSize, 0.0);
    glTexCoord2f(texSize, texSize); 
    glVertex2f(texSize, texSize);
    glTexCoord2f(0.0, texSize); 
    glVertex2f(0.0, texSize);
glEnd()
Then in my shader I want to read an offset from the current pixel in the calculation, for a usual texture we can simply calculate the offset as below:
float offset = 1/texsize
vec2 bl=vec2(tex2D(tex,coords+offset)) +
        vec2(tex2D(tex,coords-offset); 
glFragColor=bl;
However, for a rectangle texture can I simply do the following?
float offset = 1;
vec2 bl=vec2(tex2D(tex,coords+offset)) +
        vec2(tex2D(tex,coords-offset); 
glFragColor=bl;
cheers

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this