2

When I set the material in opengl for an object (glutSolidSphere(2.,10.,8.);), let for example the emerald parameters:

 float[] mat_ambient ={ 0.0215f, 0.1745f, 0.0215f, 0.55f };
 float[] mat_diffuse ={0.07568f, 0.61424f, 0.07568f, 0.55f };
 float[] mat_specular ={0.633f, 0.727811f, 0.633f, 0.55f };
 float shine = 76.8f;

In order to obtain really an emerald object I should set the components of light in the same way? I mean:

float[] light_ambient ={ 0.0215f, 0.1745f, 0.0215f, 0.55f };
float[] light_diffuse ={0.07568f, 0.61424f, 0.07568f, 0.55f };
float[] light_specular ={0.633f, 0.727811f, 0.633f, 0.55f };

float[] light_position= { 1.0, 1.0, 1.0, 0.0 };

The result is not good...

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Nik
  • 123
  • 4
  • 1
    If you want to render a green surface with a [Blinn–Phong reflection model](https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_reflection_model) and [Gouraud shading](https://en.wikipedia.org/wiki/Gouraud_shading) you have found the answer. However, you can't do anything more realistic with the 20-year-old OpenGL Fixed-Function pipeline. Same reason as in the comments on your previous question [How can I do a brass surface?](https://stackoverflow.com/questions/65509647/how-can-i-do-a-brass-surface). – Rabbid76 Dec 31 '20 at 08:09
  • @Raddib76 I have specified better my problem with the result obtained...it's an important homework... can you hel me please?? My reference is http://www.it.hiof.no/~borres/j3d/explain/light/p-materials.html.. I don't understand my result – Nik Dec 31 '20 at 08:17
  • 1
    No, I can't. It is not possible with this technology. In your example, the position of the light source appears to be behind the object (Note, the view space z axis points out of the viewport), but the result will never be of good quality. If you want to use OpenGL instead of a rendering engine (Unity, Unreal, ...)), I recommend reading a good tutorial. e.g. [LearnOpenGL](https://learnopengl.com/) – Rabbid76 Dec 31 '20 at 08:23
  • Now it's good in your opinion, at least fro what it is possible to do with this old tools? I have edited the image... – Nik Dec 31 '20 at 08:32
  • This is almost the best you can get. However, you can use a higher resolution for the sphere to get some specular highlights. – Rabbid76 Dec 31 '20 at 08:38
  • You may be interested in [GLSL fixed function fragment program replacement](https://stackoverflow.com/questions/8421778/glsl-fixed-function-fragment-program-replacement/45716107#45716107) and [What's the difference between Phong shading and Gouraud shading?](https://stackoverflow.com/questions/63958531/whats-the-difference-between-phong-shading-and-gouraud-shading) – Rabbid76 Dec 31 '20 at 08:39

1 Answers1

0

If you want to render a green surface with a Blinn–Phong reflection model and Gouraud shading you have found the answer. However, you can't do anything more realistic with the 20-year-old OpenGL Fixed-Function pipeline. Same reason as in the comments on your previous question How can I do a brass surface?.
With Gouraud shading the ligh model is computed per vertex, compared to Phong shadding where it is computed per fragment. Use a higher resolution on the sphere to improve lighting and get some specular highlights. See GLSL fixed function fragment program replacement and What's the difference between Phong shading and Gouraud shading?.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174