Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2016
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.08 KB | None | 0 0
  1. //ENB Z 2.0.000 shaderfile
  2. //ENB Z author: Marty McFly
  3.  
  4. /*
  5.  
  6. _______ _________ _______ _______ _
  7. ( ____ \\__ __/( ___ )( ____ )( )
  8. | ( \/ ) ( | ( ) || ( )|| |
  9. | (_____ | | | | | || (____)|| |
  10. (_____ ) | | | | | || _____)| |
  11. ) | | | | | | || ( (_)
  12. /\____) | | | | (___) || | _
  13. \_______) )_( (_______)|_) (_)
  14.  
  15.  
  16. Before you change anything here, please notice that you
  17. are allowed to modify my ENB config ONLY for yourself!
  18.  
  19. Please read my agreement for more informations!
  20. - http://pastebin.com/Y6AEFvdS
  21.  
  22. Only change something here if you know exactly what
  23. you are doing! I'm not responsible for any crashes,
  24. malfunctions, thermonuclear disasters etc.
  25.  
  26. Copyright:
  27. Boris Vorontsov, Rockstar Games, Timothy Lottes, iCE La GlacE,
  28. Cody Darr (Sonic Ether), Marty McFly
  29.  
  30. */
  31.  
  32. #include "ENBZ_config.ini" //include our config file
  33.  
  34. /////////////////////////TEXTURES///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  35. /////////////////////////TEXTURES///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  36.  
  37. float4 ScreenSize;
  38. float4 Timer;
  39. texture texColor;
  40. texture texDepth;
  41. texture texNoise;
  42.  
  43. sampler gcolor = sampler_state
  44. {
  45. Texture = (texColor);
  46. MinFilter = LINEAR;
  47. MagFilter = LINEAR;
  48. MipFilter = LINEAR;
  49. };
  50.  
  51. sampler gdepth = sampler_state
  52. {
  53. Texture = <texDepth>;
  54. };
  55.  
  56. sampler gnoise = sampler_state
  57. {
  58. Texture = (texNoise);
  59. MinFilter = LINEAR;
  60. MagFilter = LINEAR;
  61. AddressU = Wrap;
  62. AddressV = Wrap;
  63. };
  64.  
  65. /////////////////////////VERTEX SHADER//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  66. /////////////////////////VERTEX SHADER//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  67.  
  68. void VS_ENBZ(inout float2 txcoord : TEXCOORD0, out float4 vpos : POSITION, in float3 pos : POSITION)
  69. {
  70. vpos=float4(pos.x,pos.y,pos.z,1.0);
  71. }
  72.  
  73. /////////////////////////FUNCTIONS//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  74. /////////////////////////FUNCTIONS//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  75.  
  76. void Bloom(in float2 tex, in bool isvert, inout float alpha)
  77. {
  78. float2 pixelsize = float2(ScreenSize.y,ScreenSize.y*ScreenSize.z);
  79. float weight[5] = {0.17467,0.12098,0.06559,0.02783,0.01222};
  80. alpha = tex2D(gcolor, tex).w * 0.19741;
  81. float2 axis = (isvert == 1) ? float2(0.0,1.0) : float2(1.0,0.0);
  82. for(int i=1; i<6; i++)
  83. {
  84. alpha += tex2Dlod(gcolor, float4(tex + (float)i * pixelsize.xy * axis.xy,0,0)).w * weight[i-1];
  85. alpha += tex2Dlod(gcolor, float4(tex - (float)i * pixelsize.xy * axis.xy,0,0)).w * weight[i-1];
  86. }
  87. }
  88.  
  89. void FXAA2(inout float3 color, in float2 pos)
  90. {
  91. #define FXAA_SUBPIX_SHIFT (1.0/8.0)
  92. #define FXAA_REDUCE_MIN (1.0/32.0)
  93. #define FXAA_REDUCE_MUL (1.0/16.0)
  94. #define FXAA_SPAN_MAX 8.0
  95.  
  96. half2 rcpFrame = half2(1/ScreenSize.x, 1/(ScreenSize.x/ScreenSize.z));
  97. half4 posPos;
  98. posPos.xy = pos;
  99. posPos.zw = posPos.xy - (rcpFrame.xy * (0.5 + FXAA_SUBPIX_SHIFT));
  100. half3 rgbNW = tex2D(gcolor, posPos.zw ).xyz;
  101. half3 rgbNE = tex2D(gcolor, posPos.zw + half2(rcpFrame.x, 0.0) ).xyz;
  102. half3 rgbSW = tex2D(gcolor, posPos.zw + half2(0.0, rcpFrame.y) ).xyz;
  103. half3 rgbSE = tex2D(gcolor, posPos.zw +rcpFrame.xy ).xyz;
  104. half3 rgbM = tex2D(gcolor, posPos.xy).xyz;
  105. half3 luma = half3(0.299, 0.587, 0.114);
  106. half lumaNW = dot(rgbNW, luma);
  107. half lumaNE = dot(rgbNE, luma);
  108. half lumaSW = dot(rgbSW, luma);
  109. half lumaSE = dot(rgbSE, luma);
  110. half lumaM = dot(rgbM, luma);
  111. half lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
  112. half lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
  113. half2 dir;
  114. half lumaNWNE = lumaNW + lumaNE;
  115. half lumaSWSE = lumaSW + lumaSE;
  116. dir.x = -((lumaNWNE) - (lumaSWSE));
  117. dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
  118. half dirReduce = max( (lumaSWSE + lumaNWNE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);
  119. half rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce);
  120. dir = min(half2( FXAA_SPAN_MAX, FXAA_SPAN_MAX), max(half2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) * rcpFrame.xy;
  121. half3 rgbA = (1.0/2.0) * (tex2D(gcolor, posPos.xy + dir * (1.0/3.0 - 0.5) ).xyz + tex2D(gcolor, posPos.xy + dir * (2.0/3.0 - 0.5) ).xyz);
  122. half3 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (tex2D(gcolor, posPos.xy + dir * (0.0/3.0 - 0.5) ).xyz + tex2D(gcolor, posPos.xy + dir * (3.0/3.0 - 0.5) ).xyz);
  123. half lumaB = dot(rgbB, luma);
  124. color.xyz = (lumaB < lumaMin || lumaB > lumaMax) ? rgbA.xyz : rgbB.xyz;
  125. }
  126.  
  127. void Sharpen(inout float3 color, in float2 tex)
  128. {
  129. float2 pixelsize = float2(ScreenSize.y,ScreenSize.y*ScreenSize.z);
  130. float offset_bias = 0.35;
  131. float sharp_strength_luma = 0.13;
  132. float sharp_clamp = 0.25;
  133. float3 ori = color.xyz;
  134. float3 blur_ori = tex2D(gcolor, tex.xy + float2(0.5 * pixelsize.x,-pixelsize.y * offset_bias)).rgb; // South South East
  135. blur_ori += tex2D(gcolor, tex.xy + float2(offset_bias * -pixelsize.x,0.5 * -pixelsize.y)).rgb; // West South West
  136. blur_ori += tex2D(gcolor, tex.xy + float2(offset_bias * pixelsize.x,0.5 * pixelsize.y)).rgb; // East North East
  137. blur_ori += tex2D(gcolor, tex.xy + float2(0.5 * -pixelsize.x,pixelsize.y * offset_bias)).rgb; // North North West
  138. blur_ori /= 4.0;
  139. float3 sharp = ori - blur_ori;
  140. float sharp_luma = dot(sharp, sharp_strength_luma);
  141. sharp_luma = clamp(sharp_luma, -sharp_clamp, sharp_clamp);
  142. color.xyz += sharp_luma;
  143. }
  144.  
  145. void Grain (inout float3 color, in float2 texcoord)
  146. {
  147. float2 seed1 = texcoord.xy*14.3+0.42;
  148. float2 seed2 = texcoord.xy*14.0+0.25;
  149. float timefact = fmod(Timer.x*35+cos(Timer.x*1.2),1);
  150. seed1.xy+=timefact*10;
  151. seed2.xy-=timefact*10;
  152. float4 Noise=(tex2D(gnoise,seed1)*2-1)*(tex2D(gnoise,seed2)*2-1);
  153. float NoiseAmp = 1.1;
  154. float colorgray = dot(color.xyz,float3(0.299,0.587,0.114));
  155. float noiseDown = smoothstep(0.2,0.0,colorgray);
  156. noiseDown += colorgray;
  157. float finalnoise = lerp(Noise,0.0,pow(noiseDown,4.0));
  158. color.xyz = pow(pow(color.xyz,1/NoiseAmp)+Noise*0.0333,NoiseAmp);
  159. color.xyz += finalnoise*0.04;
  160. }
  161.  
  162. /////////////////////////PIXEL SHADERS//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  163. /////////////////////////PIXEL SHADERS//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  164.  
  165.  
  166. float4 PS_ENBZ1(float2 _v0 : TEXCOORD0) : COLOR
  167. {
  168. float4 color = tex2D(gcolor, _v0.xy);
  169. #if(FXAA >= 1)
  170. FXAA2(color.xyz, _v0.xy);
  171. #endif
  172. color.w = 0;
  173. //these steps prevent hue shift - RGB 0.0 0.5 1.0 minus 0.5 is 0.0 0.0 0.5 which is a totally different color
  174. float3 redsample = tex2D(gcolor, _v0.xy*16.0-2.0).xyz;
  175. float3 greensample = tex2D(gcolor, _v0.xy*16.0-4.0).xyz;
  176. float3 bluesample = tex2D(gcolor, _v0.xy*16.0-6.0).xyz;
  177. float redgray = dot(redsample.xyz,0.333);
  178. float greengray = dot(greensample.xyz,0.333);
  179. float bluegray = dot(bluesample.xyz,0.333);
  180. redsample *= smoothstep(0.4,1.0,redgray);
  181. greensample *= smoothstep(0.4,1.0,greengray);
  182. bluesample *= smoothstep(0.4,1.0,bluegray);
  183. if(_v0.x > 0.125 && _v0.y > 0.125 && _v0.x < 0.1875 && _v0.y < 0.1875) color.w += redsample.x;
  184. if(_v0.x > 0.25 && _v0.y > 0.25 && _v0.x < 0.3125 && _v0.y < 0.3125) color.w += greensample.y;
  185. if(_v0.x > 0.375 && _v0.y > 0.375 && _v0.x < 0.4375 && _v0.y < 0.4375) color.w += bluesample.z;
  186. return color;
  187. }
  188.  
  189. float4 PS_ENBZ2(float2 _v0 : TEXCOORD0) : COLOR
  190. {
  191.  
  192. float3 r1 = pow(tex2Dlod(gdepth,float4(_v0.xy,0,0)).x,0.33);
  193. r1.xy = smoothstep(fDepthOfFieldMin,fDepthOfFieldMax,r1.z)*fDepthOfFieldRadius*float2(ScreenSize.y,ScreenSize.y*ScreenSize.z);
  194. #if(UI_MASK == 1 && DEPTHOFFIELD == 1)
  195. bool isHUDorMenu = 0;
  196. float2 minimapcenter = float2(fMinimapCenter_X, fMinimapCenter_Y);
  197. float minimapradius = 0.1;
  198. float2 minimapdist = _v0.xy-minimapcenter;
  199. minimapdist.x*=ScreenSize.z;
  200. if(length(minimapdist.xy)<fMinimapRadius) isHUDorMenu = 1;
  201. float checkdepth = 0;
  202. for(float x = 1; x <= 3; x+=1)
  203. {
  204. for(float y = 1; y <= 3; y+=1)
  205. {
  206. checkdepth += tex2Dlod(gdepth,float4(float2(x,y)*0.25,0,0)).x;
  207. }
  208. }
  209. if(checkdepth == 9.0) isHUDorMenu = 1;
  210. float4 HUDedges = float4(fHUDLeft,fHUDRight,fHUDTop,fHUDBottom);
  211. if(_v0.x > HUDedges.x && _v0.x < HUDedges.y && _v0.y > HUDedges.z && _v0.y < HUDedges.w) isHUDorMenu = 1;
  212. if(isHUDorMenu != 0) r1.xy = 0.0;
  213. #endif
  214. float2 poisson[19] = {
  215. float2(0.000,0.000),
  216. float2(0.000,1.000),
  217. float2(0.8860,0.500),
  218. float2(0.8860,-0.500),
  219. float2(0.0000,-1.000),
  220. float2(-0.8860,-0.500),
  221. float2(-0.8860,0.500),
  222. float2(0.000,2.000),
  223. float2(1.7720,1.000),
  224. float2(1.7720,-1.000),
  225. float2(0.0000,-2.000),
  226. float2(-1.7720,-1.000),
  227. float2(-1.7720,1.000),
  228. float2(0.8860,1.500),
  229. float2(1.772,0.000),
  230. float2(0.8860,-1.500),
  231. float2(-0.8860,-1.500),
  232. float2(-1.7720,0.000),
  233. float2(-0.8860,1.500) };
  234.  
  235. float4 color = 0;
  236. int Taps = 19;
  237. #if(DEPTHOFFIELD != 1)
  238. Taps = 1;
  239. #endif
  240. [unroll] //why? for the glory of satan, of course!
  241. for(int i = 0; i < Taps; i++)
  242. {
  243. float2 curroffset = _v0.xy + poisson[i].xy*r1.xy;
  244. float4 r2 = tex2Dlod(gcolor, float4(curroffset.xy, 0.0, 0.0));
  245. color.xyz += pow(r2.xyz,8.0);
  246.  
  247. }
  248. color.xyz /= Taps;
  249. color.xyz = pow(color.xyz, 0.125);
  250. if(_v0.x < 0.5 && _v0.y < 0.5) Bloom(_v0.xy, 0, color.w);
  251. return color;
  252. }
  253.  
  254. float4 PS_ENBZ3(float2 _v0 : TEXCOORD0) : COLOR
  255. {
  256. float4 color = tex2D(gcolor, _v0.xy);
  257. #if(FXAA >= 2)
  258. FXAA2(color.xyz, _v0.xy);
  259. #endif
  260. if(_v0.x < 0.5 && _v0.y < 0.5) Bloom(_v0.xy, 1, color.w);
  261. return color;
  262. }
  263.  
  264. float4 PS_ENBZ4(float2 _v0 : TEXCOORD0) : COLOR
  265. {
  266. float4 color = tex2D(gcolor, _v0.xy);
  267. #if(FXAA == 3)
  268. FXAA2(color.xyz, _v0.xy);
  269. #endif
  270. #if(FXAA >= 2)
  271. Sharpen(color.xyz, _v0.xy); //FXAA blurs rather strong. The sharpen values are precisely configured, do not change.
  272. #endif
  273. float3 bloom = float3(tex2D(gcolor, _v0.xy/16+0.125).w,
  274. tex2D(gcolor, _v0.xy/16+0.250).w,
  275. tex2D(gcolor, _v0.xy/16+0.375).w);
  276. float gray=dot(color.xyz, 0.333);
  277. float3 satcolor=pow(color.xyz, 1.33);
  278. float satgray=dot(satcolor.xyz, 0.333);
  279. color.xyz=satcolor.xyz*gray/(satgray+0.0001);
  280. bloom.xyz = lerp(dot(bloom.xyz,0.333),bloom.xyz,1.5);
  281. color.xyz += 0.70*bloom.xyz*(1-color.xyz);
  282. #if(IMAGEGRAIN != 0)
  283. Grain(color.xyz, _v0.xy);
  284. #endif
  285. #if(VINTAGE != 0)
  286. color.r = color.r * 1.3 + 0.01;
  287. color.g = color.g * 1.2;
  288. color.b = color.b * 0.75 + 0.10;
  289. #endif
  290. color.xyz = saturate(color.xyz - pow(length(_v0.xy-0.5)*1.41, 4) * VIGNETTING);
  291. //final colormod stuff
  292. color.xyz = (color.xyz - dot(color.xyz, 0.333)) * SATURATION + dot(color.xyz, 0.333);
  293. color.xyz = (pow(color.xyz, GAMMA) - 0.5) * CONTRAST + 0.5;
  294. color.xyz *= EXPOSURE;
  295.  
  296. return color;
  297. }
  298.  
  299. /////////////////////////TECHNIQUES/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  300. /////////////////////////TECHNIQUES/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  301.  
  302. technique PostProcess
  303. {
  304. pass P0
  305. {
  306. VertexShader = compile vs_2_0 VS_ENBZ();
  307. PixelShader = compile ps_3_0 PS_ENBZ1();
  308. }
  309. }
  310.  
  311. technique PostProcess2
  312. {
  313. pass P0
  314. {
  315. VertexShader = compile vs_2_0 VS_ENBZ();
  316. PixelShader = compile ps_3_0 PS_ENBZ2();
  317. }
  318. }
  319.  
  320. technique PostProcess3
  321. {
  322. pass P0
  323. {
  324. VertexShader = compile vs_2_0 VS_ENBZ();
  325. PixelShader = compile ps_3_0 PS_ENBZ3();
  326. }
  327. }
  328.  
  329. technique PostProcess4
  330. {
  331. pass P0
  332. {
  333. VertexShader = compile vs_2_0 VS_ENBZ();
  334. PixelShader = compile ps_3_0 PS_ENBZ4();
  335. }
  336. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement