私の頂点シェーダである:
#version 400
layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexNormal;
out vec3 LightIntensity;
struct LightInfo {
vec3 Position; // Light position in eye coords.
vec3 La; // Ambient light intensity
vec3 Ld; // Diffuse light intensity
vec3 Ls; // Specular light intensity
};
uniform LightInfo Light;
struct MaterialInfo {
vec3 Ka; // Ambient reflectivity
vec3 Kd; // Diffuse reflectivity
vec3 Ks; // Specular reflectivity
float Shininess; // Specular shininess factor
};
uniform MaterialInfo Material;
uniform mat4 ModelViewMatrix;
uniform mat3 NormalMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 MVP;
void main()
{
mat4 normalMatrixBetter = transpose(inverse(ModelViewMatrix));
vec3 normalEyeSpace = normalize(vec3(normalMatrixBetter * vec4(VertexNormal, 0.0)));
//vec3 tnorm = normalize(normalMatrixBetter * VertexNormal);
vec4 vertexPositionInEyeCoords = ModelViewMatrix * vec4(VertexPosition, 1.0);
vec3 s = normalize(vec3(Light.Position.xyz - vertexPositionInEyeCoords.xyz));
vec3 v = normalize(-vertexPositionInEyeCoords.xyz);
vec3 r = reflect(-s, normalEyeSpace);
vec3 ambient = Light.La * Material.Ka;
float sDotN = max(dot(s, normalEyeSpace), 0.0);
vec3 diffuse = Light.Ld * Material.Kd * sDotN;
vec3 spec = vec3(0.0);
if (sDotN > 0.0)
{
spec = Light.Ls * Material.Ks * pow(max(dot(r, v), 0.0), Material.Shininess);
}
// LightIntensity = ambient;
// LightIntensity = diffuse;
// LightIntensity = spec;
// LightIntensity = ambient + diffuse;
LightIntensity = /*ambient +*/ diffuse + spec;
gl_Position = MVP * vec4(VertexPosition, 1.0);
}
そして、ここでは、フラグメントである:ここ
#version 400
in vec3 LightIntensity;
layout(location = 0) out vec4 FragColor;
void main()
{
FragColor = vec4(LightIntensity, 1.0) * 0.3;
}
は、対応する光強度と反射係数である:
vec3 lightSourceAmbientIntensity(1.0f, 1.0f, 1.0f); // La, Light source ambient intensity
vec3 lightSourceDiffuseIntensity(10.0f, 10.0f, 10.0f); // Ld, Light source diffuse intensity
vec3 lightSourceSpecularIntensity(1.0f, 1.0f, 1.0f); // Ls, Light source specular intensity
vec3 ambientReflectivity(0.5f, 0.0f, 0.0f); // Ka,
vec3 diffuseReflectivity(1.0f, 0.0f, 0.0f); // Kd,
vec3 specularReflectivity(0.0f, 0.9f, 0.0f); // Ks,
GLfloat materialShineness = 1.0f;
LightIntensity = spec;
私は光るはずの緑の三角形を見て、残りの三角形は黒です。 LightIntensity = diffuse;
私は、光が当たってカメラの位置に反射するすべての三角形に非常に良い拡散赤シェーディングを見ます。しかし、私がLightIntensity = /*ambient +*/ diffuse + spec;
の三角形を書くときは黒くなるのは、唯一の特殊な陰影の場合です。そしてここに私の質問です:どのように緑に赤を追加して黒になることができますか? PhongシェーディングのSpecular lightingを追加すると、正しく追加されないのはなぜですか?
イメージを追加しています。私の形がY軸を中心に回転していると考えてください。ありがとう! – Narek