1
0
Fork 0

Merge branch 'master' of git://gitorious.org/fg/fgdata

This commit is contained in:
BARANGER Emmanuel 2011-02-18 14:10:33 +01:00
commit 955f3b716d
8 changed files with 57 additions and 66 deletions

View file

@ -2,11 +2,11 @@
// Licence: GPL v2 // Licence: GPL v2
// Author: Frederic Bouvier // Author: Frederic Bouvier
varying vec4 ecPosition; varying float fogCoord;
varying vec3 VNormal; varying vec3 VNormal;
varying vec3 VTangent; varying vec3 VTangent;
varying vec3 VBinormal; varying vec3 VBinormal;
varying vec4 constantColor;
uniform sampler2D tex_color; uniform sampler2D tex_color;
uniform sampler2D tex_normal; uniform sampler2D tex_normal;
@ -29,7 +29,7 @@ void main (void)
vec4 Diffuse = gl_LightSource[0].diffuse * nDotVP; vec4 Diffuse = gl_LightSource[0].diffuse * nDotVP;
vec4 Specular = gl_LightSource[0].specular * pf; vec4 Specular = gl_LightSource[0].specular * pf;
vec4 color = constantColor + Diffuse * gl_FrontMaterial.diffuse; vec4 color = gl_Color + Diffuse * gl_FrontMaterial.diffuse;
color *= texture2D(tex_color, gl_TexCoord[0].xy); color *= texture2D(tex_color, gl_TexCoord[0].xy);
color += Specular * gl_FrontMaterial.specular * ns.a; color += Specular * gl_FrontMaterial.specular * ns.a;
@ -37,7 +37,6 @@ void main (void)
float fogFactor; float fogFactor;
float fogCoord = ecPosition.z;
const float LOG2 = 1.442695; const float LOG2 = 1.442695;
fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord * LOG2); fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord * LOG2);
fogFactor = clamp(fogFactor, 0.0, 1.0); fogFactor = clamp(fogFactor, 0.0, 1.0);

View file

@ -2,23 +2,24 @@
// Licence: GPL v2 // Licence: GPL v2
// Author: Frederic Bouvier // Author: Frederic Bouvier
varying vec4 ecPosition; varying float fogCoord;
varying vec3 VNormal; varying vec3 VNormal;
varying vec3 VTangent; varying vec3 VTangent;
varying vec3 VBinormal; varying vec3 VBinormal;
varying vec4 constantColor;
attribute vec3 tangent; attribute vec3 tangent;
attribute vec3 binormal; attribute vec3 binormal;
void main (void) void main (void)
{ {
ecPosition = gl_ModelViewMatrix * gl_Vertex; vec4 pos = gl_ModelViewMatrix * gl_Vertex;
fogCoord = pos.z / pos.w;
VNormal = normalize(gl_NormalMatrix * gl_Normal); VNormal = normalize(gl_NormalMatrix * gl_Normal);
VTangent = normalize(gl_NormalMatrix * tangent); VTangent = normalize(gl_NormalMatrix * tangent);
VBinormal = normalize(gl_NormalMatrix * binormal); VBinormal = normalize(gl_NormalMatrix * binormal);
constantColor = gl_FrontLightModelProduct.sceneColor + gl_LightSource[0].ambient * gl_FrontMaterial.ambient;
gl_FrontColor = constantColor; gl_FrontColor = gl_FrontLightModelProduct.sceneColor + gl_LightSource[0].ambient * gl_FrontMaterial.ambient;
gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform(); gl_Position = ftransform();
} }

View file

