Terrain effect has a shader
This commit is contained in:
parent
e32c47d795
commit
d4d89d2793
3 changed files with 101 additions and 0 deletions
|
@ -38,6 +38,51 @@
|
|||
<bin-name>RenderBin</bin-name>
|
||||
</render-bin>
|
||||
</parameters>
|
||||
<technique>
|
||||
<predicate>
|
||||
<less-equal>
|
||||
<value type="float">2.0</value>
|
||||
<glversion/>
|
||||
</less-equal>
|
||||
</predicate>
|
||||
<pass>
|
||||
<lighting>true</lighting>
|
||||
<material>
|
||||
<ambient><use>material/ambient</use></ambient>
|
||||
<diffuse><use>material/diffuse</use></diffuse>
|
||||
<specular><use>material/specular</use></specular>
|
||||
<color-mode>ambient-and-diffuse</color-mode>
|
||||
</material>
|
||||
<blend><use>transparent</use></blend>
|
||||
<alpha-test><use>transparent</use></alpha-test>
|
||||
<shade-model>smooth</shade-model>
|
||||
<cull-face>back</cull-face>
|
||||
<render-bin>
|
||||
<bin-number><use>render-bin/bin-number</use></bin-number>
|
||||
<bin-name><use>render-bin/bin-name</use></bin-name>
|
||||
</render-bin>
|
||||
<texture-unit>
|
||||
<unit>0</unit>
|
||||
<texture2d><use>texture0/texture2d</use>
|
||||
<image><use>texture0/texture2d/image</use></image>
|
||||
<filter><use>texture0/texture2d/filter</use></filter>
|
||||
<wrap-s><use>texture0/texture2d/wrap-s</use></wrap-s>
|
||||
<wrap-t><use>texture0/texture2d/wrap-t</use></wrap-t>
|
||||
<internal-format>
|
||||
<use>texture0/texture2d/internal-format</use>
|
||||
</internal-format>
|
||||
</texture2d>
|
||||
</texture-unit>
|
||||
<program>
|
||||
<vertex-shader>Shaders/default.vert</vertex-shader>
|
||||
<fragment-shader>Shaders/default.frag</fragment-shader>
|
||||
</program>
|
||||
<uniform>
|
||||
<name>texture</name>
|
||||
<type>sampler-2d</type>
|
||||
<value type="int">0</value></uniform>
|
||||
</pass>
|
||||
</technique>
|
||||
<technique>
|
||||
<pass>
|
||||
<lighting>true</lighting>
|
||||
|
|
30
Shaders/default.frag
Normal file
30
Shaders/default.frag
Normal file
|
@ -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);
|
||||
}
|
26
Shaders/default.vert
Normal file
26
Shaders/default.vert
Normal file
|
@ -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);
|
||||
}
|
Loading…
Reference in a new issue