// CSM Shadowmapping + Bloom + Colorgrade
// HDR version
#include "../common/constants.cg"
#include "../common/hdr.cg"
#include "../common/utils.cg"
#include "bloom.cg"
#include "common_fs.cg"
struct VertOut
{
float4 pos : POSITION;
float4 col : COLOR0;
float2 tc0 : TEXCOORD0;
};
struct FragOut
{
float4 col : COLOR;
};
float BlurTexture(sampler2D tex, float2 vin, float blur, sampler2D depthMap)
// With Z sampling
{
return tex2D(tex,vin).a;
}
FragOut main(
VertOut vin,
uniform sampler2D sceneMap : TEXUNIT0,
uniform sampler2D velocityMap : TEXUNIT1,
/// Z in TEXUNIT5
uniform sampler2D bloomMap1 : TEXUNIT2,
uniform sampler2D bloomMap2 : TEXUNIT3,
uniform sampler2D bloomMap3 : TEXUNIT4,
#ifdef CSM_MRT
uniform sampler2D depthMap : TEXUNIT5,
uniform sampler2D shadowMap : TEXUNIT6,
uniform sampler3D gradeMap : TEXUNIT7,
#else
uniform sampler3D gradeMap : TEXUNIT6, // 3D texture for color grading
#endif
uniform float alpha, // Amount of blur
uniform float exposure
)
{
FragOut fout;
float2 tc0 = vin.tc0;
if (tc0.x>0.5)
{
tc0.x = tc0.x + 0.018;
}
float4 ambientColor,
sdColor; // Specular+diffuse
float4 color;
#ifdef CSM_MRT
// Original color
ambientColor=tex2D(sceneMap,tc0);
sdColor=tex2D(shadowMap,tc0);
float shadowAmount=BlurTexture(shadowMap, tc0,smBlurAmount,depthMap);
color=ambientColor+shadowAmount*sdColor;
#else
// Single render-target (RT)
color=tex2D(sceneMap,tc0);
#endif
float4 bloomColor=BloomCombineMaps3(bloomMap1,bloomMap2,bloomMap3,tc0);
color=BloomMix(color,bloomColor);
// Show the 3 bloom stages and the end-result in 1 view
/*if(vin.tc0.y>0.5)
{
if(vin.tc0.x>0.666)color=tex2D(bloomMap3,vin.tc0);
else if(vin.tc0.x>0.333)color=tex2D(bloomMap2,vin.tc0);
else color=tex2D(bloomMap1,vin.tc0);
}*/
// HDR -> LDR tonemap
color.rgb=ToneMapHDR(color,exposure);
// Color grading
color.rgb=ColorGrade(color.rgb,gradeMap);
fout.col.rgb=color;
// Motion blur blend
fout.col.a=alpha;
return fout;
}