Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.53 KB | None | 0 0
  1. //Author: Timeslip
  2. //Title: DX9 HLSL HDR 6
  3. //SModel: ps2.0
  4. //Desc:
  5. //A combination of HDR 4 and 5
  6. //Warning: Slow!
  7.  
  8. texture lastshader;
  9. texture thisframe;
  10. texture lastpass;
  11.  
  12. sampler s0 = sampler_state { texture = <lastshader>; };
  13. sampler s1 = sampler_state { texture = <lastpass>; magfilter=linear; };
  14.  
  15. static const float Luminance = 0.08f;
  16. static const float fMiddleGray = 0.18f;
  17. static const float fWhiteCutoff = 0.8f;
  18.  
  19. static const int g_cKernelSize = 13;
  20. static const float BloomScale = 1.6f;
  21.  
  22. static const float HDRScale = -0.9;
  23. static const float HDRAdjust = 0;
  24.  
  25. static const int Scale=2;
  26.  
  27. float2 rcpres;
  28. float4 HDR;
  29.  
  30. float2 PixelCoordsDownFilter[16] =
  31. {
  32.     { 1.5,  -1.5 },
  33.     { 1.5,  -0.5 },
  34.     { 1.5,   0.5 },
  35.     { 1.5,   1.5 },
  36.  
  37.     { 0.5,  -1.5 },
  38.     { 0.5,  -0.5 },
  39.     { 0.5,   0.5 },
  40.     { 0.5,   1.5 },
  41.  
  42.     {-0.5,  -1.5 },
  43.     {-0.5,  -0.5 },
  44.     {-0.5,   0.5 },
  45.     {-0.5,   1.5 },
  46.  
  47.     {-1.5,  -1.5 },
  48.     {-1.5,  -0.5 },
  49.     {-1.5,   0.5 },
  50.     {-1.5,   1.5 },
  51. };
  52.  
  53. float2 PixelKernelH[g_cKernelSize] =
  54. {
  55.     { -6, 0 },
  56.     { -5, 0 },
  57.     { -4, 0 },
  58.     { -3, 0 },
  59.     { -2, 0 },
  60.     { -1, 0 },
  61.     {  0, 0 },
  62.     {  1, 0 },
  63.     {  2, 0 },
  64.     {  3, 0 },
  65.     {  4, 0 },
  66.     {  5, 0 },
  67.     {  6, 0 },
  68. };
  69.  
  70. float2 PixelKernelV[g_cKernelSize] =
  71. {
  72.     { 0, -6 },
  73.     { 0, -5 },
  74.     { 0, -4 },
  75.     { 0, -3 },
  76.     { 0, -2 },
  77.     { 0, -1 },
  78.     { 0,  0 },
  79.     { 0,  1 },
  80.     { 0,  2 },
  81.     { 0,  3 },
  82.     { 0,  4 },
  83.     { 0,  5 },
  84.     { 0,  6 },
  85. };
  86.  
  87. static const float BlurWeights[g_cKernelSize] =
  88. {
  89.     0.002216,
  90.     0.008764,
  91.     0.026995,
  92.     0.064759,
  93.     0.120985,
  94.     0.176033,
  95.     0.199471,
  96.     0.176033,
  97.     0.120985,
  98.     0.064759,
  99.     0.026995,
  100.     0.008764,
  101.     0.002216,
  102. };
  103.  
  104. float4 HDRUpCombine( float2 Tex : TEXCOORD0, float2 Tex2 : TEXCOORD1 ) : COLOR0
  105. {
  106.     float neg = smoothstep(0.2,1,HDR.r)/4;
  107.     float pos = 0.75 + smoothstep(0,0.8,HDR.r)/4;
  108.     float3 result = saturate((tex2D(s0, Tex)-neg)/(pos-neg));
  109.     float3 bloom = tex2D(s1, Tex/Scale);
  110.     result = sqrt((result*result)+(bloom*bloom));
  111.     return float4(result, 1 );
  112. }
  113.  
  114. float4 UpFilter( float2 Tex : TEXCOORD0 ) : COLOR0
  115. {
  116.     return tex2D( s1, Tex/Scale );
  117. }
  118.  
  119. float4 Bloom( float2 Tex : TEXCOORD0 ) : COLOR0
  120. {
  121.     float4 Color = 0;
  122.  
  123.     for (int i = 0; i < g_cKernelSize; i++)
  124.     {    
  125.         Color += tex2D( s1, Tex + (PixelKernelV[i]*rcpres) ) * BlurWeights[i];
  126.         Color += tex2D( s1, Tex + (PixelKernelH[i]*rcpres) ) * BlurWeights[i];
  127.     }
  128.  
  129.     return Color * BloomScale/2;
  130. }
  131.  
  132. float4 DownFilter( in float2 Tex : TEXCOORD0 ) : COLOR0
  133. {
  134.     float4 Color = 0;
  135.  
  136.     for (int i = 0; i < 16; i++)
  137.     {
  138.         Color += tex2D( s1, (Tex*Scale) + (PixelCoordsDownFilter[i]*rcpres) );
  139.     }
  140.  
  141.     return Color / 16;
  142. }
  143.  
  144. float4 HDRBrightPassFilter( in float2 Tex : TEXCOORD0 ) : COLOR0
  145. {
  146.     float4 color = tex2D( s0, Tex );
  147.     float4 adjust = (color-HDR.r)-HDRAdjust;
  148.     color = saturate((adjust*adjust*adjust*adjust*adjust)*8);
  149.     color.a = 1;
  150.     return color;
  151. }
  152.  
  153. technique T0
  154. {
  155.     pass p0 { PixelShader = compile ps_2_0 HDRBrightPassFilter(); }
  156.     pass p1 { PixelShader = compile ps_2_0 DownFilter();          }
  157.     pass p2 { PixelShader = compile ps_2_0 DownFilter();          }
  158.     pass p4 { PixelShader = compile ps_2_0 Bloom();               }
  159.     pass p6 { PixelShader = compile ps_2_0 Bloom();               }
  160.     pass p7 { PixelShader = compile ps_2_0 UpFilter();            }
  161.     pass p8 { PixelShader = compile ps_2_0 HDRUpCombine();        }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement