Merge pull request #2911 from ey6es/master

Use local viewer model for specular.
This commit is contained in:
Brad Hefta-Gaub 2014-05-23 11:35:40 -07:00
commit 861a48f6f9
8 changed files with 42 additions and 14 deletions

View file

@ -14,6 +14,9 @@
// the diffuse texture
uniform sampler2D diffuseMap;
// the interpolated position
varying vec4 position;
// the interpolated normal
varying vec4 normal;
@ -26,7 +29,7 @@ void main(void) {
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight));
// compute the specular component (sans exponent)
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)),
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position - normalize(vec4(position.xyz, 0.0))),
normalizedNormal));
// modulate texture by base color and add specular contribution

View file

@ -11,6 +11,9 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// the interpolated position
varying vec4 position;
// the interpolated normal
varying vec4 normal;
@ -19,6 +22,9 @@ void main(void) {
// transform and store the normal for interpolation
normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0));
// likewise with the position
position = gl_ModelViewMatrix * gl_Vertex;
// pass along the vertex color
gl_FrontColor = gl_Color;

View file

@ -17,6 +17,9 @@ uniform sampler2D diffuseMap;
// the normal map texture
uniform sampler2D normalMap;
// the interpolated position
varying vec4 interpolatedPosition;
// the interpolated normal
varying vec4 interpolatedNormal;
@ -38,8 +41,8 @@ void main(void) {
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight));
// compute the specular component (sans exponent)
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)),
viewNormal));
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position -
normalize(vec4(vec3(interpolatedPosition), 0.0))), viewNormal));
// modulate texture by base color and add specular contribution
gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) +

View file

@ -14,6 +14,9 @@
// the tangent vector
attribute vec3 tangent;
// the interpolated position
varying vec4 interpolatedPosition;
// the interpolated normal
varying vec4 interpolatedNormal;
@ -22,7 +25,8 @@ varying vec4 interpolatedTangent;
void main(void) {
// transform and store the normal and tangent for interpolation
// transform and store the position, normal and tangent for interpolation
interpolatedPosition = gl_ModelViewMatrix * gl_Vertex;
interpolatedNormal = gl_ModelViewMatrix * vec4(gl_Normal, 0.0);
interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0);

View file

@ -20,6 +20,9 @@ uniform sampler2D normalMap;
// the specular map texture
uniform sampler2D specularMap;
// the interpolated position
varying vec4 interpolatedPosition;
// the interpolated normal
varying vec4 interpolatedNormal;
@ -41,8 +44,8 @@ void main(void) {
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight));
// compute the specular component (sans exponent)
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)),
viewNormal));
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position -
normalize(vec4(interpolatedPosition.xyz, 0.0))), viewNormal));
// modulate texture by base color and add specular contribution
gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + vec4(pow(specular, gl_FrontMaterial.shininess) *

View file

@ -17,6 +17,9 @@ uniform sampler2D diffuseMap;
// the specular texture
uniform sampler2D specularMap;
// the interpolated position in view space
varying vec4 position;
// the interpolated normal
varying vec4 normal;
@ -29,7 +32,7 @@ void main(void) {
gl_FrontLightProduct[0].diffuse * (diffuse * facingLight));
// compute the specular component (sans exponent)
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position + vec4(0.0, 0.0, 1.0, 0.0)),
float specular = facingLight * max(0.0, dot(normalize(gl_LightSource[0].position - normalize(vec4(position.xyz, 0.0))),
normalizedNormal));
// modulate texture by base color and add specular contribution

View file

@ -19,11 +19,14 @@ uniform mat4 clusterMatrices[MAX_CLUSTERS];
attribute vec4 clusterIndices;
attribute vec4 clusterWeights;
// the interpolated position
varying vec4 position;
// the interpolated normal
varying vec4 normal;
void main(void) {
vec4 position = vec4(0.0, 0.0, 0.0, 0.0);
position = vec4(0.0, 0.0, 0.0, 0.0);
normal = vec4(0.0, 0.0, 0.0, 0.0);
for (int i = 0; i < INDICES_PER_VERTEX; i++) {
mat4 clusterMatrix = clusterMatrices[int(clusterIndices[i])];
@ -31,7 +34,7 @@ void main(void) {
position += clusterMatrix * gl_Vertex * clusterWeight;
normal += clusterMatrix * vec4(gl_Normal, 0.0) * clusterWeight;
}
position = gl_ModelViewProjectionMatrix * position;
position = gl_ModelViewMatrix * position;
normal = normalize(gl_ModelViewMatrix * normal);
// pass along the vertex color
@ -40,5 +43,5 @@ void main(void) {
// and the texture coordinates
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = position;
gl_Position = gl_ProjectionMatrix * position;
}

View file

@ -22,6 +22,9 @@ attribute vec3 tangent;
attribute vec4 clusterIndices;
attribute vec4 clusterWeights;
// the interpolated position
varying vec4 interpolatedPosition;
// the interpolated normal
varying vec4 interpolatedNormal;
@ -29,17 +32,17 @@ varying vec4 interpolatedNormal;
varying vec4 interpolatedTangent;
void main(void) {
vec4 position = vec4(0.0, 0.0, 0.0, 0.0);
interpolatedPosition = vec4(0.0, 0.0, 0.0, 0.0);
interpolatedNormal = vec4(0.0, 0.0, 0.0, 0.0);
interpolatedTangent = vec4(0.0, 0.0, 0.0, 0.0);
for (int i = 0; i < INDICES_PER_VERTEX; i++) {
mat4 clusterMatrix = clusterMatrices[int(clusterIndices[i])];
float clusterWeight = clusterWeights[i];
position += clusterMatrix * gl_Vertex * clusterWeight;
interpolatedPosition += clusterMatrix * gl_Vertex * clusterWeight;
interpolatedNormal += clusterMatrix * vec4(gl_Normal, 0.0) * clusterWeight;
interpolatedTangent += clusterMatrix * vec4(tangent, 0.0) * clusterWeight;
}
position = gl_ModelViewProjectionMatrix * position;
interpolatedPosition = gl_ModelViewMatrix * interpolatedPosition;
interpolatedNormal = gl_ModelViewMatrix * interpolatedNormal;
interpolatedTangent = gl_ModelViewMatrix * interpolatedTangent;
@ -49,5 +52,5 @@ void main(void) {
// and the texture coordinates
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = position;
gl_Position = gl_ProjectionMatrix * interpolatedPosition;
}