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

  • Home
  • SEARCH
  • 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 9091941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:43:48+00:00 2026-06-16T22:43:48+00:00

In OpenGL , sometimes when doing multi-pass rendering and post-processing I need to apply

  • 0

In OpenGL , sometimes when doing multi-pass rendering and post-processing I need to apply texels to the primitive’s assembly fragments which are part of full screen texture composition.That is usually the case when the current pass comes from FBO texture to which the screen quad had been rendered during previous pass.To achieve this I calculate objects UV coordinates in SCREEN SPACE .In GLSL I calculate it like this:

     vec2 texelSize = 1.0 / vec2(textureSize(TEXTURE, 0));
 vec2 screenTexCoords = gl_FragCoord.xy * texelSize;

Now I am experimenting with Unity3D which uses CG/HLSL.The docs for these languages are poor.How can I calculate screen uv coordinates in CG/HLSL?

  • 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-06-16T22:43:50+00:00Added an answer on June 16, 2026 at 10:43 pm

    To calculate screen texcoords, you typically pass the screen resolution or reciprocal thereof (res or rcpres) to the shader, then use the texcoords from your fullscreen quad (assuming a range of [0,1]) modified by those.

    Edit: Note that in many cases, you want both res and rcpres available. res is useful for calculating the current position (you wouldn’t want to use rcpres for that, since it would then require division), but rcpres can be calculated once on the CPU and is useful for moving by a single texel ((res * uv) + rcpres) is one more texel from origin).

    Something like:

    float2 res; // contains the screen res, ie {640, 480}
    
    void postEffect(in float2 uv : TEXCOORD, ...)
    {
        float2 pos = uv * res; // pos now contains your current position
    

    The logic being that the coords coming from the fs quad are 0,0 at texel 0,0 and 1,1 at texel maxX,maxY, so knowing the dimensions, you can just multiply.

    You have to provide the value of res to each effect, however, which depends on your shader system (Unity3D may do it already).

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

Sidebar

Related Questions

I'm currently using CADisplayLink to show an OpenGL animation which works great. Sometimes, however
Sometimes in my OpenGL application I get an access violation in the following API
Using OpenGL ES I am rendering a simple cube class that draws it at
I'm using OpenGL ES in my iPhone application and sometimes during startup the screen
I'm using OpenGL ES to draw things in my iPhone game. Sometimes I like
I like the convenience of NSMutableArray but sometimes you just need to drop down
On my OpenGL ES 2.0 App - Using the iPhone simulator sometimes is dirt
OpenGL ES 2.0 doesn't have the GL_POINT_SMOOTH definition which ES 1.0 does. This means
I'm drawing 2D, concave, sometimes multicontoured, sometimes self intersecting polygons with OpenGL. Here is
We have a 3D viewer that uses OpenGL, but our clients sometimes complain about

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.