@ -14,7 +14,7 @@ float luminance(vec3 color)
void main() void main()
{ {
vec3 n, halfV; vec3 n;
float NdotL, NdotHV, fogFactor; float NdotL, NdotHV, fogFactor;
vec4 color = gl_Color; vec4 color = gl_Color;
vec3 lightDir = gl_LightSource[0].position.xyz; vec3 lightDir = gl_LightSource[0].position.xyz;
@ -22,16 +22,16 @@ void main()
vec4 texel; vec4 texel;
vec4 fragColor; vec4 fragColor;
vec4 specular = vec4(0.0); vec4 specular = vec4(0.0);
n = normalize(normal);
// If gl_Color.a == 0, this is a back-facing polygon and the // If gl_Color.a == 0, this is a back-facing polygon and the
// normal should be reversed. // normal should be reversed.
n = (2.0 * gl_Color.a - 1.0) * normal;
n = normalize(n);
n = (2.0 * gl_Color.a - 1.0) * n; NdotL = dot(n, lightDir);
NdotL = max(dot(n, lightDir), 0.0);
if (NdotL > 0.0) { if (NdotL > 0.0) {
color += diffuse_term * NdotL; color += diffuse_term * NdotL;
halfV = halfVector; NdotHV = max(dot(n, halfVector), 0.0);
NdotHV = max(dot(n, halfV), 0.0);
if (gl_FrontMaterial.shininess > 0.0) if (gl_FrontMaterial.shininess > 0.0)
specular.rgb = (gl_FrontMaterial.specular.rgb specular.rgb = (gl_FrontMaterial.specular.rgb
* gl_LightSource[0].specular.rgb * gl_LightSource[0].specular.rgb

View file

@ -22,11 +22,11 @@ void main()
vec4 texel; vec4 texel;
vec4 fragColor; vec4 fragColor;
vec4 specular = vec4(0.0); vec4 specular = vec4(0.0);
n = normalize(normal);
// If gl_Color.a == 0, this is a back-facing polygon and the // If gl_Color.a == 0, this is a back-facing polygon and the
// normal should be reversed. // normal should be reversed.
n = (2.0 * gl_Color.a - 1.0) * n; n = (2.0 * gl_Color.a - 1.0) * normal;
NdotL = max(dot(n, lightDir), 0.0); n = normalize(n);
NdotL = dot(n, lightDir);
if (NdotL > 0.0) { if (NdotL > 0.0) {
color += diffuse_term * NdotL; color += diffuse_term * NdotL;
halfV = normalize(halfVector); halfV = normalize(halfVector);

View file

@ -4,19 +4,17 @@
#version 120 #version 120
varying vec4 rawpos; varying vec3 rawpos;
varying vec4 ecPosition;
varying vec3 VNormal; varying vec3 VNormal;
varying vec3 VTangent; varying vec3 VTangent;
varying vec3 VBinormal; varying vec3 VBinormal;
varying vec3 Normal; varying vec3 Normal;
varying vec4 constantColor;
varying vec3 vViewVec; varying vec3 vViewVec;
varying vec3 reflVec; varying vec3 reflVec;
varying vec4 Diffuse; varying vec4 Diffuse;
varying vec3 lightDir, halfVector; varying float alpha;
varying float alpha, fogCoord; varying float fogCoord;
uniform samplerCube Environment; uniform samplerCube Environment;
uniform sampler2D Rainbow; uniform sampler2D Rainbow;
@ -37,7 +35,12 @@ void main (void)
{ {
vec3 halfV; vec3 halfV;
float NdotL, NdotHV; float NdotL, NdotHV;
vec4 color = constantColor;
vec3 lightDir = gl_LightSource[0].position.xyz;
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
vec4 color = gl_Color;
vec4 specular = vec4(0.0); vec4 specular = vec4(0.0);
vec4 ns = texture2D(NormalTex, gl_TexCoord[0].st); vec4 ns = texture2D(NormalTex, gl_TexCoord[0].st);
vec3 n = ns.rgb * 2.0 - 1.0; vec3 n = ns.rgb * 2.0 - 1.0;
@ -61,7 +64,6 @@ void main (void)
vec4 texelcolor = color * texel + specular; vec4 texelcolor = color * texel + specular;
// calculate the fog factor // calculate the fog factor
float fogCoord = ecPosition.z;
const float LOG2 = 1.442695; const float LOG2 = 1.442695;
float fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord * LOG2); float fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord * LOG2);
fogFactor = clamp(fogFactor, 0.0, 1.0); fogFactor = clamp(fogFactor, 0.0, 1.0);

View file

@ -2,19 +2,17 @@
// Licence: GPL v2 // Licence: GPL v2
// Author: Vivian Meazza. // Author: Vivian Meazza.
varying vec4 rawpos; varying vec3 rawpos;
varying vec4 ecPosition; varying float fogCoord;
varying vec3 VNormal; varying vec3 VNormal;
varying vec3 VTangent; varying vec3 VTangent;
varying vec3 VBinormal; varying vec3 VBinormal;
varying vec3 Normal; varying vec3 Normal;
varying vec4 constantColor;
varying vec3 vViewVec; varying vec3 vViewVec;
varying vec3 reflVec; varying vec3 reflVec;
varying vec4 Diffuse; varying vec4 Diffuse;
varying vec3 normal, lightDir, halfVector; varying float alpha;
varying float alpha, fogCoord;
uniform mat4 osg_ViewMatrixInverse; uniform mat4 osg_ViewMatrixInverse;
@ -23,23 +21,23 @@ attribute vec3 binormal;
void main(void) void main(void)
{ {
rawpos = gl_Vertex; rawpos = gl_Vertex.xyz / gl_Vertex.w;
ecPosition = gl_ModelViewMatrix * gl_Vertex; vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
vec3 ecPosition3 = vec3(gl_ModelViewMatrix * gl_Vertex) / ecPosition.w; ecPosition.xyz = ecPosition.xyz / ecPosition.w;
fogCoord = ecPosition.z;
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); vec3 n = normalize(gl_Normal);
vec3 t = cross(gl_Normal, vec3(1.0,0.0,0.0));
vec3 b = cross(n,t);
VNormal = normalize(gl_NormalMatrix * gl_Normal); VNormal = normalize(gl_NormalMatrix * gl_Normal);
VTangent = normalize(gl_NormalMatrix * tangent); VTangent = normalize(gl_NormalMatrix * tangent);
VBinormal = normalize(gl_NormalMatrix * binormal); VBinormal = normalize(gl_NormalMatrix * binormal);
Normal = normalize(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 * gl_LightSource[0].diffuse;
//Diffuse= gl_Color.rgb * max(0.0, dot(normalize(VNormal), gl_LightSource[0].position.xyz)); //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 // Super hack: if diffuse material alpha is less than 1, assume a
// transparency animation is at work // transparency animation is at work
if (gl_FrontMaterial.diffuse.a < 1.0) if (gl_FrontMaterial.diffuse.a < 1.0)
@ -47,8 +45,6 @@ void main(void)
else else
alpha = gl_Color.a; alpha = gl_Color.a;
fogCoord = abs(ecPosition3.z);
// Vertex in eye coordinates // Vertex in eye coordinates
vec3 vertVec = ecPosition.xyz; vec3 vertVec = ecPosition.xyz;
@ -60,9 +56,7 @@ void main(void)
vec4 reflect_eye = vec4(reflect(vertVec, VNormal), 0.0); vec4 reflect_eye = vec4(reflect(vertVec, VNormal), 0.0);
reflVec = normalize(gl_ModelViewMatrixInverse * reflect_eye).xyz; reflVec = normalize(gl_ModelViewMatrixInverse * reflect_eye).xyz;
gl_FrontColor = gl_Color; gl_FrontColor = gl_FrontMaterial.emission + gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient);
constantColor = gl_FrontMaterial.emission
+ gl_Color * (gl_LightModel.ambient + gl_LightSource[0].ambient);
gl_Position = ftransform(); gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

View file

@ -4,17 +4,15 @@
#version 120 #version 120
varying vec4 rawpos; varying vec3 rawpos;
varying vec4 ecPosition;
varying vec3 VNormal; varying vec3 VNormal;
varying vec3 Normal;
varying vec4 constantColor; varying vec4 constantColor;
varying vec3 vViewVec; varying vec3 vViewVec;
varying vec3 reflVec; varying vec3 reflVec;
varying vec4 Diffuse; varying vec4 Diffuse;
varying vec3 lightDir, halfVector; varying float alpha;
varying float alpha, fogCoord; varying float fogCoord;
uniform samplerCube Environment; uniform samplerCube Environment;
uniform sampler2D Rainbow; uniform sampler2D Rainbow;
@ -36,8 +34,11 @@ void main (void)
float NdotL, NdotHV; float NdotL, NdotHV;
vec4 color = constantColor; vec4 color = constantColor;
vec4 specular = vec4(0.0); vec4 specular = vec4(0.0);
n = VNormal; n = normalize(VNormal);
NdotL = max(0.0, dot(n, lightDir)); vec3 lightDir = gl_LightSource[0].position.xyz;
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
NdotL = dot(n, lightDir);
// calculate the specular light // calculate the specular light
if (NdotL > 0.0) { if (NdotL > 0.0) {
@ -56,7 +57,6 @@ void main (void)
vec4 texelcolor = color * texel + specular; vec4 texelcolor = color * texel + specular;
// calculate the fog factor // calculate the fog factor
float fogCoord = ecPosition.z;
const float LOG2 = 1.442695; const float LOG2 = 1.442695;
float fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord * LOG2); float fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord * LOG2);
fogFactor = clamp(fogFactor, 0.0, 1.0); fogFactor = clamp(fogFactor, 0.0, 1.0);

View file

@ -2,17 +2,15 @@
// Licence: GPL v2 // Licence: GPL v2
// Author: Vivian Meazza. // Author: Vivian Meazza.
varying vec4 rawpos; varying vec3 rawpos;
varying vec4 ecPosition;
varying vec3 VNormal; varying vec3 VNormal;
varying vec3 Normal;
varying vec4 constantColor; varying vec4 constantColor;
varying vec3 vViewVec; varying vec3 vViewVec;
varying vec3 reflVec; varying vec3 reflVec;
varying vec4 Diffuse; varying vec4 Diffuse;
varying vec3 normal, lightDir, halfVector; varying float alpha;
varying float alpha, fogCoord; varying float fogCoord;
uniform mat4 osg_ViewMatrixInverse; uniform mat4 osg_ViewMatrixInverse;
@ -20,19 +18,16 @@ uniform mat4 osg_ViewMatrixInverse;
void main(void) void main(void)
{ {
rawpos = gl_Vertex; rawpos = gl_Vertex.xyz / gl_Vertex.w;
ecPosition = gl_ModelViewMatrix * gl_Vertex; vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
vec3 ecPosition3 = vec3(gl_ModelViewMatrix * gl_Vertex) / ecPosition.w; ecPosition.xyz = ecPosition.xyz / ecPosition.w;
vec3 t = normalize(cross(gl_Normal, vec3(1.0,0.0,0.0))); vec3 t = normalize(cross(gl_Normal, vec3(1.0,0.0,0.0)));
vec3 b = normalize(cross(gl_Normal,t)); vec3 b = normalize(cross(gl_Normal,t));
vec3 n = normalize(gl_Normal); vec3 n = normalize(gl_Normal);
VNormal = normalize(gl_NormalMatrix * 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 * gl_LightSource[0].diffuse;
//Diffuse= gl_Color.rgb * max(0.0, dot(normalize(VNormal), gl_LightSource[0].position.xyz)); //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 // Super hack: if diffuse material alpha is less than 1, assume a
@ -42,7 +37,7 @@ void main(void)
else else
alpha = gl_Color.a; alpha = gl_Color.a;
fogCoord = abs(ecPosition3.z); fogCoord = abs(ecPosition.z);
// Vertex in eye coordinates // Vertex in eye coordinates
vec3 vertVec = ecPosition.xyz; vec3 vertVec = ecPosition.xyz;