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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:15:21+00:00 2026-06-05T01:15:21+00:00

I have created a project on top of the XCode OpenGL ES template. Is

  • 0

I have created a project on top of the XCode OpenGL ES template.

Is there a way to customize the shader color for each object?

Shader.vsh:

attribute vec4 position;
attribute vec3 normal;

varying lowp vec4 colorVarying;

uniform mat4 modelViewProjectionMatrix;
uniform mat3 normalMatrix;

void main()
{
    vec3 eyeNormal = normalize(normalMatrix * normal);
    vec3 lightPosition = vec3(1.0, 1.0, 1.0);
    vec4 diffuseColor = vec4(1, 0.4, 1.0, 1.0);

    float nDotVP = max(0.0, dot(eyeNormal, normalize(lightPosition)));

    colorVarying = diffuseColor * nDotVP;

    gl_Position = modelViewProjectionMatrix * position;
}

Shader.fsh:

varying lowp vec4 colorVarying;

void main()
{
    gl_FragColor = colorVarying;
}

Do i need to create an extra attribute in Shader.vsh which parses the color to replace diffuse variable or how is this done?

  • 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-05T01:15:22+00:00Added an answer on June 5, 2026 at 1:15 am

    I suggest using uniform variables for colors

    // put this in Shader.vsh, before the main()
    uniform vec4 diffuseColor;
    

    and in the code just set the value:

    glUseProgram(progID);
    
    // object 1 (R, G, B, A is a color)
    glUniform4f(glGetUniformLocation(progID, "diffuseColor"), R, G, B, A);
    draw_object_1();
    
    // object 2 (R, G, B, A is a color)
    glUniform4f(glGetUniformLocation(progID, "diffuseColor"), R, G, B, A);
    draw_object_2();
    

    the same can be done with light position as well.

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

Sidebar

Related Questions

For our project I have created a framework on top of the PHPUnit framework
I have created a project in Netbeans using my mac , now when i
I have created the project which consists of 5 xibs. When I try to
I have created a project in Dashcode, inserted a List control, enabled a dynamic
I have created a project that uses scala that has some abstract classes definitions
I have created SSRS project in BIDS and I want to use the reports
I am using qt 4.5 I have created a project and I want to
I'm in the process of setting up TFS and have created a project with
I am trying to write my first WCF project. I have created a project
I have created a new project in Ios5 using storyboards and my project has

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.