Skip to content

Commit

Permalink
Add the whole ass shader
Browse files Browse the repository at this point in the history
it has begun
  • Loading branch information
X0nk committed Jan 12, 2023
1 parent 9deb741 commit f82426c
Show file tree
Hide file tree
Showing 279 changed files with 28,484 additions and 0 deletions.
68 changes: 68 additions & 0 deletions shaders/block.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

#if MC_VERSION >= 11300

####### ----- SSS and waving ----- #######

##ground waving
block.10001 = minecraft:beetroots minecraft:potatoes minecraft:carrots minecraft:wheat minecraft:nether_wart minecraft:kelp minecraft:large_fern:half=upper minecraft:peony:half=upper minecraft:rose_bush:half=upper minecraft:lilac:half=upper minecraft:crimson_roots minecraft:nether_sprouts minecraft:warped_roots minecraft:seagrass minecraft:tall_seagrass:half=upper minecraft:sunflower:half=upper minecraft:tall_grass:half=upper minecraft:wither_rose minecraft:lily_of_the_valley minecraft:cornflower minecraft:sweet_berry_bush minecraft:oxeye_daisy minecraft:pink_tulip minecraft:white_tulip minecraft:orange_tulip minecraft:red_tulip minecraft:azure_bluet minecraft:allium minecraft:blue_orchid minecraft:poppy minecraft:dandelion minecraft:grass minecraft:dead_bush minecraft:oak_sapling minecraft:spruce_sapling minecraft:birch_sapling minecraft:jungle_sapling minecraft:acacia_sapling minecraft:dark_oak_sapling minecraft:fern

##air waving
block.10003 = minecraft:mangrove_leaves minecraft:vine minecraft:oak_leaves minecraft:spruce_leaves minecraft:birch_leaves minecraft:jungle_leaves minecraft:acacia_leaves minecraft:dark_oak_leaves

####### ----- SSS ----- #######

## strong
block.10004 = minecraft:fern minecraft:packed_ice minecraft:blue_ice minecraft:melon_stem minecraft:pumpkin_stem minecraft:attached_melon_stem minecraft:attached_pumpkin_stem minecraft:lily_pad minecraft:azalea_leaves minecraft:flowering_azalea_leaves minecraft:azalea minecraft:flowering_azalea

## weak
block.10006 = weeping_vines weeping_vines_plant twisting_vines twisting_vines_plant vine tube_coral tube_coral_block tube_coral_fan tube_coral_wall_fan horn_coral horn_coral_block horn_coral_fan horn_coral_wall_fan fire_coral fire_coral_block fire_coral_fan fire_coral_wall_fan dead_brain_coral dead_brain_coral_block dead_brain_coral_fan dead_brain_coral_wall_fan dead_bubble_coral dead_bubble_coral_block dead_bubble_coral_fan dead_bubble_coral_wall_fan dead_bush dead_fire_coral dead_fire_coral_block dead_fire_coral_fan dead_fire_coral_wall_fan dead_horn_coral dead_horn_coral_block dead_horn_coral_fan dead_horn_coral_wall_fan dead_tube_coral dead_tube_coral_block dead_tube_coral_fan dead_tube_coral_wall_fan bubble_coral bubble_coral_block bubble_coral_fan bubble_coral_wall_fan brain_coral brain_coral_block brain_coral_fan brain_coral_wall_fan bamboo bamboo_sapling minecraft:tall_seagrass minecraft:seagrass minecraft:kelp minecraft:large_fern minecraft:tall_grass minecraft:tall_seagrass minecraft:kelp_plant minecraft:peony minecraft:rose_bush minecraft:lilac minecraft:sunflower minecraft:spore_blossom minecraft:cave_vines minecraft:cave_vines_plant minecraft:glow_lichen minecraft:melon minecraft:pumpkin minecraft:big_dripleaf minecraft:big_dripleaf_stem minecraft:cactus minecraft:hay_block minecraft:brown_mushroom minecraft:mushroom_stem minecraft:sugar_cane minecraft:crimson_fungus minecraft:warped_fungus minecraft:sea_pickle minecraft:cobweb minecraft:honeycomb_block

block.200 = minecraft:white_wool minecraft:orange_wool minecraft:magenta_wool minecraft:light_blue_wool minecraft:yellow_wool minecraft:lime_wool minecraft:pink_wool minecraft:gray_wool minecraft:light_gray_wool minecraft:cyan_wool minecraft:purple_wool minecraft:blue_wool minecraft:brown_wool minecraft:green_wool minecraft:red_wool minecraft:black_wool minecraft:orange_carpet minecraft:magenta_carpet minecraft:light_blue_carpet minecraft:yellow_carpet minecraft:lime_carpet minecraft:pink_carpet minecraft:gray_carpet minecraft:light_gray_carpet minecraft:cyan_carpet minecraft:purple_carpet minecraft:blue_carpet minecraft:brown_carpet minecraft:green_carpet minecraft:red_carpet minecraft:black_carpet

# block.201 =



block.10010 = minecraft:white_wall_banner minecraft:orange_wall_banner minecraft:magenta_wall_banner minecraft:light_blue_wall_banner minecraft:yellow_wall_banner minecraft:lime_wall_banner minecraft:pink_wall_banner minecraft:gray_wall_banner minecraft:light_gray_wall_banner minecraft:cyan_wall_banner minecraft:purple_wall_banner minecraft:blue_wall_banner minecraft:brown_wall_banner minecraft:green_wall_banner minecraft:red_wall_banner minecraft:black_wall_banner minecraft:white_banner minecraft:orange_banner minecraft:magenta_banner minecraft:light_blue_banner minecraft:yellow_banner minecraft:lime_banner minecraft:pink_banner minecraft:gray_banner minecraft:light_gray_banner minecraft:cyan_banner minecraft:purple_banner minecraft:blue_banner minecraft:brown_banner minecraft:green_banner minecraft:red_banner minecraft:black_banner


## weird blocks
block.10007 = minecraft:grass_block:snowy=false minecraft:sand minecraft:red_sand minecraft:snow_block minecraft:snow powder_snow minecraft:grass_block:snowy=true

####### ----- lightsources ----- #######

block.10005 = minecraft:sculk_sensor minecraft:soul_fire minecraft:soul_campfire:lit=true minecraft:cave_vines_plant:berries=true minecraft:soul_lantern minecraft:soul_torch minecraft:soul_wall_torch minecraft:conduit minecraft:beacon minecraft:sea_pickle minecraft:respawn_anchor:charges=4 minecraft:smoker:lit=true minecraft:blast_furnace:lit=true minecraft:furnace:lit=true minecraft:lava_cauldron minecraft:sea_lantern minecraft:cave_vines:berries=true minecraft:glowstone minecraft:torch minecraft:wall_torch minecraft:lava minecraft:fire minecraft:redstone_torch minecraft:redstone_wall_torch minecraft:jack_o_lantern minecraft:magma_block minecraft:redstone_lamp:lit=true minecraft:lantern minecraft:campfire:lit=true minecraft:shroomlight minecraft:end_rod minecraft:end_gateway minecraft:lava minecraft:fire

####### ----- reflective translucents / glass ----- #######

block.10002 = minecraft:slime_block minecraft:nether_portal minecraft:honey_block ice minecraft:frosted_ice minecraft:black_stained_glass minecraft:black_stained_glass_pane minecraft:blue_stained_glass minecraft:blue_stained_glass_pane minecraft:brown_stained_glass minecraft:brown_stained_glass_pane minecraft:cyan_stained_glass minecraft:cyan_stained_glass_pane minecraft:gray_stained_glass minecraft:gray_stained_glass_pane minecraft:green_stained_glass minecraft:green_stained_glass_pane minecraft:light_blue_stained_glass minecraft:light_blue_stained_glass_pane minecraft:light_gray_stained_glass minecraft:light_gray_stained_glass_pane minecraft:lime_stained_glass minecraft:lime_stained_glass_pane minecraft:magenta_stained_glass minecraft:magenta_stained_glass_pane minecraft:orange_stained_glass minecraft:orange_stained_glass_pane minecraft:pink_stained_glass minecraft:pink_stained_glass_pane minecraft:purple_stained_glass minecraft:purple_stained_glass_pane minecraft:red_stained_glass minecraft:red_stained_glass_pane minecraft:white_stained_glass minecraft:white_stained_glass_pane minecraft:yellow_stained_glass minecraft:yellow_stained_glass_pane minecraft:glass_pane minecraft:glass

####### ----- misc ----- #######

block.222 = end_portal end_gateway end_portal_frame

block.8 = minecraft:water minecraft:flowing_water

#else

#wavy plants, translucent, bottom vertices not moving

block.10001= 6 31 32 37 38 39 40 59 115 141 142 207

#wavy plants (blocks)

block.10003 = 18 106 161

#translucent

block.10004 = 30 83 104 105 111 175 176 177

#reflective surfaces (not including water and ice)

block.10002=95 160

#endif

layer.translucent=minecraft:glass_pane minecraft:glass

# layer.solid = minecraft:tripwire minecraft:slime_block minecraft:nether_portal minecraft:honey_block minecraft:ice minecraft:black_stained_glass minecraft:black_stained_glass_pane minecraft:blue_stained_glass minecraft:blue_stained_glass_pane minecraft:brown_stained_glass minecraft:brown_stained_glass_pane minecraft:cyan_stained_glass minecraft:cyan_stained_glass_pane minecraft:gray_stained_glass minecraft:gray_stained_glass_pane minecraft:green_stained_glass minecraft:green_stained_glass_pane minecraft:light_blue_stained_glass minecraft:light_blue_stained_glass_pane minecraft:light_gray_stained_glass minecraft:light_gray_stained_glass_pane minecraft:lime_stained_glass minecraft:lime_stained_glass_pane minecraft:magenta_stained_glass minecraft:magenta_stained_glass_pane minecraft:orange_stained_glass minecraft:orange_stained_glass_pane minecraft:pink_stained_glass minecraft:pink_stained_glass_pane minecraft:purple_stained_glass minecraft:purple_stained_glass_pane minecraft:red_stained_glass minecraft:red_stained_glass_pane minecraft:white_stained_glass minecraft:white_stained_glass_pane minecraft:yellow_stained_glass minecraft:yellow_stained_glass_pane minecraft:glass_pane minecraft:glass
276 changes: 276 additions & 0 deletions shaders/composite.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable

#define TAA

// #define LabPBR_subsurface_scattering
flat varying vec3 WsunVec;
flat varying vec2 TAA_Offset;
#include "/lib/res_params.glsl"
#include "lib/Shadow_Params.glsl"
uniform sampler2D depthtex1;
uniform sampler2D colortex1;
uniform sampler2D colortex6; // Noise
uniform sampler2D colortex8; // Noise
uniform sampler2D colortex15; // Noise
uniform sampler2D shadow;
uniform sampler2D noisetex;
uniform vec3 sunVec;
uniform vec2 texelSize;
uniform float frameTimeCounter;
uniform float rainStrength;
uniform int frameCounter;
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelView;

uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
uniform vec3 cameraPosition;
uniform float viewWidth;
uniform float aspectRatio;
uniform float viewHeight;
uniform float far;
uniform float near;

#define ffstep(x,y) clamp((y - x) * 1e35,0.0,1.0)
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
vec3 toScreenSpace(vec3 p) {
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
vec3 p3 = p * 2. - 1.;
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
return fragposition.xyz / fragposition.w;
}
vec3 worldToView(vec3 worldPos) {
vec4 pos = vec4(worldPos, 0.0);
pos = gbufferModelView * pos;
return pos.xyz;
}

vec2 tapLocation(int sampleNumber,int nb, float nbRot,float jitter,float distort)
{
float alpha = (sampleNumber+jitter)/nb;
float angle = jitter*6.28+alpha * nbRot * 6.28;
float sin_v, cos_v;

sin_v = sin(angle);
cos_v = cos(angle);

return vec2(cos_v, sin_v)*alpha;
}
// float interleaved_gradientNoise(){
// vec2 coord = gl_FragCoord.xy;
// float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+ 1.0/1.6180339887 * frameCounter) ;
// return noise;
// }
// float interleaved_gradientNoise2(){
// vec2 alpha = vec2(0.75487765, 0.56984026);
// vec2 coord = vec2(alpha.x * gl_FragCoord.x,alpha.y * gl_FragCoord.y)+ 1.0/1.6180339887 * frameCounter;
// float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
// return noise;
// }
float interleaved_gradientNoise(){
vec2 coord = gl_FragCoord.xy + (frameCounter%40000);
// vec2 coord = gl_FragCoord.xy + frameTimeCounter;
// vec2 coord = gl_FragCoord.xy;
float noise = fract( 52.9829189 * fract( (coord.x * 0.06711056) + (coord.y * 0.00583715)) );
return noise ;
}
vec3 decode (vec2 encn){
vec3 n = vec3(0.0);
encn = encn * 2.0 - 1.0;
n.xy = abs(encn);
n.z = 1.0 - n.x - n.y;
n.xy = n.z <= 0.0 ? (1.0 - n.yx) * sign(encn) : encn;
return clamp(normalize(n.xyz),-1.0,1.0);
}
vec2 decodeVec2(float a){
const vec2 constant1 = 65535. / vec2( 256., 65536.);
const float constant2 = 256. / 255.;
return fract( a * constant1 ) * constant2 ;
}
float R2_dither(){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter);
}
float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
}
vec4 blueNoise(vec2 coord){
return texelFetch2D(colortex6, ivec2(coord )%512 , 0);
}

vec2 R2_samples(int n){
vec2 alpha = vec2(0.75487765, 0.56984026);
return fract(alpha * n);
}
vec2 tapLocation_alternate(
int sampleNumber,
float spinAngle,
int nb,
float nbRot,
float r0
){
float alpha = (float(sampleNumber*1.0f + r0) * (1.0 / (nb)));
float angle = alpha * (nbRot * 3.14) ;

float ssR = alpha + spinAngle*3.14;
float sin_v, cos_v;

sin_v = sin(angle);
cos_v = cos(angle);
return vec2(cos_v, sin_v)*ssR;
}
vec3 viewToWorld(vec3 viewPosition) {
vec4 pos;
pos.xyz = viewPosition;
pos.w = 0.0;
pos = gbufferModelViewInverse * pos;
return pos.xyz;
}


// Emin's and Gri's combined ideas to stop peter panning and light leaking, also has little shadowacne so thats nice
// https://www.complementary.dev/reimagined
// https://github.com/gri573
void GriAndEminShadowFix(
inout vec3 WorldPos,
vec3 FlatNormal,
float VanillaAO,
float SkyLightmap,
bool Entities
){
float DistanceOffset = clamp(0.1 + length(WorldPos) / (shadowMapResolution*0.20), 0.0,1.0) ;
vec3 Bias = FlatNormal * DistanceOffset; // adjust the bias thingy's strength as it gets farther away.

// stop lightleaking
if(SkyLightmap < 0.1 && !Entities) {
WorldPos += mix(Bias, 0.5 * (0.5 - fract(WorldPos + cameraPosition + FlatNormal*0.01 ) ), VanillaAO) ;
}else{
WorldPos += Bias;
}
}

void main() {
/* DRAWBUFFERS:3 */
vec2 texcoord = gl_FragCoord.xy*texelSize;


float z = texture2D(depthtex1,texcoord).x;

vec2 tempOffset=TAA_Offset;

vec4 data = texture2D(colortex1,texcoord);
vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y));
vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w));
vec3 normal = mat3(gbufferModelViewInverse) * clamp(worldToView( decode(dataUnpacked0.yw) ),-1.,1.);
vec2 lightmap = dataUnpacked1.yz;


bool translucent = abs(dataUnpacked1.w-0.5) <0.01;
bool translucent2 = abs(dataUnpacked1.w-0.6) <0.01; // Weak translucency
bool translucent3 = abs(dataUnpacked1.w-0.55) <0.01; // Weak translucency
bool translucent4 = abs(dataUnpacked1.w-0.65) <0.01; // Weak translucency
bool entities = abs(dataUnpacked1.w-0.45) <0.01; // Weak translucency
bool hand = abs(dataUnpacked1.w-0.75) <0.01;

float minshadowfilt = Min_Shadow_Filter_Radius;
float maxshadowfilt = Max_Shadow_Filter_Radius;

float vanillAO = clamp(pow(1-texture2D(colortex15,texcoord).a*2,4),0,1) ;

if(lightmap.y < 0.1 && !entities){
// minshadowfilt *= vanillAO;
maxshadowfilt = mix(minshadowfilt ,maxshadowfilt, vanillAO);
}


#ifdef LabPBR_subsurface_scattering
float SpecularTex = texture2D(colortex8,texcoord).z;
float LabSSS = clamp((-65.0 + SpecularTex * 255.0) / 190.0 ,0.0,1.0);
#else
float LabSSS = 0.0;
#endif


#ifndef Variable_Penumbra_Shadows
if (translucent && !hand) minshadowfilt += 25;
#endif


gl_FragData[0] = vec4(minshadowfilt, 0.1, 0.0, 0.0);



if (z < 1.0){

// if( translucent || translucent2)

if (!hand){

float NdotL = clamp(dot(normal,WsunVec),0.0,1.0);

vec3 fragpos = toScreenSpace(vec3(texcoord/RENDER_SCALE-vec2(tempOffset)*texelSize*0.5,z));

#ifdef Variable_Penumbra_Shadows

if (NdotL > 0.000 || LabSSS > 0.0 || translucent || translucent2 || translucent3 || translucent4) {

vec3 p3 = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz;

vec3 projectedShadowPosition = mat3(shadowModelView) * p3 + shadowModelView[3].xyz;
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;

//apply distortion
float distortFactor = calcDistort(projectedShadowPosition.xy);
projectedShadowPosition.xy *= distortFactor;
//do shadows only if on shadow map
if (abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.z) < 6.0){
const float threshMul = max(2048.0/shadowMapResolution*shadowDistance/128.0,0.95);
float distortThresh = (sqrt(1.0-NdotL*NdotL)/NdotL+0.7)/distortFactor;
float diffthresh = distortThresh/6000.0*threshMul;
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5,0.5,0.5);

float mult = maxshadowfilt;
float avgBlockerDepth = 0.0;
vec2 scales = vec2(0.0,Max_Filter_Depth);
float blockerCount = 0.0;
float rdMul = distortFactor*(1.0+mult)*d0*k/shadowMapResolution;
float diffthreshM = diffthresh*mult*d0*k/20.;
float avgDepth = 0.0;

int seed = (frameCounter%40000) + (1+frameCounter);
float randomDir = fract(R2_samples(seed).y + blueNoise(gl_FragCoord.xy).g) * 1.61803398874 ;

for(int i = 0; i < VPS_Search_Samples; i++){

// vec2 offsetS = tapLocation(i,VPS_Search_Samples,1.61803398874 , blueNoise(),0.0);

vec2 offsetS = tapLocation_alternate(i, 0.0, 7, 20, randomDir);

float weight = 3.0 + (i+blueNoise() ) *rdMul/SHADOW_FILTER_SAMPLE_COUNT*shadowMapResolution*distortFactor/2.7;
float d = texelFetch2D( shadow, ivec2((projectedShadowPosition.xy+offsetS*rdMul)*shadowMapResolution),0).x;
float b = smoothstep(weight*diffthresh/2.0, weight*diffthresh, projectedShadowPosition.z - d);

blockerCount += b;
avgDepth += max(projectedShadowPosition.z - d, 0.0)*1000.;
avgBlockerDepth += d * b;
}

gl_FragData[0].g = avgDepth / VPS_Search_Samples;
gl_FragData[0].b = blockerCount / VPS_Search_Samples;
if (blockerCount >= 0.9){
avgBlockerDepth /= blockerCount;
float ssample = max(projectedShadowPosition.z - avgBlockerDepth,0.0)*1500.0;
gl_FragData[0].r = clamp(ssample, scales.x, scales.y)/(scales.y)*(mult-minshadowfilt)+minshadowfilt;
}
}
}
#endif
}

}

}
35 changes: 35 additions & 0 deletions shaders/composite.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
#define TAA
flat varying vec2 TAA_Offset;
flat varying vec3 WsunVec;

uniform sampler2D colortex4;

uniform int frameCounter;
uniform float sunElevation;
uniform vec3 sunPosition;
uniform mat4 gbufferModelViewInverse;
#include "/lib/util.glsl"
#include "/lib/res_params.glsl"
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
void main() {
TAA_Offset = offsets[frameCounter%8];
#ifndef TAA
TAA_Offset = vec2(0.0);
#endif
gl_Position = ftransform();
#ifdef TAA_UPSCALING
gl_Position.xy = (gl_Position.xy*0.5+0.5)*RENDER_SCALE*2.0-1.0;
#endif

WsunVec = (float(sunElevation > 1e-5)*2-1.)*normalize(mat3(gbufferModelViewInverse) * sunPosition);

}
Loading

0 comments on commit f82426c

Please sign in to comment.