var KERNEL_SIZE=2;
var KERNEL_LOOP=KERNEL_SIZE/2-0.5;
var KERNEL_CONTRIBUTIONS=KERNEL_SIZE*KERNEL_SIZE;
//#GLSLSource
pub.buildShader=function(features) {
var shadowMapSampler = "\n"+
"const float shadowTexelSize=1.0/2048.0;\n"+
//When dot-producted with the packed values in the shadow map will produce a Z value in the range 0-1
"const vec4 bitShifts=vec4(1.0/(256.0*256.0*256.0),1.0/(256.0*256.0),1.0/256.0,1.0);\n"+
"float rand(vec2 co){\n"+
" return fract(sin(dot(co.xy,vec2(12.9898,78.233)))*43758.5453);\n"+
"}\n"+
"float ShadowMapSamplerStochastic(vec4 sunShadowMapPosition, sampler2D sunShadowMap, float shadowStrength) {\n"+
" float shadowEffect;\n"+
" vec3 shadowMapTexel=sunShadowMapPosition.xyz/sunShadowMapPosition.w;\n"+
" shadowMapTexel.z-=shadowMapTexel.z*0.003;\n"+
" if (shadowMapTexel.x<0.0 || shadowMapTexel.x>1.0 || shadowMapTexel.y<0.0 || shadowMapTexel.y>1.0 || shadowMapTexel.z<0.0 || shadowMapTexel.z>0.45) shadowEffect=1.0;\n"+
" else {\n"+
" float shadowTotal=0.0, shadowMapDepth=0.0;\n"+
" vec2 lookupTexel;\n";
for (var pixelX=-KERNEL_LOOP; pixelX<=KERNEL_LOOP; pixelX+=1.0) {
for (var pixelY=-KERNEL_LOOP; pixelY<=KERNEL_LOOP; pixelY+=1.0) {
shadowMapSampler +=
" lookupTexel=shadowMapTexel.xy+shadowTexelSize*( vec2(cos(rand(sunShadowMapPosition.xy))+("+pixelX+"),sin(rand(sunShadowMapPosition.yx))+("+pixelY+")) );\n"+
" shadowMapDepth=dot(texture2D(sunShadowMap,lookupTexel),bitShifts);\n"+
" shadowTotal+=step(shadowMapDepth,shadowMapTexel.z)*shadowStrength;\n";
}
}
shadowMapSampler +=
" shadowEffect=max(1.0-(shadowTotal/"+KERNEL_CONTRIBUTIONS+".0),0.0);\n"+
" }\n"+
" return shadowEffect;\n"+
"}\n"+
};
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}