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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:21:54+00:00 2026-06-14T10:21:54+00:00

OK so i have a really big square (grid) that I have made up

  • 0

OK so i have a really big square (grid) that I have made up using triangles, then applied a heightmap to bump it. What im trying to do now is get grid lines on it. I have figured out a way to do this but this results in 33 if statements in the fragment shader just for x and then another 33 for y. I have been told I can use what im doing now and implement it slightly differently (using some GLSL function) to only need 1 or 2 if statements. This is my current code (not all finished but gives you the idea of what im doing.)

#version 330

uniform sampler2D texture;

in vec2 texCoord;

layout (location=0) out vec4 fragColour;



void main(void) {

vec4 newColor;
vec2 line = texCoord * 32; // makes texCoords easier to number (as divided by 32 in the C++array)


if(line.x > 0 && line.x < 0.9)
{
    newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 1 && line.x < 1.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 2 && line.x < 2.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 3 && line.x < 3.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 4 && line.x < 4.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 5 && line.x < 5.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 6 && line.x < 6.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 7 && line.x < 7.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 8 && line.x < 8.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 9 && line.x < 9.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 10 && line.x < 10.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 11 && line.x < 11.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 12 && line.x < 12.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 13 && line.x < 13.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 14 && line.x < 14.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 15 && line.x < 15.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 16 && line.x < 16.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 17 && line.x < 17.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 18 && line.x < 18.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 19 && line.x < 19.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 20 && line.x < 20.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 21 && line.x < 21.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 22 && line.x < 22.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 23 && line.x < 23.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}
    else if(line.x > 24 && line.x < 24.9)
{
     newColor = vec4(1.0,1.0,1.0,1.0);
}

else
{
    newColor = vec4(0.0,0.0,0.0,1.0);
}

fragColour = newColor;
}
  • 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-14T10:21:55+00:00Added an answer on June 14, 2026 at 10:21 am

    YOu shouldn’t use control flow (that depedns on something other than uniform) unless it is absolutely necessary (at least that was standard recommendation last time I wrote a glsl shader). In your case control flow isn’t needed. Use step, smoothstep, mix and multiplication to avoid control flow.

    Your “if/else” segment of code could be implemented using something like this (untested code):

    fragColor = mix(vec4(0.0, 0.0, 0.0, 0.0), vec4(1.0, 1.0, 1.0, 1.0), step(fract(line.x), 0.9));

    Or using texture lookup. Texture lookup might be faster than numerical calculation, depending on hardware (and texture size)

    Please note that using “step” might produce jagged non-antialiased edges and noise/moire pattern on faraway surfaces. “OpenGL orange book” (“OpenGL shading language”) had some examples that should explain how to deal with it. However, using texture lookup might be easier. For a start, you could try using “smoothstep” instead of “step”.

    Or, alternatively, you could simply redraw entire landscape in wireframe mode on top of solid rendered landscape.

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

Sidebar

Related Questions

I have a really big .less file that I am trying to break into
I have a project going on right now that is really big data model
I have a website that just takes a really big form and saves the
I have an NodeJS Express app that is getting really big in just one
Im trying to create a really big sql table that consists of 900 attributes.
I have a really big project that will use for example mails, contacts and
I have had really big problems understand the char* lately. Let's say I made
I'm trying to calculate the square root of a really big number in Ruby.
I have really big Oracle table with many columns that are not relevant to
My application has a few portions that have really big buttons (640x130, 230x150, etc.)

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.