diff --git a/Effects/terrain-default.eff b/Effects/terrain-default.eff index 23ff780d3..b49cc7992 100644 --- a/Effects/terrain-default.eff +++ b/Effects/terrain-default.eff @@ -38,6 +38,51 @@ RenderBin + + + + 2.0 + + + + + true + + material/ambient + material/diffuse + material/specular + ambient-and-diffuse + + transparent + transparent + smooth + back + + render-bin/bin-number + render-bin/bin-name + + + 0 + texture0/texture2d + texture0/texture2d/image + texture0/texture2d/filter + texture0/texture2d/wrap-s + texture0/texture2d/wrap-t + + texture0/texture2d/internal-format + + + + + Shaders/default.vert + Shaders/default.frag + + + texture + sampler-2d + 0 + + true diff --git a/Shaders/default.frag b/Shaders/default.frag new file mode 100644 index 000000000..a50f8f497 --- /dev/null +++ b/Shaders/default.frag @@ -0,0 +1,30 @@ +// -*-C++-*- + +varying vec4 diffuse, ambient; +varying vec3 normal, lightDir, halfVector; +varying float fogCoord; + +uniform sampler2D texture; + +void main() +{ + vec3 n, halfV; + float NdotL, NdotHV, fogFactor; + vec4 color = ambient; + 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); + 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); +} diff --git a/Shaders/default.vert b/Shaders/default.vert new file mode 100644 index 000000000..3e73c3bb7 --- /dev/null +++ b/Shaders/default.vert @@ -0,0 +1,26 @@ +// -*-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, ambient; +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; + ambient = gl_Color * gl_LightSource[0].ambient; + fogCoord = abs(ecPosition.z); +}