Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
if else condition is not working in opengl glsl shading language

I am using this code on glsl script

but when i use if else condition it not works , every time i run script it choose the first value of color variable which is declared before if else condition.

float color = 0.3 * clr.r + 0.59 * clr.g + 0.11 * clr.b; // script always choose this value instead of if else values

float maxrgb = max(max(clr.r, clr.g), clr.b);

if (maxrgb < 128.0) {
  float color = 0.21 * clr.r + 0.71 * clr.g + 0.80 * clr.b;
} else if (maxrgb > 128.0) {
  float color = 0.30 * clr.r + 0.60 * clr.g + 0.82 * clr.b;
} // the values in the condition are not working.

is am i doing something wrong ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have declared the color variable twice. You have declared a new variable with the same name in scope of the if-statement. Declare the variable before the if statement, but assign new values to the existing variable in the statement:

float color = 0.3 * clr.r + 0.59 * clr.g + 0.11 * clr.b; 

float maxrgb = max(max(clr.r, clr.g), clr.b);

if (maxrgb < 128.0) {
    color = 0.21 * clr.r + 0.71 * clr.g + 0.80 * clr.b;
} else if (maxrgb > 128.0) {
    color = 0.30 * clr.r + 0.60 * clr.g + 0.82 * clr.b;
} 
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!