1
0
Fork 0
fgdata/Shaders/reflect.vert

64 lines
1.9 KiB
GLSL
Raw Normal View History

// -*- mode: C; -*-
// Licence: GPL v2
2010-04-02 14:02:48 +00:00
// Author: Vivian Meazza.
2010-04-02 14:02:48 +00:00
varying vec4 rawpos;
varying vec4 ecPosition;
varying vec3 VNormal;
varying vec3 Normal;
varying vec4 constantColor;
varying vec3 vViewVec;
varying vec3 reflVec;
2010-03-29 09:50:54 +00:00
varying vec4 Diffuse;
varying vec3 normal, lightDir, halfVector;
varying float alpha, fogCoord;
uniform mat4 osg_ViewMatrixInverse;
//attribute vec3 tangent, binormal, normal;
void main(void)
{
2010-04-02 14:02:48 +00:00
rawpos = gl_Vertex;
ecPosition = gl_ModelViewMatrix * gl_Vertex;
vec3 ecPosition3 = vec3(gl_ModelViewMatrix * gl_Vertex) / ecPosition.w;
vec3 t = normalize(cross(gl_Normal, vec3(1.0,0.0,0.0)));
vec3 b = normalize(cross(gl_Normal,t));
vec3 n = normalize(gl_Normal);
VNormal = normalize(gl_NormalMatrix * gl_Normal);
Normal = normalize(gl_Normal);
lightDir = normalize(vec3(gl_LightSource[0].position));
halfVector = normalize(gl_LightSource[0].halfVector.xyz);
Diffuse = gl_Color * gl_LightSource[0].diffuse;
//Diffuse= gl_Color.rgb * max(0.0, dot(normalize(VNormal), gl_LightSource[0].position.xyz));
// Super hack: if diffuse material alpha is less than 1, assume a
// transparency animation is at work
if (gl_FrontMaterial.diffuse.a < 1.0)
alpha = gl_FrontMaterial.diffuse.a;
else
alpha = gl_Color.a;
fogCoord = abs(ecPosition3.z);
// Vertex in eye coordinates
vec3 vertVec = ecPosition.xyz;
vViewVec.x = dot(t, vertVec);
vViewVec.y = dot(b, vertVec);
vViewVec.z = dot(n, vertVec);
// calculate the reflection vector
vec4 reflect_eye = vec4(reflect(vertVec, VNormal), 0.0);
2010-03-29 09:50:54 +00:00
reflVec = normalize(gl_ModelViewMatrixInverse * reflect_eye).xyz;
gl_FrontColor = gl_Color;
constantColor = gl_FrontMaterial.emission
+ gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient);
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
}