Implemented specular reflective lighting for OpenGL 3.x, everything looks shiny (will add APIs to make it less shiny ;-)
Remove roof from kitchens/1.sdf, otherwise shadows and shinyness won't work (light is outside the room, bouncing against roof-top) Make kuka_iiwa/model.urdf more smooth, use .obj for per-vertex normals (using Blender, import STL, export OBJ, enable triangles, normals and Z-UP, Y forward)
This commit is contained in:
@@ -13,9 +13,14 @@ in Vert
|
||||
|
||||
uniform sampler2D Diffuse;
|
||||
uniform sampler2DShadow shadowMap;
|
||||
uniform mat4 ViewMatrixInverse;
|
||||
|
||||
in vec3 lightDir,normal,ambient;
|
||||
in vec3 lightPos,cameraPosition, normal,ambient;
|
||||
in vec4 ShadowCoord;
|
||||
in vec4 vertexPos;
|
||||
in float materialShininess;
|
||||
in vec3 lightSpecularIntensity;
|
||||
in vec3 materialSpecularColor;
|
||||
|
||||
out vec4 color;
|
||||
|
||||
@@ -28,8 +33,11 @@ void main(void)
|
||||
float intensity,at,af;
|
||||
if (fragment.color.w==0)
|
||||
discard;
|
||||
|
||||
intensity = 0.5+0.5*clamp( dot( normalize(normal),lightDir ), -1,1 );
|
||||
vec3 lightDir = normalize(lightPos);
|
||||
|
||||
vec3 normalDir = normalize(normal);
|
||||
|
||||
intensity = 0.5+0.5*clamp( dot( normalDir,lightDir ), -1,1 );
|
||||
|
||||
af = 1.0;
|
||||
|
||||
@@ -38,7 +46,24 @@ void main(void)
|
||||
|
||||
//float bias = 0.005f;
|
||||
|
||||
vec3 specularReflection;
|
||||
|
||||
if (dot(normalDir, lightDir) < 0.0)
|
||||
{
|
||||
specularReflection = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
else // light source on the right side
|
||||
{
|
||||
vec3 surfaceToLight = normalize(lightPos - vertexPos.xyz);
|
||||
vec3 surfaceToCamera = normalize(cameraPosition - vertexPos.xyz);
|
||||
|
||||
|
||||
float specularCoefficient = 0.0;
|
||||
specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normalDir))), materialShininess);
|
||||
specularReflection = specularCoefficient * materialSpecularColor * lightSpecularIntensity;
|
||||
|
||||
}
|
||||
|
||||
|
||||
float visibility = texture(shadowMap, vec3(ShadowCoord.xy,(ShadowCoord.z)/ShadowCoord.w));
|
||||
if (intensity<0.5)
|
||||
@@ -46,6 +71,6 @@ void main(void)
|
||||
|
||||
intensity = 0.7*intensity + 0.3*intensity*visibility;
|
||||
|
||||
cf = intensity*(vec3(1.0,1.0,1.0)-ambient)+ambient;
|
||||
cf = intensity*(vec3(1.0,1.0,1.0)-ambient)+ambient+specularReflection*visibility;
|
||||
color = vec4(ct * cf, fragment.color.w);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user