Guest User

Untitled

a guest
May 24th, 2018
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. //ENBSeries: boris-vorontsov@yandex.ru, boris-vorontsov.narod.ru
  3. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  4. /*
  5. THIS IS HLSL (HIGH LEVEL SHADER LANGUAGE) FILE FOR EXECUTING ADDITIONAL
  6. HARDWARE EFFECTS. MAKE THE COPY BEFORE CHANGING IT!
  7. */
  8.  
  9. //keyboard controled variables
  10. float tempF1;
  11. float tempF2;
  12. float tempF3;
  13. float tempF4;
  14. float tempF5;
  15. float tempF6;
  16. float tempF7;
  17. float tempF8;
  18. float tempF9;
  19. float tempF0;
  20.  
  21.  
  22. //global variables, already set before executing this code
  23. float ScreenSize;1920 //width of the display resolution (1024 f.e.)
  24. float ScreenScaleY;1.777 //screen proportions (1.333 for 1024/768)
  25.  
  26. float bloomPower;5//(0..10) actually used for bloom, but may be useful here (user defined constant factor)
  27. float useBloom;0//(0 or 1) if bloom enabled by user
  28.  
  29.  
  30.  
  31.  
  32. //textures
  33. texture2D texColor;
  34. texture2D texBloom;
  35.  
  36. sampler2D SamplerColor = sampler_state
  37. {
  38. Texture = <texColor>;
  39. MinFilter = LINEAR;
  40. MagFilter = LINEAR;
  41. MipFilter = LINEAR;//NONE;
  42. AddressU = Clamp;
  43. AddressV = Clamp;
  44. SRGBTexture=FALSE;
  45. };
  46.  
  47. sampler2D SamplerBloom = sampler_state
  48. {
  49. Texture = <texBloom>;
  50. MinFilter = LINEAR;
  51. MagFilter = LINEAR;
  52. MipFilter = NONE;//NONE;
  53. AddressU = Clamp;
  54. AddressV = Clamp;
  55. SRGBTexture=FALSE;
  56. };
  57.  
  58. struct VS_OUTPUT_POST {
  59. float4 vpos : POSITION;
  60. float2 txcoord : TEXCOORD0;
  61. };
  62.  
  63. struct VS_INPUT_POST {
  64. float3 pos : POSITION;
  65. float2 txcoord : TEXCOORD0;
  66. };
  67.  
  68.  
  69.  
  70.  
  71. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  72. //
  73. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  74. VS_OUTPUT_POST VS_PostProcess(VS_INPUT_POST IN)
  75. {
  76. VS_OUTPUT_POST OUT;
  77.  
  78. float4 pos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);
  79.  
  80. OUT.vpos=pos;
  81. OUT.txcoord.xy=IN.txcoord.xy;
  82.  
  83. return OUT;
  84. }
  85.  
  86.  
  87.  
  88.  
  89. float4 PS_PostProcess(VS_OUTPUT_POST In) : COLOR
  90. {
  91.  
  92. float2 offset[4]=
  93. {
  94. float2(-1.0,-1.0),
  95. float2(-1.0, 1.0),
  96. float2( 1.0, 1.0),
  97. float2( 1.0,-1.0)
  98.  
  99. };
  100. float4 res=0.0;
  101. float4 coord=0.0;
  102. coord.xy=In.txcoord.xy;
  103. float4 origcolor=tex2D(SamplerColor, coord.xy);
  104. float origgray=max(origcolor.r, max(origcolor.g, origcolor.b));
  105. res+=origcolor;
  106. float range=0.7*tempF9/ScreenSize;
  107. for (int i=0; i<4; i++)
  108. {
  109.  
  110. coord.xy=In.txcoord+offset[i]*range;
  111. float4 color;
  112. float gray;
  113. color=tex2D(SamplerColor, coord.xy);
  114. float4 colordiff=abs(origcolor-color);
  115. gray=dot(colordiff.rgb,0.333);
  116. float lerpfact=saturate(4.0*abs(gray)*color.a);//saturate
  117. res+=lerp(origcolor, color, lerpfact);
  118. }
  119. res=res*0.2;
  120.  
  121.  
  122.  
  123.  
  124. //res=origcolor;
  125.  
  126. coord.xy=In.txcoord.xy;
  127. coord.w=2.5*tempF1;
  128. float4 envcol1=tex2Dbias(SamplerColor, coord);
  129. coord.w=3.5*tempF2;
  130. float4 envcol2=tex2Dbias(SamplerColor, coord);
  131. float4 envcol3=tex2D(SamplerBloom, coord.xy);
  132. float4 bloom=envcol3;
  133.  
  134.  
  135. float4 envcol=(envcol1+envcol2+envcol3)*0.777;
  136.  
  137.  
  138. //envcol=tempF5*pow(envcol,tempF4);
  139.  
  140. //envcol=envcol*tempF7/(1.0+envcol*tempF8);
  141.  
  142. //envcol=dot(envcol.xyz,0.333);
  143. //envcol=max(envcol.x, max(envcol.y, envcol.z));
  144. float4 tempcol;//=max(envcol.x, max(envcol.y, envcol.z));
  145. //envcol=lerp(tempcol, envcol, tempF3);
  146.  
  147. //tempcol.xyz=saturate(res.xyz-envcol.xyz);
  148. //float diff=dot(tempcol.xyz, 0.333);
  149.  
  150. //float srcgray=dot(res.xyz,0.333);
  151. //envcol.xyz=res.xyz-(tempF7*envcol.xyz)*(1.0-saturate(srcgray));
  152.  
  153. envcol=tempF5*pow(envcol,tempF4);
  154. res=lerp(res, res*envcol, tempF6);
  155. //res=res*tempF7/(1.0+res*tempF8);
  156. //res+=tempF7*pow(bloom,4.0*tempF8);
  157.  
  158.  
  159. //desaturate
  160. float middlegray=(res.r+res.g+res.b)*0.333;
  161. float3 diffcolor=res.rgb-middlegray;
  162. res.rgb-=diffcolor*0.4*tempF0;
  163.  
  164. if (tempF3>1.1) res=origcolor;
  165.  
  166. res.a=1.0;
  167. return res;
  168. }
  169.  
  170.  
  171.  
  172. /*
  173.  
  174. float4 PS_PostProcess(VS_OUTPUT_POST In) : COLOR
  175. {
  176.  
  177. float2 offset[4]=
  178. {
  179. float2(-1.0,-1.0),
  180. float2(-1.0, 1.0),
  181. float2( 1.0, 1.0),
  182. float2( 1.0,-1.0)
  183. };
  184. float4 res=0.0;
  185. float4 coord=0.0;
  186. coord.xy=In.txcoord.xy;
  187. float4 origcolor=tex2Dlod(SamplerColor, coord);
  188. float origgray=max(origcolor.r, max(origcolor.g, origcolor.b));
  189. res+=origcolor;
  190. float range=tempF5*0.001;// /ScreenSize.x
  191. for (int i=0; i<4; i++)
  192. {
  193. coord.xy=In.txcoord+offset[i]*range;
  194. float4 color;
  195. float gray;
  196. color=tex2Dlod(SamplerColor, coord);
  197. float4 colordiff=abs(origcolor-color);
  198. gray=max(colordiff.r, max(colordiff.g, colordiff.b));
  199. float lerpfact=saturate(tempF6*abs(gray));//saturate
  200. res+=lerp(origcolor, color, lerpfact);
  201. }
  202. res=res/5.0;
  203.  
  204. res.a=1.0;
  205. return res;
  206. }
  207. */
  208.  
  209.  
  210.  
  211. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  212. //
  213. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  214. technique PostProcess
  215. {
  216. pass P0
  217. {
  218. VertexShader = compile vs_3_0 VS_PostProcess();
  219. PixelShader = compile ps_3_0 PS_PostProcess();
  220.  
  221. FogEnable=FALSE;
  222. ALPHATESTENABLE=FALSE;
  223. SEPARATEALPHABLENDENABLE=FALSE;
  224. AlphaBlendEnable=FALSE;
  225. FogEnable=FALSE;
  226. SRGBWRITEENABLE=FALSE;
  227. }
  228. }
Add Comment
Please, Sign In to add comment