Before I start rendering I set the material properties with the following function:
private void SetMaterial(B3DMaterial m)
{
if (m == null)
{
m = new B3DMaterial();
}
Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_AMBIENT, m.AmbientColor);
Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_DIFFUSE, m.DiffuseColor);
Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_SPECULAR, m.SpecularColor);
Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_EMISSION, m.EmissiveColor);
float s = m.Shininess;
s *= 128;
Gl.glMaterialf(Gl.GL_FRONT, Gl.GL_SHININESS, s);
}
(The B3DMaterial is a wrapper class that contains the properties of the material.)
During the rendering there is a rotation of my objects. When I watch the restult I slowly see the model light up when it enters the light and see it darken when it leaves the light again.
But the strange thing is that all parts of the model have the same colour during this process. In other words my objects appear to be flat. What am I doing wrong?
This is probably something obvious I am missing. I am a real beginner and it is the first time I tried to render material properties.
Do them yourself, it’s no biggie. Lighthouse3D has a good introduction to normals
or maybe this will help a little, it’s copypasted from my own engine so you have to rewrite it a little for it to work.
all vars are floats(exept for vr)
Eventually you will also learn how to smothly blend the normals with each other giving your geometry a more rounded apperance, but that is a whole other issue.
Thank you all! It is starting to work pretty well. Especially when I split up the faces first in several triangles. The more triangles the nicer it looks . Also I’ve been avereging the normals with the normals of their neighbours, this also seems to help.
Eventually you will also learn how to smothly blend the normals with each other giving your geometry a more rounded apperance, but that is a whole other issue.
That’s a usual practice? The last hyperlinks you people gave me were really helpful. Is there also a good tutorial on how to get started blending the normals?
Yes it’s a usual practice.
You need to average all normals that share the same vertic as you said you where doing, personally i am also discarding normals (from being ingluded in the average of the current normal) based on the dotproduct of the two normals, if it’s over 0.707 i don’t use them for averaging.
this will alow you to still have both sharp edges and smooth polygons with the same algothitm.
Just keep experimenting and you will eventually get it.