3 // =================================================================================================
\r
5 // =================================================================================================
\r
8 <Sampler id="colormap" />
\r
10 <Sampler id="detailmap" />
\r
12 <Sampler id="ambientMap">
\r
13 <StageConfig addressMode="CLAMP" filtering="BILINEAR" maxAnisotropy="1" />
\r
16 <Uniform id="specParams" a="0.1" b="16.0">
\r
19 b - Specular exponent
\r
23 <Context id="ATTRIBPASS">
\r
24 <Shaders vertex="VS_GENERAL" fragment="FS_ATTRIBPASS" />
\r
27 <Context id="SHADOWMAP">
\r
28 <Shaders vertex="VS_SHADOWMAP" fragment="FS_SHADOWMAP" />
\r
31 <Context id="LIGHTING">
\r
32 <Shaders vertex="VS_GENERAL" fragment="FS_LIGHTING" />
\r
33 <RenderConfig writeDepth="false" blendMode="ADD" />
\r
36 <Context id="AMBIENT">
\r
37 <Shaders vertex="VS_GENERAL" fragment="FS_AMBIENT" />
\r
42 // =================================================================================================
\r
44 #include "shaders/utilityLib/vertCommon.glsl"
\r
46 uniform vec3 viewer;
\r
47 attribute vec2 texCoords0;
\r
49 varying vec4 pos, vsPos;
\r
50 varying vec2 texCoords;
\r
52 varying vec3 tsbNormal;
\r
54 uniform vec4 terrainSize;
\r
59 vec3 _normal = calcWorldVec( gl_Normal );
\r
61 // Calculate tangent and bitangent
\r
62 tsbNormal = _normal;
\r
64 // Calculate world space position
\r
65 pos = calcWorldPos( gl_Vertex );
\r
67 vsPos = calcViewPos( pos );
\r
69 // Calculate tangent space eye vector
\r
71 // Calculate texture coordinates and clip space position
\r
72 texCoords = vec2(gl_Vertex.x, gl_Vertex.z);
\r
73 gl_Position = gl_ModelViewProjectionMatrix * pos;
\r
78 // =================================================================================================
\r
80 #include "shaders/utilityLib/fragDeferredWrite.glsl" />
\r
82 uniform vec4 specParams;
\r
83 uniform sampler2D colormap;
\r
84 uniform sampler2D detailmap;
\r
87 varying vec2 texCoords;
\r
89 varying vec3 tsbNormal;
\r
91 uniform vec4 terrainSize;
\r
95 vec3 newCoords = vec3( texCoords, 0 );
\r
97 // Flip texture vertically to match the GL coordinate system
\r
98 //newCoords.t *= -1.0;
\r
100 vec3 detail = texture2D( detailmap, newCoords.st ).rgb;
\r
101 newCoords.s /= terrainSize.x;
\r
102 newCoords.t /= terrainSize.y;
\r
103 vec3 albedo = texture2D( colormap, newCoords.st ).rgb;
\r
104 albedo += (detail - 0.5) * 0.3;
\r
106 vec3 normal = tsbNormal;
\r
108 vec3 newPos = pos.xyz;
\r
112 setNormal( normalize( normal ) );
\r
113 setAlbedo( albedo );
\r
114 setSpecMask( specParams.x );
\r
119 // =================================================================================================
\r
121 #include "shaders/utilityLib/vertCommon.glsl"
\r
123 uniform vec4 lightPos;
\r
124 varying float dist;
\r
128 vec4 pos = calcWorldPos( gl_Vertex );
\r
129 dist = length( lightPos.xyz - pos.xyz ) / lightPos.w;
\r
131 gl_Position = gl_ModelViewProjectionMatrix * pos;
\r
136 // =================================================================================================
\r
138 uniform float shadowBias;
\r
139 varying float dist;
\r
143 gl_FragDepth = dist + shadowBias;
\r
145 // Clearly better bias but requires SM 3.0
\r
146 // gl_FragDepth = dist + abs( dFdx( dist ) ) + abs( dFdy( dist ) ) + shadowBias;
\r
151 // =================================================================================================
\r
153 #include "shaders/utilityLib/fragLighting.glsl" />
\r
155 uniform vec4 specParams;
\r
156 uniform sampler2D colormap;
\r
157 uniform sampler2D detailmap;
\r
159 varying vec4 pos, vsPos;
\r
160 varying vec2 texCoords;
\r
162 varying vec3 tsbNormal;
\r
164 uniform vec4 terrainSize;
\r
168 vec3 newCoords = vec3( texCoords, 0 );
\r
170 // Flip texture vertically to match the GL coordinate system
\r
171 //newCoords.t *= -1.0;
\r
173 vec3 detail = texture2D( detailmap, newCoords.st ).rgb;
\r
174 newCoords.s /= terrainSize.x;
\r
175 newCoords.t /= terrainSize.y;
\r
176 vec3 albedo = texture2D( colormap, newCoords.st ).rgb;
\r
177 albedo += (detail - 0.5) * 0.3;
\r
179 vec3 normal = tsbNormal;
\r
181 vec3 newPos = pos.xyz;
\r
184 calcPhongSpotLight( newPos, normalize( normal ), albedo, specParams.x, specParams.y, -vsPos.z, 0.3 );
\r
189 // =================================================================================================
\r
191 #include "shaders/utilityLib/fragLighting.glsl" />
\r
193 uniform sampler2D colormap;
\r
194 uniform sampler2D detailmap;
\r
195 uniform samplerCube ambientMap;
\r
199 varying vec2 texCoords;
\r
201 varying vec3 tsbNormal;
\r
203 uniform vec4 terrainSize;
\r
207 vec3 newCoords = vec3( texCoords, 0 );
\r
209 // Flip texture vertically to match the GL coordinate system
\r
210 //newCoords.t *= -1.0;
\r
212 vec3 detail = texture2D( detailmap, newCoords.st ).rgb;
\r
213 newCoords.s /= terrainSize.x;
\r
214 newCoords.t /= terrainSize.y;
\r
215 vec3 albedo = texture2D( colormap, newCoords.st ).rgb;
\r
216 albedo += (detail - 0.5) * 0.3;
\r
218 vec3 normal = tsbNormal;
\r
220 gl_FragColor.rgb = albedo * textureCube( ambientMap, normal ).rgb;
\r