#include "Defs.fxh" sampler2D TexSrc; sampler2D TexDst; float4 TexSize; struct VSIn { float4 vPos : POSITION; float2 vTex0 : TEXCOORD0; }; struct VSOut { float4 vHPos : POSITION; float2 vTex0 : TEXCOORD0; }; VSOut VShader(in VSIn IN) { VSOut OUT = (VSOut)0; IN.vPos.z=0; OUT.vHPos = IN.vPos; OUT.vTex0 = IN.vTex0; return OUT; } float4 PShader(in VSOut IN) : COLOR0 { return tex2D(TexSrc, IN.vTex0); } float4 temporal_weights; float4 PShaderLogLuminance(in VSOut IN) : COLOR0 { // wartości w teksturze są w jakiejśtam gammie, ale InputColor odczytuje je liniowo // mnożenie przez starą wartość luminancji siedzi w InputColor float l = Luminance(InputColor(tex2D(TexSrc, IN.vTex0)).rgb); // do debugowania blackscreenów // float l_limit = GetAverageLuminance_prevFrame() * 20; // if(l > l_limit) // l = l_limit; float log2_value = log2(max(l,1./255)); #ifdef _XBOX // pack into 16-bit normalized fixed point // arbitrary range: 2^-8 to 2^16 log2_value = (log2_value+8.)/ 24.; #endif // return frac(IN.vTex0.x*2)>.5; return log2_value; } float sample_luminance_bilinear(float2 uv) { #ifdef _PS3 uv = uv - TexSize.yy; float d = 0.001; return (tex2D(TexSrc, uv + float2( d,-d)) + tex2D(TexSrc, uv + float2( d, d)) + tex2D(TexSrc, uv + float2(-d, d)) + tex2D(TexSrc, uv + float2(-d,-d))).r / 4; #else return tex2D(TexSrc, uv).r; #endif } float4 PShaderExpLuminance(in VSOut IN) : COLOR0 { #ifdef _PS3 // nie chce mi się tego poprawiać, tak działa w miarę float log2_value = sample_luminance_bilinear(2./128.); #else float log2_value = sample_luminance_bilinear(IN.vTex0); #endif #ifdef _XBOX // inverse of the above log2_value = log2_value * 24. - 8.; #endif float l = exp2(log2_value); l=clamp(l, temporal_weights.z, temporal_weights.w); float prev_v = tex2D(TexHDRConfig, float2(0,0)).r; prev_v = clamp(prev_v, 1/255., 100000); l = dot(float2(l, prev_v), temporal_weights.yx); return float4(l, 1./l, 0, 0); } float4 PShaderDownsampleLuminance(in VSOut IN) : COLOR0 { return sample_luminance_bilinear(IN.vTex0); } float4 PShaderLDRToHDR(in VSOut IN) : COLOR0 { float4 ldr_color = tex2D(TexSrc, IN.vTex0); #ifndef _FINAL_LINEAR ldr_color = real_decode_sRGB(ldr_color); #endif return OutputColor(ldr_color); } float4 PShaderParticleToHDR(in VSOut IN) : COLOR0 { float4 color = tex2D(TexSrc, IN.vTex0); #ifdef _HDR_FRAMEBUFFER_RGBM color.rgb += InputColor(tex2D(TexDst, IN.vTex0)).rgb * color.a; color.a = 1; #endif return OutputColor(color); } float4 PShaderHDRToLDR(in VSOut IN) : COLOR0 { float4 r =InputColor(tex2D(TexSrc, IN.vTex0)); // wyjście powinno być linear-space bo rt_final_output ma wbudowaną konwersję sRGB (albo jest liniowe na '360) #ifndef _FINAL_LINEAR r = real_encode_sRGB(r); #endif return r; } sampler2D TexDigits; float4 PShaderDebugNumber(in VSOut IN) : COLOR0 { float n_decimal = 3; float n_digits = 6; float digit_u = frac(IN.vTex0.x * n_digits); float digit_idx = floor(IN.vTex0.x * n_digits); float digit_number = (n_digits-1-digit_idx) - n_decimal; float l = tex2D(TexSrc, float2(0,0)).r * pow(10, n_digits); float scale = pow(10, digit_number+n_digits); // return floor(IN.vTex0.x*n_digits)/n_digits; // digit_number=1 // scale = 10 // l/scale = 51.234 // floor(l/scale) = 51 // floor(l/scale)/10 = 5.1 // frac(floor(l/scale)/10) = .1 float digit_frac = frac(floor(l/scale)/10); if(l >= pow(10, 2*n_digits-n_decimal)) digit_frac=.9; float digit_v = 2.0; digit_u = digit_u * .05+.02 + digit_frac; if(digit_u >= 0.8) { digit_u -= 0.8; digit_v += 1.0; } float4 clr = tex2D(TexDigits, float2(digit_u / 0.8, (digit_v + IN.vTex0.y-.05) / 12.)); float digit_f = n_digits - IN.vTex0.x * n_digits - n_decimal + 0.5; if(digit_f > 0 && digit_f < 1) clr += tex2D(TexDigits, float2((6. + digit_f) / 8., (1. + IN.vTex0.y)/12.)); if(l >= pow(10, 2*n_digits-n_decimal)) clr.rb*=.5; if(digit_number < 0) clr.gb=0; return clr; } //DEVTEST_T(VShader, PShader)