Archived

This topic is now archived and is closed to further replies.

Willywig

Phong Shading

Recommended Posts

siaspete    208
"Been there, done that"? This may seem rude, but go there and do it again!

I typed "phong shading tutorial" into the box and there are plenty of great links.

http://www.google.com/search?q=phong+shading+tutorial

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
quote:
Original post by Oluseyi
[quote]Original post by Willywig
Been there done that

Liar.

Don''t get mad at me; I''m the blunt one.




I wanna work for Microsoft!


I did look and all the ones that i found there where not very good.... So I will rephrase the question.... Where are some GOOD tutorials?

Ps. I do work for microsoft

Share this post


Link to post
Share on other sites
no way    122
All you need is Phongs lighting model equation, if you are a CODER you should be able to continue from here.
Kd * (N dot L) + Ks * (R dot V)^n
If this doesnt make sense to you, you are asking the wrong question.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
quote:
Original post by Anonymous Poster
[quote]Original post by Oluseyi
[quote]Original post by Willywig
Been there done that

Liar.

Don''t get mad at me; I''m the blunt one.




I wanna work for Microsoft!


I did look and all the ones that i found there where not very good.... So I will rephrase the question.... Where are some GOOD tutorials?

Ps. I do work for microsoft



If you work for microsoft, you can afford a decent graphics reference book. Something like Watt''s Advanced Animation and Rendering techniques will cover this.

You don''t find many tutorials on phong shading or phong reflectance because it''s a very basic technique, and not very interesting to study on it''s own.

Share this post


Link to post
Share on other sites
siaspete    208
This link here was found on the search I did on google for "phong shading tutorial"

http://www.geocities.com/SiliconValley/Horizon/6933/shading.html

It has code, diagrams, and links to other resources about phong shading.

If someone isn''t willing to look for information that is this easy to find, then I don''t see how they have what it takes to code anything like a 3d renderer.

Share this post


Link to post
Share on other sites
TerranFury    142
quote:
Original post by no way
All you need is Phongs lighting model equation, if you are a CODER you should be able to continue from here.
Kd * (N dot L) + Ks * (R dot V)^n
If this doesnt make sense to you, you are asking the wrong question.


Explaining what all those variables are might help. N seems to be the surface normal; L seems to be the normalized light vector; Ks seems to be the specularity coefficient; Kd seems to be the diffuse coefficient; R seems to be the reflected light vector; V seems to be the view vector; and n is.... another specularity changer thingy.... (Ks changes the intensity; n changes the "falloff" of the bright dot)

How good were those guesses?

(And what are the "official" names for Ks and n?)

Share this post


Link to post
Share on other sites
BStaz    122
// CROSSES FINGERS HOPS THIS POSTS OKAY...


// if the ray from the light hits the current object we ARE NOT IN THE SHADOW
// and we have to take into account the effects of the light.
if( Light_Results->HitObject == Ray_Results->HitObject )
{

// When we made the intersection from the original ray and out Ray Type was RAY_LIGHT we set
// a pointer to the light source.. get that pointer now.
Base_Light* CurrentLight = (*Ray_itor)->SourceLight;

// make sure the pointer is valid.
assert( Current_Light );


// Now we need to Make normalized 3 vectors.

Vector3f Int_To_eye; // Intersection Point To The Eye
Vector3f Int_To_lit; // Intersection Point to The Light we are current working with;
Vector3f lit_To_Int; // Light to the Intersection Point


// Make Intersection Point to Eye
Int_To_eye = (*Ray_Results->Casted_Ray->Ray_Origin) - (*Ray_Results->IntersectionPt);
Int_To_eye.Normalise();

// Make Intersection Point to Light
Int_To_lit = (*CurrentLight->GetPosition()) - (*Ray_Results->IntersectionPt);
Int_To_lit.Normalise();

// Make Light to the Intersection Point
lit_To_Int = (*Ray_Results->IntersectionPt) - (*CurrentLight->GetPosition());
lit_To_Int.Normalise();



// Find the Dot Product of the Normal and the Ray from the Intersection Point To the Eye
float n_dot_eye = (Ray_Results->Normal)->Dot( Int_To_eye );

// Find the Dot Product of the Normal and the Ray from the Light To the Intersection Point
float n_dot_light = (Ray_Results->Normal)->Dot( lit_To_Int );

// Check to see if both the EYE and the Light are on the same side of the object.
if((n_dot_eye > 0 && n_dot_light < 0) || (n_dot_eye < 0 && n_dot_light > 0))
{
// By adding the Int_To_lit & Int_To_Eye we are in effect getting the magnitude
// of the angle between them. The Smaller the angle between them the larger
// the result vector is. (also not that if you divde this by 2 you get the a
// point halfway between the two vectors.. thus it is called the ''Half'' vector!
Vector3f Half;
Half = Int_To_lit + Int_To_eye;

// Normalize it
Half.Normalise();

// We now take the Dot Product of the Half to see how close this resultant
// vector is to the Normal.. the close to the normal the brigher that point is.
float Spec = (*Ray_Results->Normal).Dot( Half );

// recap.. the closer the Eye and Light angles are together the brighter the
// point on the object is.. and also the closer that is to the normal the
// brighter the point is as well.


// take the abs value.. (need to verify we still need this..)
Spec = fabs( Spec );

// Use the Material Properties to get the shinness. (there are better light models out here..)
Spec = CurrentMaterial->GetShine_1() * pow( Spec, CurrentMaterial->GetShine_2() );

// Add the light & specular properties to the point.
CurrentColor.Red += MaterialColor->Red * Spec * CurrentLight->GetColor()->Red;
CurrentColor.Green += MaterialColor->Green * Spec * CurrentLight->GetColor()->Green;
CurrentColor.Blue += MaterialColor->Blue * Spec * CurrentLight->GetColor()->Blue;


// Add in the diffuse lighting to the object.

// The closer the Ray from the Intersection Point to the Normal the brighter the point.
float Diffuse = (*Ray_Results->Normal).Dot( (Int_To_lit) );
Diffuse = fabs( Diffuse );

CurrentColor.Red += MaterialColor->Red * Diffuse * CurrentLight->GetColor()->Red;
CurrentColor.Green += MaterialColor->Green * Diffuse * CurrentLight->GetColor()->Green;
CurrentColor.Blue += MaterialColor->Blue * Diffuse * CurrentLight->GetColor()->Blue;

}
}
}

Share this post


Link to post
Share on other sites