Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogreode/demos/Media/autoterraintexture.cg @ 21

Last change on this file since 21 was 21, checked in by nicolasc, 17 years ago

added ogreode and Colladaplugin

File size: 2.1 KB
Line 
1// Vertex program for automatic terrain texture generation
2void main_vp
3(
4    float4             iPosition           : POSITION,
5        float4             iNormal             : NORMAL,
6        float2             iTexcoord           : TEXCOORD0,
7
8        out float4         oPosition           : POSITION,
9        out float4         oTexcoord           : TEXCOORD0,
10        out float4         oColor0             : COLOR0,
11        out float4         oColor1             : COLOR1,
12        out float4         oFog                : TEXCOORD1,
13
14        uniform float4x4   worldViewProj,
15        uniform float4     lightDirection,
16        uniform float4     ambientLight,
17
18        uniform float4     configSettings,
19        uniform float4     fogSettings,
20        uniform float4     fogColour
21)
22{
23    // Calculate the output position and texture coordinates
24        oPosition  = mul(worldViewProj,iPosition);
25    oTexcoord = float4(iPosition.x,iPosition.z,0.0,0.0) * configSettings[0];
26
27    float fog = clamp(( oPosition.z - fogSettings[0] ) / (fogSettings[1] - fogSettings[0]),0.0,1.0) * fogSettings[2];
28
29    // Calculate the diffuse and the ambient lighting
30    float diffuse = dot(iNormal,lightDirection);
31
32    // Set the output color based on the lighting
33    float rock_factor = (iNormal.y > configSettings[1])?0.0:(clamp((configSettings[1] - iNormal.y) * configSettings[2],0.0,1.0));
34    float4 color = float4(diffuse,diffuse,diffuse,1.0) + (ambientLight * configSettings[3]);
35    oColor0 = (1.0 - fog) * (color * (1.0 - rock_factor));
36    oColor1 = (1.0 - fog) * (color * rock_factor);
37    oFog = fogColour * fog;
38}
39
40// Fragment program for automatic terrain texture generation
41void main_fp
42(
43    float4              iTexcoord       : TEXCOORD0,
44    float4              iColor0     : COLOR0,
45    float4              iColor1     : COLOR1,
46    float4              iFog        : TEXCOORD1,
47
48        out float4          oColor              : COLOR,
49
50    uniform sampler2D   textureUnit0,
51    uniform sampler2D   textureUnit1
52)
53{
54    // Sample the texture to get the output colour, times the lighting
55        oColor = iFog + (tex2D(textureUnit0,iTexcoord.xy) * iColor0) + (tex2D(textureUnit1,iTexcoord.xy) * iColor1);
56        oColor.a = 1.0;
57}
58
Note: See TracBrowser for help on using the repository browser.