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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:45:26+00:00 2026-05-31T21:45:26+00:00

I’m trying to implement phong shading to no avail. I am building the shaders

  • 0

I’m trying to implement phong shading to no avail. I am building the shaders bit by bit (which could be an issue in itself) but here is where I am at currently. I would expect this to output my result (the Utah teapot) as a white image on my black background. It does this correctly when I remove line 18 from the vertex shader, but when the line is there there is no output, and no error. Any ideas?

Fragment Shader:

  1 #version 120                                                                                      
  2                                                                                                   
  3 varying vec3 vertexNormal;                                                                        
  4 varying vec3 cameraSpacePos;                                                                      
  5                                                                                                   
  6 vec3 calcSpecular(vec3 l, vec3 n, vec3 v, vec3 cL, vec3 cS, float p)                              
  7 {                                                                                                 
  8     vec3 r =  2.0 * n * (n * l) - l;                                                              
  9     return cL * cS * pow(max(0.0, dot(r, v)), p);                                                 
 10 }                                                                                                 
 11                                                                                                   
 12 vec3 calcDiffuse(vec3 l, vec3 n, vec3 cL, vec3 cD)                                                
 13 {                                                                                                 
 14     return cL * cD * max(0.0, dot(n, l));                                                         
 15 }                                                                                                 
 16                                                                                                   
 17 void main(void)                                                                                   
 18 {                                                                                                 
 19     vec3 lightDirection = normalize(vec3(-1.0, 0.0, -1.0));                                       
 20     vec3 objectColor    = vec3(0.5, 0.0, 0.0);                                                    
 21     vec3 ambientColor   = vec3(0.1, 0.1, 0.1);                                                    
 22     vec3 lightColor     = vec3(0.3, 0.0, 0.3);                                                    
 23     vec3 specularColor  = vec3(1.0, 1.0, 1.0);                                                    
 24                                                                                                   
 25     gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);                                                      
 26 }                   

Vertex Shader:

  1 #version 120
  2 
  3 uniform mat4 modelView;
  4 uniform mat4 normalModelView;
  5 uniform mat4 projection;
  6 
  7 attribute vec3 position;
  8 attribute vec3 normal;
  9 
 10 varying vec3 vertexNormal;
 11 varying vec3 cameraSpacePos;
 12 
 13 void main(void)
 14 {
 15     vec4 tmpCameraSpacePos = modelView * vec4(position, 1.0);
 16     gl_Position    = projection * tmpCameraSpacePos;
 17 
 18     vertexNormal = (normalModelView * vec4(normal, 0.0)).xyz;
 19     cameraSpacePos  = (tmpCameraSpacePos).xyz;
 20 
 21 }
 22

It may also be worth mentioning that normal and normalModelView are not currently being set. I had tried with them enabled previously to similar results. My understanding is that they should be set to default values.

  • 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-31T21:45:27+00:00Added an answer on May 31, 2026 at 9:45 pm

    Since you mentioned that normal and normalModelView are not being set, my guess is that they are not being set to default values either, and are technically invalid data. When invalid data is used in a shader, the results are undefined, part of the reason why shaders are difficult to debug. Make sure that you’re providing values for those variables before you try to reference them in the code.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to select an H1 element which is the second-child in its group
This could be a duplicate question, but I have no idea what search terms
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:

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.