Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6684705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:58:16+00:00 2026-05-26T04:58:16+00:00

I am passing a texture with NxM size as a sampler in the GLSL

  • 0

I am passing a texture with NxM size as a sampler in the GLSL fragment shader (OpenGL ES 2.0). What is the right way to read the texel data from the neighboring texel ? I do not have a “varying” texture coordinate in the fragment shader. I can only use fragment coordinate to read the texture information.

following is my shader, I am not sure if its actually reading the data:

precision mediump float;

uniform sampler2D Sampler;

#define OFFSET 1.0

void main()
{

    vec2 T = gl_FragCoord.xy;

    //Find neighboring velocities:
    vec2 N = texture2D(Sampler,vec2(T.x,T.y+OFFSET)).xy;
    vec2 S = texture2D(Sampler,vec2(T.x,T.y-OFFSET)).xy;
    vec2 E = texture2D(Sampler,vec2(T.x+OFFSET,T.y)).xy; 
    vec2 W = texture2D(Sampler,vec2(T.x-OFFSET,T.y)).xy; 
}

Is the OFFSET value should be 1.0 OR something else for NxM size texture ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:58:16+00:00Added an answer on May 26, 2026 at 4:58 am

    Nem is right in his answer that the texture coordinate should be in [0,1]. But keep in mind, that the values of gl_FragCoord are in [0,N]x[0,M] (assuming your viewport is NxM, too). So you are correct in adding an offset of 1 to the fragment coordinate, but this sum has then to be divided by the screen size (which is probably the same as the texture size):

    precision mediump float;
    
    uniform sampler2D Sampler;
    uniform vec2 invScreenSize;
    
    void main()
    {
    
        vec2 T = gl_FragCoord.xy;
    
        //Find neighboring velocities:
        vec2 N = texture2D(Sampler,vec2(T.x,T.y+1.0)*invScreenSize).xy;
        vec2 S = texture2D(Sampler,vec2(T.x,T.y-1.0)*invScreenSize).xy;
        vec2 E = texture2D(Sampler,vec2(T.x+1.0,T.y)*invScreenSize).xy; 
        vec2 W = texture2D(Sampler,vec2(T.x-1.0,T.y)*invScreenSize).xy; 
    }
    

    where invScreenSize is the reciprocal screen size (1/N, 1/M), to prevent division in the shader.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm debating the pros and cons of passing texture coordinates to a GLSL shader
Shaders can not read data from framebuffer, they can pass data only forward by
Passing small amount of data from one controller to another controller, do I use
Passing data from a controller to another controller. this is what i am doing,
passing post data using cURL requires that the name of the input. However, I
warning: passing argument 1 of 'bsearch' makes pointer from integer without a cast and
I am passing an object from one asp.net page to another. I'm encoding the
I'm passing data between my controller and my view using a ViewModel class. When
I am passing a PHP array to a javascript function. The only way I
I'm trying to draw a subregion of a texture in OpenGL by specifying the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.