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 6069305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:48:31+00:00 2026-05-23T09:48:31+00:00

I would like to efficiently render in an interlaced mode using GLSL. I can

  • 0

I would like to efficiently render in an interlaced mode using GLSL.

I can alrdy do this like:

vec4 background = texture2D(plane[5], gl_TexCoord[1].st);
if(is_even_row(gl_TexCoord[1].t))
{
    vec4 foreground = get_my_color();
    gl_FragColor = vec4(fore.rgb * foreground .a + background .rgb * (1.0-foreground .a), background .a + fore.a);
}
else
   gl_FragColor = background;

However, as far as I have understood the nature of branching in GLSL is that both branches will actually be executed, since “even_row” is considered as run-time value.

Is there any trick I can use here in order to avoid unnecessarily calling the rather heavy function “get_color”? The behavior of is_even_row is quite static.

Or is there some other way to do this?

NOTE: glPolygonStipple will not work since I have custom blend functions in my GLSL code.

  • 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-23T09:48:31+00:00Added an answer on May 23, 2026 at 9:48 am

    (comment to answer, as requested)

    The problem with interlacing is that GPUs run shaders in 2×2 clusters, which means that you gain nothing from interlacing (a good software implementation might possibly only execute the actual pixels that are needed, unless you ask for partial derivatives).

    At best, interlacing runs at the same speed, at worst it runs slower because of the extra work for the interlacing. Some years ago, there was an article in ShaderX4, which suggested interlaced rendering. I tried that method on half a dozen graphics cards (3 generations of hardware of each the “two big” manufacturers), and it ran slower (sometimes slightly, sometimes up to 50%) in every case.

    What you could do is do all the expensive rendering in 1/2 the vertical resolution, this will reduce the pixel shader work (and texture bandwidth) by 1/2. You can then upscale the texture (GL_NEAREST), and discard every other line.

    The stencil test can be used to discard pixels before the pixel shader is executed. Of course the hardware still runs shaders in 2×2 groups, so in this pass you do not gain anything. However, that does not matter if it’s just the very last pass, which is a trivial shader writing out a single fetched texel. The more costly composition shaders (the ones that matter!) run at half resolution.
    You find a detailled description including code here: fake dynamic branching. This demo avoids lighting pixels by discarding those that are outside the light’s range using the stencil.

    Another way which does not need the stencil buffer is to use “explicit Z culling”. This may in fact be even easier and faster.
    For this, clear Z, disable color writes (glColorMask), and draw a fullscreen quad whose vertices have some “close” Z coordinate, and have the shader kill fragments in every odd line (or use the deprecated alpha test if you want, or whatever). gl_FragCoord.y is a very simple way of knowing which line to kill, using a small texture that wraps around would be another (if you must use GLSL 1.0).
    Now draw another fullscreen quad with “far away” Z values in the vertices (and with depth test, of course). Simply fetch your half-res texture (GL_NEAREST filtering), and write it out. Since the depth buffer has a value that is “closer” in every other row, it will discard those pixels.

    How does glPolygonStipple compare to this? Polygon stipple is a deprecated feature, because it is not directly supported by the hardware and has to be emulated by the driver either by “secretly” rewriting the shader to include extra logic or by falling back to software.

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

Sidebar

Related Questions

I've around 80 instances of this class called Items and would like to efficiently
I would like to know how to efficiently implement filesystem changes in java? Say
Would like to get a list of advantages and disadvantages of using Stored Procedures.
I would like to efficiently generate a unique list of combinations of numbers based
I would like to delete parts from a binary file, using C++. The binary
I'm trying to create something like *.ascxs' factory. Scenario: I would like to render
I would like to efficiently compute the size of a filtered list, i.e., I
I have a container std::vector and I would like to efficiently split it into
I would like to know if there's an efficient algorithm to find the greatest
Which of these queries is more efficient, and would a modern DBMS (like SQL

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.