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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:04:18+00:00 2026-06-12T11:04:18+00:00

The HLSL clip() function is described here . I intend to use this for

  • 0

The HLSL clip() function is described here.

I intend to use this for alpha cutoff, in OpenGL. Would the equivalent in GLSL simply be

if (gl_FragColor.a < cutoff)
{
    discard;
}

Or is there some more efficient equivalent?

  • 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-12T11:04:19+00:00Added an answer on June 12, 2026 at 11:04 am

    OpenGL has no such function. And it doesn’t need one.

    Or is there some more efficient equivalent?

    The question assumes that this conditional statement is less efficient than calling HLSL’s clip function. It’s very possible that it’s more efficient (though even then, it’s a total micro-optimization). clip checks if the value is less than 0, and if it is, discards the fragment. But you’re not testing against zero; you’re testing against cutoff, which probably isn’t 0. So, you must call clip like this (using GLSL-style): clip(gl_FragColor.a - cutoff)

    If clip is not directly support by the hardware, then your call is equivalent to if(gl_FragColor.a - cutoff < 0) discard;. That’s a math operation and a conditional test. That’s slower than just a conditional test. And if it’s not… the driver will almost certainly rearrange your code to do the conditional test that way.

    The only way the conditional would be slower than clip is if the hardware had specific support for clip and that the driver is too stupid to turn if(gl_FragColor.a < cutoff) discard; into clip(gl_FragColor.a - cutoff). If the driver is that stupid, if it lacks that basic pinhole optimization, then you’ve got bigger performance problems than this to deal with.

    In short: don’t worry about it.

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

Sidebar

Related Questions

I've seen this done long ago with hlsl/glsl shader code -- using an #include
does anyone know an implementation of the inverse FFT in HLSL/GLSL/cg ... ? It
I'm looking for a way to use a function as an argument to another
There are several shading languages available today like GLSL, HLSL, CG, which one to
I like Cg but it seems to be a long way behind GLSL/HLSL now
This is an HLSL question, although I'm using XNA if you want to reference
This question may look pretty simple, but I cannot find how HLSL handles its
Silverlight filter/class for cloud generation? Some HLSL or just C# class for generating clouds?
In HLSL, is there any way to limit the number of constant registers that
Is there any kind of HLSL or HYDRA Pixel Shader languages vorking in toch

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.