Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BASE.VSH
- // Shader that curves the Minecraft world by daxnitro.
- #version 120 // This will always get moved to the top of the code in pre-processing.
- const float WORLD_RADIUS = 1000.0;
- const float WORLD_RADIUS_SQUARED = 1000000.0;
- #ifdef _ENABLE_GL_TEXTURE_2D
- centroid varying vec4 texCoord;
- #endif
- varying vec4 vertColor;
- void main() {
- vec4 position = gl_ModelViewMatrix * gl_Vertex;
- if (gl_Color.a != 0.8) {
- // Not a cloud.
- float distanceSquared = position.x * position.x + position.z * position.z;
- position.y -= WORLD_RADIUS - sqrt(max(1.0 - distanceSquared / WORLD_RADIUS_SQUARED, 0.0)) * WORLD_RADIUS;
- }
- gl_Position = gl_ProjectionMatrix * position;
- #ifdef _ENABLE_GL_TEXTURE_2D
- texCoord = gl_MultiTexCoord0;
- #endif
- vertColor = gl_Color;
- gl_FogFragCoord = gl_Position.z;
- }
- FINAL.FSH
- // More realistic depth-of-field by Azraeil.
- // This is a modification of Daxnitro's depth-of-field shader.
- // If you want a higher quality blur, remove the forward slashes from the following line:
- //#define USE_HIGH_QUALITY_BLUR
- uniform sampler2D sampler0;
- uniform sampler2D sampler1;
- uniform sampler2D sampler2;
- uniform float aspectRatio;
- uniform float near;
- uniform float far;
- uniform int worldTime;
- // HYPERFOCAL = (Focal Distance ^ 2)/(Circle of Confusion * F Stop) + Focal Distance
- const float HYPERFOCAL = 3.132;
- const float PICONSTANT = 3.14159;
- float getDepth(vec2 coord);
- float getCursorDepth(vec2 coord);
- vec4 getBlurredColor();
- vec4 getSample(vec2 coord, vec2 aspectCorrection);
- vec4 getSampleWithBoundsCheck(vec2 offset);
- float samples = 0.0;
- vec2 space;
- void main() {
- vec4 baseColor = texture2D(sampler0, gl_TexCoord[0].st);
- gl_FragColor = baseColor;
- float depth = getDepth(gl_TexCoord[0].st);
- float cursorDepth = getCursorDepth(vec2(0.5, 0.5));
- // foreground blur = 1/2 background blur. Blur should follow exponential pattern until cursor = hyperfocal -- Cursor before hyperfocal
- // Blur should go from 0 to 1/2 hyperfocal then clear to infinity -- Cursor @ hyperfocal.
- // hyperfocal to inifity is clear though dof extends from 1/2 hyper to hyper -- Cursor beyond hyperfocal
- float blur_start = 30;
- float blur_length = 15;
- float blur = clamp( ( depth - blur_start ) / blur_length, 0.0, 1.0 );
- // gl_FragColor = mix(baseColor, getBlurredColor(), blur);
- float lum = dot( baseColor.xyz, vec3( 0.39f, 0.5f, 0.11f ) );
- vec3 min_mul = vec3( 0.65f, 0.7f, 1.2f );
- vec3 max_mul = vec3( 1.2f, 0.9f, 0.7f );
- //gl_FragColor.xyz = gl_FragColor.xyz * mix( min_mul, max_mul, lum );
- if ( baseColor.a < 0.8f && baseColor.a > 0.7f )
- {
- //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;
- }
- //gl_FragColor.xyz = baseColor.aaa;
- }
- float getDepth(vec2 coord) {
- float depth = texture2D(sampler1, coord).x;
- float depth2 = texture2D(sampler2, coord).x;
- if (depth2 < 1.0) {
- depth = depth2;
- }
- depth = 2.0 * near * far / (far + near - (2.0 * depth - 1.0) * (far - near));
- return depth;
- }
- float getCursorDepth(vec2 coord) {
- return 2.0 * near * far / (far + near - (2.0 * texture2D(sampler1, coord).x - 1.0) * (far - near));
- }
- vec4 getBlurredColor() {
- vec4 blurredColor = vec4(0.0);
- float depth = getDepth(gl_TexCoord[0].xy);
- vec2 aspectCorrection = vec2(1.0, aspectRatio) * 0.005;
- vec2 ac0_4 = 0.4 * aspectCorrection; // 0.4
- #ifdef USE_HIGH_QUALITY_BLUR
- vec2 ac0_4x0_4 = 0.4 * ac0_4; // 0.16
- vec2 ac0_4x0_7 = 0.7 * ac0_4; // 0.28
- #endif
- vec2 ac0_29 = 0.29 * aspectCorrection; // 0.29
- #ifdef USE_HIGH_QUALITY_BLUR
- vec2 ac0_29x0_7 = 0.7 * ac0_29; // 0.203
- vec2 ac0_29x0_4 = 0.4 * ac0_29; // 0.116
- #endif
- vec2 ac0_15 = 0.15 * aspectCorrection; // 0.15
- vec2 ac0_37 = 0.37 * aspectCorrection; // 0.37
- #ifdef USE_HIGH_QUALITY_BLUR
- vec2 ac0_15x0_9 = 0.9 * ac0_15; // 0.135
- vec2 ac0_37x0_9 = 0.37 * ac0_37; // 0.1369
- #endif
- vec2 lowSpace = gl_TexCoord[0].st;
- vec2 highSpace = 1.0 - lowSpace;
- space = vec2(min(lowSpace.s, highSpace.s), min(lowSpace.t, highSpace.t));
- if (space.s >= ac0_4.s && space.t >= ac0_4.t) {
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(0.0, ac0_4.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_4.s, 0.0));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(0.0, -ac0_4.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_4.s, 0.0));
- #ifdef USE_HIGH_QUALITY_BLUR
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_4x0_7.s, 0.0));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(0.0, -ac0_4x0_7.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_4x0_7.s, 0.0));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(0.0, ac0_4x0_7.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_4x0_4.s, 0.0));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(0.0, -ac0_4x0_4.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_4x0_4.s, 0.0));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(0.0, ac0_4x0_4.t));
- #endif
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_29.s, -ac0_29.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_29.s, ac0_29.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_29.s, ac0_29.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_29.s, -ac0_29.t));
- #ifdef USE_HIGH_QUALITY_BLUR
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_29x0_7.s, ac0_29x0_7.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_29x0_7.s, -ac0_29x0_7.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_29x0_7.s, ac0_29x0_7.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_29x0_7.s, -ac0_29x0_7.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_29x0_4.s, ac0_29x0_4.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_29x0_4.s, -ac0_29x0_4.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_29x0_4.s, ac0_29x0_4.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_29x0_4.s, -ac0_29x0_4.t));
- #endif
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_15.s, ac0_37.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_37.s, ac0_15.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_37.s, -ac0_15.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_15.s, -ac0_37.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_15.s, ac0_37.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_37.s, ac0_15.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_37.s, -ac0_15.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_15.s, -ac0_37.t));
- #ifdef USE_HIGH_QUALITY_BLUR
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_15x0_9.s, ac0_37x0_9.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_37x0_9.s, ac0_15x0_9.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_37x0_9.s, -ac0_15x0_9.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_15x0_9.s, -ac0_37x0_9.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_15x0_9.s, ac0_37x0_9.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_37x0_9.s, ac0_15x0_9.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(-ac0_37x0_9.s, -ac0_15x0_9.t));
- blurredColor += texture2D(sampler0, gl_TexCoord[0].st + vec2(ac0_15x0_9.s, -ac0_37x0_9.t));
- #endif
- #ifdef USE_HIGH_QUALITY_BLUR
- blurredColor /= 41.0;
- #else
- blurredColor /= 16.0;
- #endif
- } else {
- blurredColor += getSampleWithBoundsCheck(vec2(0.0, ac0_4.t));
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_4.s, 0.0));
- blurredColor += getSampleWithBoundsCheck(vec2(0.0, -ac0_4.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_4.s, 0.0));
- #ifdef USE_HIGH_QUALITY_BLUR
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_4x0_7.s, 0.0));
- blurredColor += getSampleWithBoundsCheck(vec2(0.0, -ac0_4x0_7.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_4x0_7.s, 0.0));
- blurredColor += getSampleWithBoundsCheck(vec2(0.0, ac0_4x0_7.t));
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_4x0_4.s, 0.0));
- blurredColor += getSampleWithBoundsCheck(vec2(0.0, -ac0_4x0_4.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_4x0_4.s, 0.0));
- blurredColor += getSampleWithBoundsCheck(vec2(0.0, ac0_4x0_4.t));
- #endif
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_29.s, -ac0_29.t));
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_29.s, ac0_29.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_29.s, ac0_29.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_29.s, -ac0_29.t));
- #ifdef USE_HIGH_QUALITY_BLUR
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_29x0_7.s, ac0_29x0_7.t));
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_29x0_7.s, -ac0_29x0_7.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_29x0_7.s, ac0_29x0_7.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_29x0_7.s, -ac0_29x0_7.t));
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_29x0_4.s, ac0_29x0_4.t));
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_29x0_4.s, -ac0_29x0_4.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_29x0_4.s, ac0_29x0_4.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_29x0_4.s, -ac0_29x0_4.t));
- #endif
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_15.s, ac0_37.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_37.s, ac0_15.t));
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_37.s, -ac0_15.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_15.s, -ac0_37.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_15.s, ac0_37.t));
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_37.s, ac0_15.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_37.s, -ac0_15.t));
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_15.s, -ac0_37.t));
- #ifdef USE_HIGH_QUALITY_BLUR
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_15x0_9.s, ac0_37x0_9.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_37x0_9.s, ac0_15x0_9.t));
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_37x0_9.s, -ac0_15x0_9.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_15x0_9.s, -ac0_37x0_9.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_15x0_9.s, ac0_37x0_9.t));
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_37x0_9.s, ac0_15x0_9.t));
- blurredColor += getSampleWithBoundsCheck(vec2(-ac0_37x0_9.s, -ac0_15x0_9.t));
- blurredColor += getSampleWithBoundsCheck(vec2(ac0_15x0_9.s, -ac0_37x0_9.t));
- #endif
- blurredColor /= samples;
- }
- return blurredColor;
- }
- vec4 getSampleWithBoundsCheck(vec2 offset) {
- vec2 coord = gl_TexCoord[0].st + offset;
- if (coord.s <= 1.0 && coord.s >= 0.0 && coord.t <= 1.0 && coord.t >= 0.0) {
- samples += 1.0;
- return texture2D(sampler0, coord);
- } else {
- return vec4(0.0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement