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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:47:42+00:00 2026-05-31T13:47:42+00:00

I am just learning OpenGL, and I’m realizing that for more complex shader effects,

  • 0

I am just learning OpenGL, and I’m realizing that for more complex shader effects, there are basically two stategies that you can use to implement them. The first is to write one complicated vertex and fragment shader that accepts a number of different uniform variables from the main program, and decides what to do in the shader. Ex. if I want to make pixels in one context blue and in another context green, I might do in GLSL:

uniform int whichColor;
int main() {
    if (whichColor == 1) {
        gl_FragColor = vec4(0,1.0,0,1.0);
    }
    else {
          gl_FragColor = vec4(0,0,1.0,1.0);
    }
 }

and pass different ints to whichColor in my C++ drawing loop. Alternatively, I could just define two separate shader programs, one of which sets gl_FragColor to blue and the other to green, and simply load one or the other when it is time for me to draw a particular object in my OpenGL scene.

I can’t seem find any information on which one of these strategies is better, though. I might expect the first strategy, putting all the complexity of what to render on the graphics card, to be more performant, but in the sorts of cases I’m thinking of deciding what to draw isn’t a per-pixel calculation and doesn’t benefit from parallelization. I don’t really understand how the shader programs run on the graphics card and what the costs of linking and passing variables are, so I’m not sure that my intuition is actually correct here.

  • 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-31T13:47:43+00:00Added an answer on May 31, 2026 at 1:47 pm

    I’ve looked for answers on this topic a while ago, too. What I’ve gathered from a few different games and books is that you’d generally use different shaders.

    You can compile all needed shader programs once and make every object-to-be-drawn switch to the required shader program:

    void Draw(){
    
        glUseProgram(yourShaderProgram);
    
        glUniformX(yourUniformVariables);
    
        glDrawArrays(yourVAO);
    
    }
    

    What you do NOT want to do is load and link the shader program everytime you need it.

    Rather, keep a list of all shader programs somewhere, or pass the program’s id to each objects so they can make use of it.

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

Sidebar

Related Questions

Im just learning SQLite and I can't get my parameters to compile into the
Just learning about sql joins and things, and I have a question. Can you
I am learning OpenGL and just started getting into lighting. I enable lighting and
Im using OpenGL for an app that im trying to make. I've been learning
Since I'm just learning C# with .NET, (I have more experience with the XNA
im learning to use openGL and iv been told that because my wheel arches
I'm a student just learning xml and c#. I'm writing a program that will
Just started learning OpenGL and couldn't find a decent tutorial to get me going.
Just learning PHP and I'm having some trouble understanding mysql_query. My understanding is that
Just learning more about threads and concurrency, and thought of playing around with a

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.