Texture2D ColorTexture : register(t0, space2); SamplerState Sampler0 : register(s0, space2); Texture2D EmissiveTexture : register(t1, space2); SamplerState Sampler1 : register(s1, space2); Texture2D SsaoTexture : register(t2, space2); SamplerState Sampler2 : register(s2, space2); float3 reinhard2(float3 x) { const float L_white = 10.0; const float3 a = 1.0 + x / (L_white * L_white); const float3 x2 = x * a; const float3 x3 = 1.0 + x; return x2 / x3; } float3 blurSSAO(float2 uv) { const float offset[5] = {0.0, 1.0, 2.0, 3.0, 4.0}; const float weight[5] = {0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162}; float3 c = float3(0,0,0); // SsaoTexture.Sample(Sampler2, uv).xyz * weight[0] / 25; for(int j = 0; j < 5; j++ ) { for(int i = 0; i < 5; i++ ) { { float2 uv2 = uv + float2(j - 2.5, i) / 1024; float3 s = SsaoTexture.Sample(Sampler2, uv2).xyz / 50; c += s; } { float2 uv2 = uv - float2(j - 2.5, i) / 1024; float3 s = SsaoTexture.Sample(Sampler2, uv2).xyz / 50; c += s; } } } return c; } float3 blur(float2 uv) { const float offset[5] = {0.0, 1.0, 2.0, 3.0, 4.0}; const float weight[5] = {0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162}; float3 c = EmissiveTexture.Sample(Sampler1, uv).xyz * weight[0]; for(int j = 0; j < 5; j++ ) { for(int i = 0; i < 5; i++ ) { { float2 uv2 = uv + float2(j - 2.5, i) / 512; float3 s = EmissiveTexture.Sample(Sampler1, uv2).xyz / 25; c += s; } { float2 uv2 = uv - float2(j - 2.5, i) / 512; float3 s = EmissiveTexture.Sample(Sampler1, uv2).xyz / 25; c += s; } #if 0 { float2 uv2 = uv + float2(0.0, offset[i]) / 1024; float3 s = EmissiveTexture.Sample(Sampler1, uv2).xyz * weight[i]; c += s; } { float2 uv2 = uv - float2(0.0, offset[i]) / 1024; float3 s = EmissiveTexture.Sample(Sampler1, uv2).xyz * weight[i]; c += s; } #endif } } return c; } float4 main(float2 UV : TEXCOORD0) : SV_Target0 { float2 uv = UV; uv.y *= -1; uv.y += 1.0; float3 c; #if 0 { c = ColorTexture.Sample(Sampler0, uv).xyz; c = reinhard2(c); c = pow(c, 1.0/2.2); } #endif c = ColorTexture.Sample(Sampler0, uv).xyz; c = reinhard2(c); float3 b = float3(0.0, 0.0, 0.0); if(length(c) < 1.0) { b = blur(uv) * 0.3; } c = pow(c, 1.0/2.2); float3 e = EmissiveTexture.Sample(Sampler1, uv).xyz; c = c + blur(uv) * 0.05; float exposure = 1.0; c *= exposure; //= exposure(c, 1.0, 0.3); // c = blur(uv) * 0.01; // c = float3(1.0, 1.0, 1.0) - (step(0.91, length(float3(1.0, 1.0, 1.0) - (e - c)))); // c = c * c ; // c = e; // c = float3(uv.x, uv.y, 0.0); // c = SsaoTexture.Sample(Sampler2, uv).x; #if 0 float4 ssao = SsaoTexture.Sample(Sampler2, uv); //c.x += (1.0 - ssao.x) * 0.7; c = ssao; #else float3 ssao = blurSSAO(uv); c = c * ssao; #endif //float4 x = SsaoTexture.Sample(Sampler2, uv); //c = x; c.x *= 1.0 + 0.000001 * EmissiveTexture.Sample(Sampler1, uv).x; c.x *= 1.0 + 0.000001 * ColorTexture.Sample(Sampler0, uv).x; c.x *= 1.0 + 0.000001 * SsaoTexture.Sample(Sampler2, uv).x; return float4(c, 1.0); }