Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.38 KB | None | 0 0
  1. BASE.VSH
  2.  
  3.  
  4. // Shader that curves the Minecraft world by daxnitro.
  5.  
  6. #version 120 // This will always get moved to the top of the code in pre-processing.
  7.  
  8. const float WORLD_RADIUS = 1000.0;
  9. const float WORLD_RADIUS_SQUARED = 1000000.0;
  10.  
  11. #ifdef _ENABLE_GL_TEXTURE_2D
  12. centroid varying vec4 texCoord;
  13. #endif
  14.  
  15. varying vec4 vertColor;
  16.  
  17. void main() {
  18. vec4 position = gl_ModelViewMatrix * gl_Vertex;
  19.  
  20. if (gl_Color.a != 0.8) {
  21. // Not a cloud.
  22.  
  23. float distanceSquared = position.x * position.x + position.z * position.z;
  24.  
  25. position.y -= WORLD_RADIUS - sqrt(max(1.0 - distanceSquared / WORLD_RADIUS_SQUARED, 0.0)) * WORLD_RADIUS;
  26. }
  27.  
  28. gl_Position = gl_ProjectionMatrix * position;
  29.  
  30. #ifdef _ENABLE_GL_TEXTURE_2D
  31. texCoord = gl_MultiTexCoord0;
  32. #endif
  33.  
  34. vertColor = gl_Color;
  35.  
  36. gl_FogFragCoord = gl_Position.z;
  37. }
  38.  
  39. FINAL.FSH
  40.  
  41. // More realistic depth-of-field by Azraeil.
  42. // This is a modification of Daxnitro's depth-of-field shader.
  43.  
  44. // If you want a higher quality blur, remove the forward slashes from the following line:
  45. //#define USE_HIGH_QUALITY_BLUR
  46.  
  47. uniform sampler2D sampler0;
  48. uniform sampler2D sampler1;
  49. uniform sampler2D sampler2;
  50.  
  51. uniform float aspectRatio;
  52. uniform float near;
  53. uniform float far;
  54. uniform int worldTime;
  55.  
  56. // HYPERFOCAL = (Focal Distance ^ 2)/(Circle of Confusion * F Stop) + Focal Distance
  57. const float HYPERFOCAL = 3.132;
  58. const float PICONSTANT = 3.14159;
  59.  
  60. float getDepth(vec2 coord);
  61. float getCursorDepth(vec2 coord);
  62. vec4 getBlurredColor();
  63. vec4 getSample(vec2 coord, vec2 aspectCorrection);
  64. vec4 getSampleWithBoundsCheck(vec2 offset);
  65.  
  66. float samples = 0.0;
  67. vec2 space;
  68.  
  69. void main() {
  70. vec4 baseColor = texture2D(sampler0, gl_TexCoord[0].st);
  71.  
  72. gl_FragColor = baseColor;
  73.  
  74. float depth = getDepth(gl_TexCoord[0].st);
  75.  
  76. float cursorDepth = getCursorDepth(vec2(0.5, 0.5));
  77.  
  78. // foreground blur = 1/2 background blur. Blur should follow exponential pattern until cursor = hyperfocal -- Cursor before hyperfocal
  79. // Blur should go from 0 to 1/2 hyperfocal then clear to infinity -- Cursor @ hyperfocal.
  80. // hyperfocal to inifity is clear though dof extends from 1/2 hyper to hyper -- Cursor beyond hyperfocal
  81.  
  82. float blur_start = 30;
  83. float blur_length = 15;
  84. float blur = clamp( ( depth - blur_start ) / blur_length, 0.0, 1.0 );
  85.  
  86. // gl_FragColor = mix(baseColor, getBlurredColor(), blur);
  87.  
  88. float lum = dot( baseColor.xyz, vec3( 0.39f, 0.5f, 0.11f ) );
  89. vec3 min_mul = vec3( 0.65f, 0.7f, 1.2f );
  90. vec3 max_mul = vec3( 1.2f, 0.9f, 0.7f );
  91. //gl_FragColor.xyz = gl_FragColor.xyz * mix( min_mul, max_mul, lum );
  92.  
  93. if ( baseColor.a < 0.8f && baseColor.a > 0.7f )
  94. {
  95. //gl_FragColor.xyz = texture2D(sampler0, gl_TexCoord[0].st + vec2( sin( gl_TexCoord[0].s * 300 + worldTime / 10.0f ), sin( gl_TexCoord[0].t * 300 + worldTime / 10.0f ) ) * 0.01f ).xyz;
  96. }
  97.  
  98. //gl_FragColor.xyz = baseColor.aaa;
  99. }
  100.  
  101.  
  102. float getDepth(vec2 coord) {
  103. float depth = texture2D(sampler1, coord).x;
  104. float depth2 = texture2D(sampler2, coord).x;
  105. if (depth2 < 1.0) {
  106. depth = depth2;
  107. }
  108.  
  109. depth = 2.0 * near * far / (far + near - (2.0 * depth - 1.0) * (far - near));
  110.  
  111. return depth;
  112. }
  113.  
  114. float getCursorDepth(vec2 coord) {
  115. return 2.0 * near * far / (far + near - (2.0 * texture2D(sampler1, coord).x - 1.0) * (far - near));
  116. }
  117.  
  118. vec4 getBlurredColor() {
  119. vec4 blurredColor = vec4(0.0);
  120. float depth = getDepth(gl_TexCoord[0].xy);
  121. vec2 aspectCorrection = vec2(1.0, aspectRatio) * 0.005;
  122.  
  123. vec2 ac0_4 = 0.4 * aspectCorrection; // 0.4
  124. #ifdef USE_HIGH_QUALITY_BLUR
  125. vec2 ac0_4x0_4 = 0.4 * ac0_4; // 0.16
  126. vec2 ac0_4x0_7 = 0.7 * ac0_4; // 0.28
  127. #endif
  128.  
  129. vec2 ac0_29 = 0.29 * aspectCorrection; // 0.29
  130. #ifdef USE_HIGH_QUALITY_BLUR
  131. vec2 ac0_29x0_7 = 0.7 * ac0_29; // 0.203
  132. vec2 ac0_29x0_4 = 0.4 * ac0_29; // 0.116
  133. #endif
  134.  
  135. vec2 ac0_15 = 0.15 * aspectCorrection; // 0.15
  136. vec2 ac0_37 = 0.37 * aspectCorrection; // 0.37
  137. #ifdef USE_HIGH_QUALITY_BLUR
  138. vec2 ac0_15x0_9 = 0.9 * ac0_15; // 0.135
  139. vec2 ac0_37x0_9 = 0.37 * ac0_37; // 0.1369
  140. #endif
  141.  
  142. vec2 lowSpace = gl_TexCoord[0].st;
  143. vec2 highSpace = 1.0 - lowSpace;
  144. space = vec2(min(lowSpace.s, highSpace.s), min(lowSpace.t, highSpace.t));
  145.  
  146. if (space.s >= ac0_4.s && space.t >= ac0_4.t) {
  147.  
  148. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(0.0, ac0_4.t));
  149. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_4.s, 0.0));
  150. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(0.0, -ac0_4.t));
  151. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_4.s, 0.0));
  152.  
  153. #ifdef USE_HIGH_QUALITY_BLUR
  154. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_4x0_7.s, 0.0));
  155. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(0.0, -ac0_4x0_7.t));
  156. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_4x0_7.s, 0.0));
  157. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(0.0, ac0_4x0_7.t));
  158.  
  159. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_4x0_4.s, 0.0));
  160. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(0.0, -ac0_4x0_4.t));
  161. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_4x0_4.s, 0.0));
  162. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(0.0, ac0_4x0_4.t));
  163. #endif
  164.  
  165. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_29.s, -ac0_29.t));
  166. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_29.s, ac0_29.t));
  167. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_29.s, ac0_29.t));
  168. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_29.s, -ac0_29.t));
  169.  
  170. #ifdef USE_HIGH_QUALITY_BLUR
  171. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_29x0_7.s, ac0_29x0_7.t));
  172. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_29x0_7.s, -ac0_29x0_7.t));
  173. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_29x0_7.s, ac0_29x0_7.t));
  174. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_29x0_7.s, -ac0_29x0_7.t));
  175.  
  176. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_29x0_4.s, ac0_29x0_4.t));
  177. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_29x0_4.s, -ac0_29x0_4.t));
  178. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_29x0_4.s, ac0_29x0_4.t));
  179. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_29x0_4.s, -ac0_29x0_4.t));
  180. #endif
  181.  
  182. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_15.s, ac0_37.t));
  183. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_37.s, ac0_15.t));
  184. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_37.s, -ac0_15.t));
  185. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_15.s, -ac0_37.t));
  186. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_15.s, ac0_37.t));
  187. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_37.s, ac0_15.t));
  188. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_37.s, -ac0_15.t));
  189. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_15.s, -ac0_37.t));
  190.  
  191. #ifdef USE_HIGH_QUALITY_BLUR
  192. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_15x0_9.s, ac0_37x0_9.t));
  193. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_37x0_9.s, ac0_15x0_9.t));
  194. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_37x0_9.s, -ac0_15x0_9.t));
  195. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_15x0_9.s, -ac0_37x0_9.t));
  196. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_15x0_9.s, ac0_37x0_9.t));
  197. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_37x0_9.s, ac0_15x0_9.t));
  198. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_37x0_9.s, -ac0_15x0_9.t));
  199. blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_15x0_9.s, -ac0_37x0_9.t));
  200. #endif
  201.  
  202. #ifdef USE_HIGH_QUALITY_BLUR
  203. blurredColor /= 41.0;
  204. #else
  205. blurredColor /= 16.0;
  206. #endif
  207.  
  208. } else {
  209.  
  210. blurredColor += getSampleWithBoundsCheck(vec2(0.0, ac0_4.t));
  211. blurredColor += getSampleWithBoundsCheck(vec2(ac0_4.s, 0.0));
  212. blurredColor += getSampleWithBoundsCheck(vec2(0.0, -ac0_4.t));
  213. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_4.s, 0.0));
  214.  
  215. #ifdef USE_HIGH_QUALITY_BLUR
  216. blurredColor += getSampleWithBoundsCheck(vec2(ac0_4x0_7.s, 0.0));
  217. blurredColor += getSampleWithBoundsCheck(vec2(0.0, -ac0_4x0_7.t));
  218. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_4x0_7.s, 0.0));
  219. blurredColor += getSampleWithBoundsCheck(vec2(0.0, ac0_4x0_7.t));
  220.  
  221. blurredColor += getSampleWithBoundsCheck(vec2(ac0_4x0_4.s, 0.0));
  222. blurredColor += getSampleWithBoundsCheck(vec2(0.0, -ac0_4x0_4.t));
  223. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_4x0_4.s, 0.0));
  224. blurredColor += getSampleWithBoundsCheck(vec2(0.0, ac0_4x0_4.t));
  225. #endif
  226.  
  227. blurredColor += getSampleWithBoundsCheck(vec2(ac0_29.s, -ac0_29.t));
  228. blurredColor += getSampleWithBoundsCheck(vec2(ac0_29.s, ac0_29.t));
  229. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_29.s, ac0_29.t));
  230. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_29.s, -ac0_29.t));
  231.  
  232. #ifdef USE_HIGH_QUALITY_BLUR
  233. blurredColor += getSampleWithBoundsCheck(vec2(ac0_29x0_7.s, ac0_29x0_7.t));
  234. blurredColor += getSampleWithBoundsCheck(vec2(ac0_29x0_7.s, -ac0_29x0_7.t));
  235. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_29x0_7.s, ac0_29x0_7.t));
  236. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_29x0_7.s, -ac0_29x0_7.t));
  237.  
  238. blurredColor += getSampleWithBoundsCheck(vec2(ac0_29x0_4.s, ac0_29x0_4.t));
  239. blurredColor += getSampleWithBoundsCheck(vec2(ac0_29x0_4.s, -ac0_29x0_4.t));
  240. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_29x0_4.s, ac0_29x0_4.t));
  241. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_29x0_4.s, -ac0_29x0_4.t));
  242. #endif
  243.  
  244. blurredColor += getSampleWithBoundsCheck(vec2(ac0_15.s, ac0_37.t));
  245. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_37.s, ac0_15.t));
  246. blurredColor += getSampleWithBoundsCheck(vec2(ac0_37.s, -ac0_15.t));
  247. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_15.s, -ac0_37.t));
  248. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_15.s, ac0_37.t));
  249. blurredColor += getSampleWithBoundsCheck(vec2(ac0_37.s, ac0_15.t));
  250. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_37.s, -ac0_15.t));
  251. blurredColor += getSampleWithBoundsCheck(vec2(ac0_15.s, -ac0_37.t));
  252.  
  253. #ifdef USE_HIGH_QUALITY_BLUR
  254. blurredColor += getSampleWithBoundsCheck(vec2(ac0_15x0_9.s, ac0_37x0_9.t));
  255. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_37x0_9.s, ac0_15x0_9.t));
  256. blurredColor += getSampleWithBoundsCheck(vec2(ac0_37x0_9.s, -ac0_15x0_9.t));
  257. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_15x0_9.s, -ac0_37x0_9.t));
  258. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_15x0_9.s, ac0_37x0_9.t));
  259. blurredColor += getSampleWithBoundsCheck(vec2(ac0_37x0_9.s, ac0_15x0_9.t));
  260. blurredColor += getSampleWithBoundsCheck(vec2(-ac0_37x0_9.s, -ac0_15x0_9.t));
  261. blurredColor += getSampleWithBoundsCheck(vec2(ac0_15x0_9.s, -ac0_37x0_9.t));
  262. #endif
  263.  
  264. blurredColor /= samples;
  265.  
  266. }
  267.  
  268. return blurredColor;
  269. }
  270.  
  271. vec4 getSampleWithBoundsCheck(vec2 offset) {
  272. vec2 coord = gl_TexCoord[0].st + offset;
  273. if (coord.s <= 1.0 && coord.s >= 0.0 && coord.t <= 1.0 && coord.t >= 0.0) {
  274. samples += 1.0;
  275. return texture2D(sampler0, coord);
  276. } else {
  277. return vec4(0.0);
  278. }
  279. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement