Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Minecraft Combination final shader//
- /* final.fsh
- Shader combination by rcw
- Daxnitro: glsl mod
- azraeil: Dof
- Blackops: Combination shader
- cferrill1: kickass nh/s textures
- Yourself:
- */
- /*Features and Settings*/
- /* Alter here */
- #define ENABLE_GAMMA 1.2
- #define ENABLE_PSEUDO_CELL
- #define CELL_FACTOR 0.4
- #define CELL_DELTA 0.0025
- #define ENABLE_AA
- #define AA_depthThreshold 0.01
- #define ENABLE_SSAO
- #define SSAO_LOOP 4
- #define SSAO_Cap 1.0
- #define SSAO_depthTolerance 0.0001
- #define ENABLE_BLOOM
- #define BLOOM_LOOP 1
- #define BLOOM_OFFSET 0.002
- #define BLOOM_STRENGTH 0.2
- #define ENABLE_DOF
- #define DOF_HYPERFOCAL 4.0
- #define DOF_STRENGTH 0.003
- #define DOF_PI 3.14159265
- //3589793238462
- //#define ENABLE_SHADOWTRACE
- uniform sampler2D sampler0;
- uniform sampler2D sampler1;
- uniform sampler2D sampler2;
- uniform float near;
- uniform float far;
- uniform float aspectRatio;
- uniform float displayHeight;
- uniform float displayWidth;
- /*######################################Helpers###################################*/
- float getMinDepth(vec2 coord) {
- float d = texture2D(sampler2, coord).x;
- if (d < 1.0) return d;
- return texture2D(sampler1, coord).x;
- }
- float getDepth(vec2 coord) {
- float depth= getMinDepth(coord);
- return 2.0 * near * far / ( far + near - ( 2.0 * depth - 1.0 ) * ( far - near ) );
- }
- vec3 BlendOverlay(vec3 base,vec3 blend){
- return vec3(
- (base.r < 0.5 ? (2.0 * base.r * blend.r) : (1.0 - 2.0 * (1.0 - base.r) * (1.0 - blend.r))),
- (base.g < 0.5 ? (2.0 * base.g * blend.g) : (1.0 - 2.0 * (1.0 - base.g) * (1.0 - blend.g))),
- (base.b < 0.5 ? (2.0 * base.b * blend.b) : (1.0 - 2.0 * (1.0 - base.b) * (1.0 - blend.b)))
- );
- }
- /*######################################AA###################################*/
- // 10 depth lookups, 3x3 texture kernel
- #ifdef ENABLE_AA
- float AA_depth( vec2 coord ) {
- float depth= getMinDepth(coord);
- return ( 2.0 * near ) / ( far + near - depth * ( far - near ) );
- }
- vec4 getAA(vec2 coord) {
- vec4 sum = vec4(0.0);
- float depth = AA_depth(coord);
- vec2 offset = vec2(1.0, aspectRatio) * 0.005 * 0.12;
- if (
- abs( depth - AA_depth( coord + vec2( offset.x, 0 ) ) ) > AA_depthThreshold ||
- abs( depth - AA_depth( coord + vec2( -offset.x, 0 ) ) ) > AA_depthThreshold ||
- abs( depth - AA_depth( coord + vec2( 0, offset.y ) ) ) > AA_depthThreshold ||
- abs( depth - AA_depth( coord + vec2( 0, -offset.y ) ) ) > AA_depthThreshold
- ) {
- //3x3 Kernel
- sum += texture2D(sampler0, coord + vec2(-offset.x, offset.y));
- sum += texture2D(sampler0, coord + vec2(0, offset.y));
- sum += texture2D(sampler0, coord + offset);
- sum += texture2D(sampler0, coord + vec2(-offset.x, 0));
- sum += texture2D(sampler0, coord);
- sum += texture2D(sampler0, coord + vec2(offset.x, 0));
- sum += texture2D(sampler0, coord -offset);
- sum += texture2D(sampler0, coord + vec2(0, -offset.y));
- sum += texture2D(sampler0, coord + vec2(offset.x, -offset.y));
- sum /= 9.0;
- } else
- sum=texture2D(sampler0, coord);
- return sum;
- }
- #endif
- /*######################################SSAO###################################*/
- // SSAO_LOOP * 4 + 1 depth lookups
- #ifdef ENABLE_SSAO
- float getSSAOFactor(vec2 coord) {
- float depth = getDepth(coord);
- float d= 0.0;
- float ao = 0.0;
- float aoMultiplier= 300.0;
- float pw = 1.0 / displayWidth;
- float ph = 1.0 / displayHeight;
- for( int i = 0; i < SSAO_LOOP; i++) {
- d=getDepth( vec2(coord.x+pw,coord.y+ph)); ao+=clamp((depth-d-SSAO_depthTolerance) * aoMultiplier,0.0,SSAO_Cap);
- d=getDepth( vec2(coord.x-pw,coord.y+ph)); ao+=clamp((depth-d-SSAO_depthTolerance) * aoMultiplier,0.0,SSAO_Cap);
- d=getDepth( vec2(coord.x+pw,coord.y-ph)); ao+=clamp((depth-d-SSAO_depthTolerance) * aoMultiplier,0.0,SSAO_Cap);
- d=getDepth( vec2(coord.x-pw,coord.y-ph)); ao+=clamp((depth-d-SSAO_depthTolerance) * aoMultiplier,0.0,SSAO_Cap);
- pw*=2.0; ph*=2.0; aoMultiplier/=2.0;
- }
- return 1.0 - ao/16.0;
- }
- #endif
- /*######################################BLOOM###################################*/
- // (2*BLOOM_LOOP+1)^2 + 1 texture lookups
- #ifdef ENABLE_BLOOM
- vec4 getBloom(vec2 coord) {
- vec4 sum = vec4(0);
- for( int i = -BLOOM_LOOP; i <= BLOOM_LOOP; i++) {
- for ( int j = -BLOOM_LOOP; j <= BLOOM_LOOP; j++ ) {
- sum += texture2D( sampler0, coord + vec2( j, i ) * BLOOM_OFFSET ) * BLOOM_STRENGTH;
- }
- }
- sum = sum*sum;
- vec4 rt=texture2D(sampler0, coord);
- if (rt.r < 0.3) sum *= 0.012;
- else if (rt.r < 0.5) sum *= 0.009;
- else sum *= 0.0075;
- return (sum-rt*0.1)*2.0;
- }
- #endif
- /*######################################PSEUDO_CELL###################################*/
- // 6 depth lookups
- #ifdef ENABLE_PSEUDO_CELL
- float getCellShaderFactor(vec2 coord) {
- float d=getDepth(coord);
- vec3 n=normalize(vec3(getDepth(coord+vec2(CELL_DELTA,0.0))-d,getDepth(coord+vec2(0.0,CELL_DELTA))-d ,CELL_FACTOR));
- return n.z;//clamp(n.z*3.0,0.0,1.0);
- }
- #endif
- /*######################################DOF###################################*/
- // 1 depth lookup, 16 texture lookups
- #ifdef ENABLE_DOF
- vec4 sampleClamped(vec2 coord) {
- return (coord.s <= 1.0 && coord.s >= 0.0 && coord.t <= 1.0 && coord.t >= 0.0) ? texture2D(sampler0, coord) : vec4(0.0);
- }
- vec4 getBlurredColor(vec2 coord,float strength) {
- vec4 sum = vec4( 0.0 );
- float depth = getDepth( coord );
- vec2 aspectCorrection = vec2( 1.0, aspectRatio ) * DOF_STRENGTH * strength;
- vec2 ac0_4 = 0.4 * aspectCorrection; // 0.4
- vec2 ac0_29 = 0.29 * aspectCorrection; // 0.29
- vec2 ac0_15 = 0.15 * aspectCorrection; // 0.15
- vec2 ac0_37 = 0.37 * aspectCorrection; // 0.37
- vec2 lowSpace = coord;
- vec2 highSpace = 1.0 - lowSpace;
- vec2 space = vec2( min( lowSpace.s, highSpace.s ), min( lowSpace.t, highSpace.t ) );
- if (space.s >= ac0_4.s && space.t >= ac0_4.t) {
- sum += texture2D(sampler0, coord + vec2(0.0, ac0_4.t));
- sum += texture2D(sampler0, coord + vec2(ac0_4.s, 0.0));
- sum += texture2D(sampler0, coord + vec2(0.0, -ac0_4.t));
- sum += texture2D(sampler0, coord + vec2(-ac0_4.s, 0.0));
- sum += texture2D(sampler0, coord + vec2(ac0_29.s, -ac0_29.t));
- sum += texture2D(sampler0, coord + vec2(ac0_29.s, ac0_29.t));
- sum += texture2D(sampler0, coord + vec2(-ac0_29.s, ac0_29.t));
- sum += texture2D(sampler0, coord + vec2(-ac0_29.s, -ac0_29.t));
- sum += texture2D(sampler0, coord + vec2(ac0_15.s, ac0_37.t));
- sum += texture2D(sampler0, coord + vec2(-ac0_37.s, ac0_15.t));
- sum += texture2D(sampler0, coord + vec2(ac0_37.s, -ac0_15.t));
- sum += texture2D(sampler0, coord + vec2(-ac0_15.s, -ac0_37.t));
- sum += texture2D(sampler0, coord + vec2(-ac0_15.s, ac0_37.t));
- sum += texture2D(sampler0, coord + vec2(ac0_37.s, ac0_15.t));
- sum += texture2D(sampler0, coord + vec2(-ac0_37.s, -ac0_15.t));
- sum += texture2D(sampler0, coord + vec2(ac0_15.s, -ac0_37.t));
- sum /= 16.0;
- } else {
- sum += sampleClamped(coord + vec2(0.0, ac0_4.t));
- sum += sampleClamped(coord + vec2(ac0_4.s, 0.0));
- sum += sampleClamped(coord + vec2(0.0, -ac0_4.t));
- sum += sampleClamped(coord + vec2(-ac0_4.s, 0.0));
- sum += sampleClamped(coord + vec2(ac0_29.s, -ac0_29.t));
- sum += sampleClamped(coord + vec2(ac0_29.s, ac0_29.t));
- sum += sampleClamped(coord + vec2(-ac0_29.s, ac0_29.t));
- sum += sampleClamped(coord + vec2(-ac0_29.s, -ac0_29.t));
- sum += sampleClamped(coord + vec2(ac0_15.s, ac0_37.t));
- sum += sampleClamped(coord + vec2(-ac0_37.s, ac0_15.t));
- sum += sampleClamped(coord + vec2(ac0_37.s, -ac0_15.t));
- sum += sampleClamped(coord + vec2(-ac0_15.s, -ac0_37.t));
- sum += sampleClamped(coord + vec2(-ac0_15.s, ac0_37.t));
- sum += sampleClamped(coord + vec2(ac0_37.s, ac0_15.t));
- sum += sampleClamped(coord + vec2(-ac0_37.s, -ac0_15.t));
- sum += sampleClamped(coord + vec2(ac0_15.s, -ac0_37.t));
- sum /= 16.0;
- }
- return sum;
- }
- float getDOFStrength(float depth,float dcursor){
- if ( dcursor > DOF_HYPERFOCAL )
- {
- if ( depth < DOF_HYPERFOCAL ) return ( depth < 0.5 * DOF_HYPERFOCAL ) ? 1.0 : sin( 2.0 * ( depth - 0.25 * DOF_HYPERFOCAL ) / DOF_HYPERFOCAL * DOF_PI) / 2.0 + 0.5;
- else return 0.0;
- }
- else
- {
- return
- ( depth - dcursor > ( dcursor * DOF_HYPERFOCAL) / ( DOF_HYPERFOCAL - dcursor ) ) ? 1.0 :
- ( depth > dcursor ) ? sin( DOF_PI * ( ( depth - dcursor ) - 0.5 * ( ( dcursor * DOF_HYPERFOCAL ) / ( DOF_HYPERFOCAL - dcursor ) ) ) / ( ( dcursor * DOF_HYPERFOCAL ) / ( DOF_HYPERFOCAL - dcursor ) ) ) / 2.0 + 0.5 :
- ( depth <= 0.5 * dcursor ) ? 1.0 :
- sin(2.0 * (depth - 0.25 * dcursor) / dcursor * DOF_PI) / 2.0 + 0.5 ;
- }
- return 0.0;
- }
- #endif
- /*######################################MAIN###################################*/
- void main() {
- #ifdef ENABLE_AA
- gl_FragColor = getAA(gl_TexCoord[0].st);
- #else
- gl_FragColor = texture2D(sampler0, gl_TexCoord[0].st);
- #endif
- #ifdef ENABLE_DOF
- float dof=getDOFStrength( getDepth( gl_TexCoord[0].st ), getDepth( vec2( 0.5, 0.5 ) ));
- gl_FragColor=getBlurredColor(gl_TexCoord[0].st,dof);
- #endif
- #ifdef ENABLE_SSAO
- gl_FragColor.rgb *= (getSSAOFactor(gl_TexCoord[0].st));
- #endif
- #ifdef ENABLE_PSEUDO_CELL
- gl_FragColor.rgb *= (getCellShaderFactor(gl_TexCoord[0].st));
- #endif
- #ifdef ENABLE_BLOOM
- gl_FragColor.rgb = BlendOverlay(gl_FragColor.rgb, getBloom(gl_TexCoord[0].st).rgb*1.0+0.5);
- #endif
- #ifdef ENABLE_GAMMA
- if (gl_FragColor.a == 0.0) { gl_FragColor = gl_Fog.color; }
- else { gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(1.0/ENABLE_GAMMA)); }
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement