Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uniform vec3 m_region1;
- uniform vec3 m_region2;
- uniform vec3 m_region3;
- uniform vec3 m_region4;
- uniform vec4 g_LightDirection;
- uniform vec4 g_LightPosition;
- uniform sampler2D m_region1ColorMap;
- uniform sampler2D m_region2ColorMap;
- uniform sampler2D m_region3ColorMap;
- uniform sampler2D m_region4ColorMap;
- uniform sampler2D m_slopeColorMap;
- uniform float m_minSlopeAngle;
- uniform float m_maxSlopeAngle;
- uniform float m_slopeTileFactor;
- uniform float m_terrainSize;
- varying vec3 normal ;
- varying vec4 position;
- vec4 GenerateTerrainColor() {
- float height = position.y;
- vec4 p = position / m_terrainSize;
- // This angles can be changed to match user
- // The minimum and maximum angles at which slope texture appears
- float minAngle = 30;
- float maxAngle = 60;
- float angleRange = m_maxSlopeAngle - m_minSlopeAngle;
- vec3 toUp = vec3(0.0, 1.0, 0.0);
- float angle = degrees (acos ( dot(toUp, normal) )) ;
- // The amount the current angle is above the minimum angle the slope tex appears
- float deltaAngle = angle - minAngle;
- float angleImpact = clamp (deltaAngle / angleRange,0.00001 , 1 );
- vec4 slopeColor = texture2D(m_slopeColorMap, p.xz * m_slopeTileFactor);
- vec4 terrainColor = vec4(0.0, 0.0, 0.0, 1.0);
- float m_regionMin = 0.0;
- float m_regionMax = 0.0;
- float m_regionRange = 0.0;
- float m_regionWeight = 0.0;
- // Terrain m_region 1.
- m_regionMin = m_region1.x;
- m_regionMax = m_region1.y;
- m_regionRange = m_regionMax - m_regionMin;
- m_regionWeight = (m_regionRange - abs(height - m_regionMax)) / m_regionRange;
- m_regionWeight = max(0.0, m_regionWeight);
- terrainColor += m_regionWeight * texture2D(m_region1ColorMap, p.xz * m_region1.z);
- // Terrain m_region 2.
- m_regionMin = m_region2.x;
- m_regionMax = m_region2.y;
- m_regionRange = m_regionMax - m_regionMin;
- m_regionWeight = (m_regionRange - abs(height - m_regionMax)) / m_regionRange;
- m_regionWeight = max(0.0, m_regionWeight);
- terrainColor += m_regionWeight * (texture2D(m_region2ColorMap, p.xz * m_region2.z));
- // Terrain m_region 3.
- m_regionMin = m_region3.x;
- m_regionMax = m_region3.y;
- m_regionRange = m_regionMax - m_regionMin;
- m_regionWeight = (m_regionRange - abs(height - m_regionMax)) / m_regionRange;
- m_regionWeight = max(0.0, m_regionWeight);
- terrainColor += m_regionWeight * texture2D(m_region3ColorMap, p.xz * m_region3.z);
- // Terrain m_region 4.
- m_regionMin = m_region4.x;
- m_regionMax = m_region4.y;
- m_regionRange = m_regionMax - m_regionMin;
- m_regionWeight = (m_regionRange - abs(height - m_regionMax)) / m_regionRange;
- m_regionWeight = max(0.0, m_regionWeight);
- terrainColor += m_regionWeight * texture2D(m_region4ColorMap, p.xz * m_region4.z);
- return (mix(terrainColor, slopeColor, angleImpact ));
- }
- void main() {
- vec4 color = GenerateTerrainColor();
- vec3 lightDir = vec3(1.0, 3.0, 2.0);
- float lambert = dot(-g_LightPosition.xyz,normal);
- vec4 darkColor = vec4(0.0, 0.0, 0.0, 1.0);
- float rgb = 1;
- color = mix(darkColor,color , lambert);
- color = clamp(color, vec4(0,0,0,0), vec4(rgb,rgb,rgb,1));
- color = color * 0.8 ;
- gl_FragColor = color;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement