문제

I am currently looking for information on how to get the final flat color value of a given face within a lit 3d scene. I have a Material class that contains the following 4 colors:

ambient, specular, diffuse & emissive

My Color class has methods for simple blend effects such as add, multiply etc

From a list of lights, camera position, material, face normal & face position. I would like to calculate the final color of a face to be filled using a software render pipeline using the standard 4 color material model.

도움이 되었습니까?

해결책

I assume you want the standard Phong or Blinn-Phong lighting model, which the fixed-function GL uses, too.

The emissive term is the color the material emits by itself (for example when modeling a light). So it just adds to the final color.

color = emissive;

The ambient term simulates the indirect lighting computation due to infinitely reflected light, so it doesn't depend on the position of the light and is approximately everywhere. So the material's ambient is just multiplied by the light's color and adds to the final color.

color += ambient * lightColor;

The diffuse term simulates a standard Lambertian reflector, that reflects light equally in all directions. It depends on the angle between the direction to the light and the surface normal, with smaller angles resulting in more light.

lightDir = normalize(lightPos-facePos);
color += dot(lightDir, normal) * diffuse * lightColor;

The specular term finally simulates specular surfaces, that reflect more light into a singular direction (the perfect reflection direction). So it depends on the direction you are looking onto the face in. Additionally the reflectivity depends on another parameter that describes the roughness of the surface (or actually its shininess which is also the name GL uses, with higher values making sharper highlights and thus being more "shiny").

viewDir = normalize(cameraPos-facePos);
halfVec = normalize(lightDir+viewDir);
color += pow(dot(normal, halfVec), shininess) * specular * lightColor;

Of course the ambient, diffuse and specular term have to be computed for every light.

For more complex lights other than simple point lights without distance attenuation, you have to consider other things, but this simple model should get you started.

다른 팁

The colors are just added together:

ambient + diffuse + emissive + specular

Ambient is the basecolor. Diffuse is the material's color multiplied with the lighting intensity. Emissive is just added to create the illusion of some global illumination. The last one is the specularcolor which is muliplied by the result of the specular lighting calculation.

So it becomes:

ambientcolor + diffusecolor * diffuselighting + emissivecolor + specularcolor * specularlighting

In my experience this is not always the lightingmodel you want. Specifying different hues for these colors results in unnatural lighting-behavior, but that is how the models of the fixed function pipeline of OpenGl and DirectX work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top