The problem was that I don't know things like what is ATTRIBPASS.
Anyway I've found the solution. The shader for lightmaps:
Code:
[[FX]]
<!--
// =================================================================================================
Lightmap Shader
// =================================================================================================
-->
<Sampler id="albedoMap" />
<Sampler id="lightMap" />
<Context id="LIGHTING">
<Shaders vertex="VS_GENERAL" fragment="FS_LIGHTING" />
<RenderConfig writeDepth="false" blendMode="MULT" />
</Context>
<Context id="AMBIENT">
<Shaders vertex="VS_GENERAL" fragment="FS_AMBIENT" />
</Context>
[[VS_GENERAL]]
// =================================================================================================
#include "shaders/utilityLib/vertCommon.glsl"
uniform vec3 viewer;
attribute vec2 texCoords0;
attribute vec3 normal;
varying vec4 pos, vsPos;
varying vec2 texCoords;
varying vec3 tsbNormal;
void main( void )
{
// Calculate normal
tsbNormal = calcWorldVec( normal );
// Calculate world space position
pos = calcWorldPos( gl_Vertex );
vsPos = calcViewPos( pos );
// Calculate texture coordinates and clip space position
texCoords = texCoords0;
gl_Position = gl_ModelViewProjectionMatrix * pos;
}
[[FS_LIGHTING]]
// =================================================================================================
#include "shaders/utilityLib/fragLighting.glsl" />
uniform sampler2D albedoMap;
uniform sampler2D lightMap;
varying vec4 pos, vsPos;
varying vec2 texCoords;
varying vec3 tsbNormal;
vec3 calcLightmapShadow( const vec3 pos, const vec3 normal, const float viewDist, const float ambientIntensity )
{
vec3 light = lightPos.xyz - pos;
// Distance
float lightDist = length( light ) / lightPos.w;
light = normalize( light );
// Light intensity
vec3 col = vec3(1,1,1);
// Shadow
if( dot( normal, light ) > 0.0)
{
vec4 projShadow = shadowMats[3] * vec4( pos, 1.0 );
if( viewDist < shadowSplitDists.x ) projShadow = shadowMats[0] * vec4( pos, 1.0 );
else if( viewDist < shadowSplitDists.y ) projShadow = shadowMats[1] * vec4( pos, 1.0 );
else if( viewDist < shadowSplitDists.z ) projShadow = shadowMats[2] * vec4( pos, 1.0 );
projShadow.z = lightDist;
projShadow.xy /= projShadow.w;
float shadowFac = PCF( projShadow );
col *= max( shadowFac, ambientIntensity );
}
return col;
}
void main( void )
{
vec3 newCoords = vec3( texCoords, 0 );
// Flip texture vertically to match the GL coordinate system
newCoords.t *= -1.0;
vec3 normal = tsbNormal;
vec3 newPos = pos.xyz;
gl_FragColor.rgb = calcLightmapShadow( newPos, normalize( normal ), -vsPos.z, 0.3 );
}
[[FS_AMBIENT]]
// =================================================================================================
#include "shaders/utilityLib/fragLighting.glsl" />
uniform sampler2D albedoMap;
uniform sampler2D lightMap;
varying vec4 pos;
varying vec2 texCoords;
void main( void )
{
vec3 newCoords = vec3( texCoords, 0 );
// Flip texture vertically to match the GL coordinate system
newCoords.t *= -1.0;
vec3 albedo = texture2D( albedoMap, newCoords.st ).rgb;
vec3 light = texture2D( lightMap, newCoords.st ).rgb;
gl_FragColor.rgb = albedo * light;
}