= 0.8; // version #
texture Image <
string ResourceName = "nave.hdr";
string ResourceType = "2D";
string format="A16B16G16R16f";
>;
sampler2D ImageSampler = sampler_state
{
Texture = ;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = None;
};
float exposure
<
string UIWidget = "slider";
string UIName = "Exposure";
float UIMin = -10.0; float UIMax = 10.0; float UIStep = 0.1;
> = 0.0;
float defog
<
string UIWidget = "slider";
string UIName = "De-fog";
float UIMin = 0.0; float UIMax = 0.1; float UIStep = 0.001;
> = 0.0;
float gamma
<
string UIWidget = "slider";
string UIName = "Gamma";
float UIMin = 0.0; float UIMax = 1.0; float UIStep = 0.01;
> = 1.0 / 2.2;
float3 fogColor = { 1.0, 1.0, 1.0 };
//////////////////////////////
struct a2v {
float4 position : POSITION;
float4 texcoord : TEXCOORD0;
};
struct v2f {
float4 position : POSITION;
float4 texcoord : TEXCOORD0;
// calculated values:
float exposure : TEXCOORD1;
};
/////////////////////////////////
v2f TonemapVS(a2v IN)
{
v2f OUT;
OUT.position = IN.position;
OUT.texcoord = IN.texcoord;
OUT.exposure = pow(2.0, exposure);
return OUT;
}
half4 TonemapPS(v2f IN,
uniform half3 defog,
uniform half gamma) : COLOR
{
half3 c = tex2D(ImageSampler, IN.texcoord);
c = max(0, c - defog);
c *= IN.exposure;
// gamma correction - could use texture lookups for this
c = pow(c, gamma);
return half4(c.rgb, 1.0);
}
//////////////////////////////////////////
technique Main <
string ScriptClass = "scene";
string ScriptOrder = "standard";
string ScriptOutput = "color";
string Script = "Pass=p0;";
> {
pass p0 <
string Script = "RenderColorTarget0=;"
"Draw=Buffer;";
> {
cullmode = none;
ZEnable = false;
AlphaBlendEnable = false;
VertexShader = compile vs_1_1 TonemapVS();
PixelShader = compile ps_2_0 TonemapPS(defog*fogColor, gamma);
}
}
]]>