Jump to content
  • Advertisement
Sign in to follow this  
ms75214

phong kong

This topic is 2541 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Any tips on where to get good opengl fragment shaders?


Also, is this basically phong shading?


varying vec3 normal;
varying vec3 vertex_to_light_vector;

void main()
{
// Defining The Material Colors
const vec4 AmbientColor = vec4(0.1, 0.0, 0.0, 1.0);
const vec4 DiffuseColor = vec4(1.0, 0.0, 0.0, 1.0);

// Scaling The Input Vector To Length 1
vec3 normalized_normal = normalize(normal);
vec3 normalized_vertex_to_light_vector = normalize(vertex_to_light_vector);

// Calculating The Diffuse Term And Clamping It To [0;1]
float DiffuseTerm = clamp(dot(normal, vertex_to_light_vector), 0.0, 1.0);

// Calculating The Final Color
gl_FragColor = AmbientColor + DiffuseColor * DiffuseTerm;
}

Share this post


Link to post
Share on other sites
Advertisement

Any tips on where to get good opengl fragment shaders?


Also, is this basically phong shading?


varying vec3 normal;
varying vec3 vertex_to_light_vector;

void main()
{
// Defining The Material Colors
const vec4 AmbientColor = vec4(0.1, 0.0, 0.0, 1.0);
const vec4 DiffuseColor = vec4(1.0, 0.0, 0.0, 1.0);

// Scaling The Input Vector To Length 1
vec3 normalized_normal = normalize(normal);
vec3 normalized_vertex_to_light_vector = normalize(vertex_to_light_vector);

// Calculating The Diffuse Term And Clamping It To [0;1]
float DiffuseTerm = clamp(dot(normal, vertex_to_light_vector), 0.0, 1.0);

// Calculating The Final Color
gl_FragColor = AmbientColor + DiffuseColor * DiffuseTerm;
}

The answer to #1 is 'write them yourself' in basically every case-- it's not all that hard to do and it gives you a lot of flexibility :)
The answer to #2 is 'no.' Phong shading can refer to two separate concepts that frequently crop up in computer graphics, specifically a method for calculating specular reflection of light and blending per-vertex normals and other attributes across the surface of a polygon. However, the term 'Phong shading' almost always refers to the specular reflection stuff, as the latter is just sort of taken for granted with the programmable pipeline as it all happens automagically.

Specifically, you're missing the pow( dot( vertex_to_camera_vector, reflect( normalized_vertex_to_light_vector, normalized_normal ) ), specular_power ) stuff to get 'true' Phong shading. With that said, I'd also suggest the more physically-meaningful Blinn-Phong approximation/improvement, which will look like pow( dot( normalized_normal, normalize( vertex_to_light_vector + vertex_to_viewVector ) ), specular_power ).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!