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

  • Home
  • SEARCH
  • 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 1079081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:48:59+00:00 2026-05-16T21:48:59+00:00

In a tutorial there was a diffuse value calculation of the type float diffuse_value

  • 0

In a tutorial there was a diffuse value calculation of the type

float diffuse_value = max(dot(vertex_normal, vertex_light_position), 0.0);

..on the vertex shader.

That was supposed to be making per vertex lighting if later on the fragment shader..

gl_FragColor = gl_Color * diffuse_value;

Then when he moved the first line – appropriately (by outputting vertex_normal and vertex_light_position to fragment) – to the the fragment shader, it is supposed to be transforming the method to “per pixel shading”.

How is that so? The first method appears to be doing the diffuse_value calculation every pixel anyway!

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

    diffuse_value in the first case is computed in the vertex shader. So it’s only done per vertex.

    After the vertex shader outputs values, the rasterizer takes those values (3 per triangle for each vector) and interpolates (in a perspective correct manner) them to provide different values for each pixel. As it happens, interpolating vectors like that (the normal and the light direction vectors) is not proper, because it loses their normalized property. Many implementations will actually normalize the vectors first thing in the fragment shader.

    But it’s worse to interpolate the dot of the 2 vectors (what the vector lighting effectively does). Say for example that your is N=+Z for all your vertices and L=norm(Z-X) on one and L=norm(Z+X) on another.

    N.L = 1/sqrt(2) for both vertices. 
    

    Interpolating that will give you a flat lighting, whereas actually interpolating N and L separately and renormalizing will give you the result you’d expect, a lighting that peaks exactly in the middle of the polygon. (because the interpolation of norm(Z-X) and norm(Z+X) will give exactly Z once normalized).

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

Sidebar

Ask A Question

Stats

  • Questions 535k
  • Answers 535k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It's available on the Subpatterns page of the official documentation.… May 17, 2026 at 1:05 am
  • Editorial Team
    Editorial Team added an answer As with so many things, it depends on your needs… May 17, 2026 at 1:05 am
  • Editorial Team
    Editorial Team added an answer One obvious way could be creating your own MyActivity class… May 17, 2026 at 1:05 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I followed this tutorial (there's a bit more than what's listed here because in
In the tutorial there is an example for finding prime numbers: >>> for n
In day 2 of the go tutorial there is this exercise: Why may it
Is there any tutorial out there on how to write a FileUpload in asp.net
Is there some sample code or a tutorial out there about how to draw
i wonder if theres a tutorial out there or you could give me a
I am studying some examples in a tutorial where there are a lot of
Is there any tutorial out there showing how to use OAuth on IPhone? Basically
What is the most comprehensive MD5 tutorial out there? I have been trying to
Is there anyway to do Files Handling in Objective-C? I am just trying to

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.