Created different default shaders for models.
These use the vertex color as the diffuse part of the lighting equation, instead of both ambient and diffuse. Author: Tim Moore <timoore@redhat.com>
This commit is contained in:
parent
a2481d8e60
commit
8e2077e330
3 changed files with 60 additions and 2 deletions
|
@ -50,8 +50,8 @@
|
|||
-->
|
||||
</texture-unit>
|
||||
<program>
|
||||
<vertex-shader>Shaders/default.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/default.frag</fragment-shader>
|
||||
<vertex-shader>Shaders/model-default.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/model-default.frag</fragment-shader>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>texture</name>
|
||||
|
|
31
Shaders/model-default.frag
Normal file
31
Shaders/model-default.frag
Normal file
|
@ -0,0 +1,31 @@
|
|||
// -*-C++-*-
|
||||
|
||||
varying vec4 diffuse, constantColor;
|
||||
varying vec3 normal, lightDir, halfVector;
|
||||
varying float fogCoord;
|
||||
|
||||
uniform sampler2D texture;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 n, halfV;
|
||||
float NdotL, NdotHV, fogFactor;
|
||||
vec4 color = constantColor;
|
||||
vec4 texel;
|
||||
vec4 fragColor;
|
||||
|
||||
n = normalize(normal);
|
||||
NdotL = max(dot(n, lightDir), 0.0);
|
||||
if (NdotL > 0.0) {
|
||||
color += diffuse * NdotL;
|
||||
halfV = normalize(halfVector);
|
||||
NdotHV = max(dot(n, halfV), 0.0);
|
||||
if (gl_FrontMaterial.shininess > 0.0)
|
||||
color += gl_FrontMaterial.specular * gl_LightSource[0].specular
|
||||
* pow(NdotHV, gl_FrontMaterial.shininess);
|
||||
}
|
||||
texel = texture2D(texture, gl_TexCoord[0].st);
|
||||
fragColor = color * texel;
|
||||
fogFactor = exp(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord);
|
||||
gl_FragColor = mix(gl_Fog.color, fragColor, fogFactor);
|
||||
}
|
27
Shaders/model-default.vert
Normal file
27
Shaders/model-default.vert
Normal file
|
@ -0,0 +1,27 @@
|
|||
// -*-C++-*-
|
||||
|
||||
// Shader that uses OpenGL state values to do per-pixel lighting
|
||||
//
|
||||
// The only light used is gl_LightSource[0], which is assumed to be
|
||||
// directional.
|
||||
//
|
||||
// Diffuse and ambient colors come from the gl_Color. This is
|
||||
// equivalent to osg::Material::AMBIENT_AND_DIFFUSE.
|
||||
|
||||
varying vec4 diffuse, constantColor;
|
||||
varying vec3 normal, lightDir, halfVector;
|
||||
varying float fogCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
|
||||
gl_Position = ftransform();
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
normal = gl_NormalMatrix * gl_Normal;
|
||||
lightDir = normalize(vec3(gl_LightSource[0].position));
|
||||
halfVector = normalize(gl_LightSource[0].halfVector.xyz);
|
||||
diffuse = gl_Color * gl_LightSource[0].diffuse;
|
||||
constantColor = gl_FrontLightModelProduct.sceneColor
|
||||
+ gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
|
||||
fogCoord = abs(ecPosition.z);
|
||||
}
|
Loading…
Reference in a new issue