OpenGL API Specifications

Documents and Learning ResourcesSupport Libraries and FrameworksFunction Libraries and GeneratorsThis list contains some basic resources for getting started with, and developing for, OpenGL 3.0 and onwards. Contact your forum moderator if you want to contribute to the list or have any comments.-
##### Interactive Music / Sound Designer | Audio Programming

Raúl Ibarra Aranda -
##### SFX Designer/Composer/Dialogue/Audio Implementation

Matthewdeargameaudio -
##### Game Development Studio for Hire

JanJohansson

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Started by dgma9271, Sep 28 2009 12:10 PM

4: Adsense

**Guest**, the last post of this topic is over **60 days old** and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

- You cannot reply to this topic

7 replies to this topic

Posted 28 September 2009 - 12:10 PM

I'm new to opengl shading language. I see that dot product is used frequently
in shading language. My question is: what does it mean? I mean i know what dot
product is. It's simply the sum of the products of corresponding scalar components
of two vectors. But sayin' that when used in a glsl shader what does it actually
mean according to glsl context? Also why use it to calculate ambient, diffuse
and specular intensity?

Posted 28 September 2009 - 12:18 PM

In general you will find that the dot product operator is used quite frequently when dealing with lighting. This is because given two unit vectors, such as a face normal and the light direction normal, then the dot product gives us cos(θ). If you look at a sample lighting equation, like Phong, then you'll note that you can directly substitute that straight into the equation to get the resulting lighting value.

Posted 28 September 2009 - 12:19 PM

Dot product between 2 normalized vectors will give you a number that ranges from -1 to 1.

1 means that they are pointed the same way

-1 means they are pointed opposite ways.

0 means they are perpendicular.

(etc)

Anyhow, since many lighting calculations are based upon reflection, you need to do things like find the difference in angle between a triangle face's normal vs the direction of light, so dot product comes in useful there.

that's the high level reasoning, if you are curious for more details hopefully someone else can explain deeper (:

1 means that they are pointed the same way

-1 means they are pointed opposite ways.

0 means they are perpendicular.

(etc)

Anyhow, since many lighting calculations are based upon reflection, you need to do things like find the difference in angle between a triangle face's normal vs the direction of light, so dot product comes in useful there.

that's the high level reasoning, if you are curious for more details hopefully someone else can explain deeper (:

Posted 28 September 2009 - 12:33 PM

Quote:

Original post by dgma9271

But sayin' that when used in a glsl shader what does it actually mean according to glsl context?

It's important to realise that there's nothing particularly special about the built-in 'dot' function - it doesn't use any glsl context, nor does it change the glsl state. You'd get exactly the same results if you did the dot product manually.

The only difference is that by having it as a built-in function it allows for more efficient instructions to be generated under the hood.

Posted 28 September 2009 - 12:38 PM

Thanks for explaining it.

> Anyhow, since many lighting calculations are based upon reflection, you need to

> do things like find the difference in angle between a triangle face's normal vs

> the direction of light, so dot product comes in useful there.

>

> that's the high level reasoning, if you are curious for more details hopefully

> someone else can explain deeper (:

But how do you calculate angle difference with dot product? I could be wrong but

are you sayin that dot product of face normal and light direction is the angle

difference between them? Can you kindly explain a bit?

> Anyhow, since many lighting calculations are based upon reflection, you need to

> do things like find the difference in angle between a triangle face's normal vs

> the direction of light, so dot product comes in useful there.

>

> that's the high level reasoning, if you are curious for more details hopefully

> someone else can explain deeper (:

But how do you calculate angle difference with dot product? I could be wrong but

are you sayin that dot product of face normal and light direction is the angle

difference between them? Can you kindly explain a bit?

Posted 28 September 2009 - 12:40 PM

When you dot 2 vectors, you don't get the angle between them, you get the COSINE of the angle between them (:

so, you can do an inverse cosine to get the angle - OR, if you have need of the cosine of the angle, then you are done and can just use the dot product, it's kinda cool.

The vectors have to be normalized though for that to work.

so, you can do an inverse cosine to get the angle - OR, if you have need of the cosine of the angle, then you are done and can just use the dot product, it's kinda cool.

The vectors have to be normalized though for that to work.

Posted 28 September 2009 - 12:43 PM

Based on what Atrix256 said,

"Dot product between 2 normalized vectors will give you a number that ranges from -1 to 1.

1 means that they are pointed the same way

-1 means they are pointed opposite ways.

0 means they are perpendicular."

We can use this to calculate the angle between them, this is because you have the cosine between the two, so if you use inverse cos^-1(dot product between two vectors) that will give you the angle.

EDIT: Beaten to it ;)

"Dot product between 2 normalized vectors will give you a number that ranges from -1 to 1.

1 means that they are pointed the same way

-1 means they are pointed opposite ways.

0 means they are perpendicular."

We can use this to calculate the angle between them, this is because you have the cosine between the two, so if you use inverse cos^-1(dot product between two vectors) that will give you the angle.

EDIT: Beaten to it ;)

Posted 28 September 2009 - 12:48 PM

Thanks to ya all. I get it now.

> We can use this to calculate the angle between them, this is because you have

>the cosine between the two, so if you use inverse cos^-1(dot product between two

>vectors) that will give you the angle.

Ooops. I donno how i missed that. Thanks.

> We can use this to calculate the angle between them, this is because you have

>the cosine between the two, so if you use inverse cos^-1(dot product between two

>vectors) that will give you the angle.

Ooops. I donno how i missed that. Thanks.

**Guest**, the last post of this topic is over **60 days old** and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

Reply to quoted posts Clear

Copyright © 1999-2017 GameDev.net, LLC

GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.