readd SSGI, fix spider eyes on iris, fix min light amount

all that.
This commit is contained in:
Xonk 2023-04-16 19:43:56 -04:00
parent 2ee6634935
commit e1c82709f0
11 changed files with 252 additions and 177 deletions

View File

@ -610,43 +610,6 @@ vec3 TangentToWorld(vec3 N, vec3 H, float roughness){
return vec3((T * H.x) + (B * H.y) + (N * H.z));
}
// void rtAO(inout vec3 lighting, vec3 normal, vec2 noise, vec3 fragpos, float lightmap, float inShadow){
// int nrays = 4;
// float occlude = 0.0;
// float indoor = clamp(pow(lightmap,2)*2,0.0,AO_Strength);
// for (int i = 0; i < nrays; i++){
// int seed = (frameCounter%40000)*nrays+i;
// vec2 ij = fract(R2_samples(seed) + noise.rg);
// vec3 rayDir = TangentToWorld( normal, normalize(cosineHemisphereSample(ij,1.0)) ,1.0) ;
// #ifdef HQ_SSGI
// vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, fragpos, blueNoise(), 30.); // ssr rt
// #else
// vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, fragpos, blueNoise(), 24.); // choc sspt
// #endif
// // vec3 lightDir = normalize(vec3(0.2,0.8,0.2));
// // float skyLightDir = dot(rayDir,lightDir); // the positons where the occlusion happens
// float skyLightDir = rayDir.y > 0.0 ? 1.0 : max(rayDir.y,1.0-indoor); // the positons where the occlusion happens
// // if (rayHit.z > 1.0) occlude += skyLightDir;
// occlude += normalize(rayHit.z - 1.0) / (1.1-rayDir.y);
// }
// // occlude = mix( occlude,1, inShadow);
// // occlude = occlude*0.5 + 0.5;
// // lighting *= 2.5;
// lighting *= occlude/nrays;
// }
void rtAO(inout vec3 lighting, vec3 normal, vec2 noise, vec3 fragpos, float lightmap, float inShadow){
int nrays = 4;
float occlude = 0.0;
@ -680,53 +643,12 @@ void rtAO(inout vec3 lighting, vec3 normal, vec2 noise, vec3 fragpos, float ligh
lighting *= mix(occlude/nrays,1.0,0) ;
}
// void rtGI(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, float lightmap, vec3 albedo, float inShadow){
// int nrays = RAY_COUNT;
// vec3 intRadiance = vec3(0.0);
// vec3 occlude = vec3(0.0);
// lighting *= 1.50;
// float indoor = clamp(pow(lightmap,2)*2,0.0,AO_Strength);
// for (int i = 0; i < nrays; i++){
// int seed = (frameCounter%40000)*nrays+i;
// vec2 ij = fract(R2_samples(seed) + noise );
// vec3 rayDir = TangentToWorld(normal, normalize(cosineHemisphereSample(ij,1.0)) ,1.0);
// #ifdef HQ_SSGI
// vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, fragpos, blueNoise(), 50.); // ssr rt
// #else
// vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, fragpos, blueNoise(), 30.); // choc sspt
// #endif
// float skyLightDir = rayDir.y > 0.0 ? 1.0 : max(rayDir.y,1.0-indoor); // the positons where the occlusion happens
// if (rayHit.z < 1.){
// vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rayHit) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
// previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz;
// previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5;
// if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0)
// intRadiance = DoContrast(texture2D(colortex5,previousPosition.xy).rgb) ;
// else
// intRadiance += lighting*skyLightDir; // make sure ambient light exists but at screen edges when you turn
// }else{
// intRadiance += lighting*skyLightDir;
// }
// }
// lighting = intRadiance/nrays;
// }
void rtGI(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, float lightmap, vec3 albedo){
int nrays = RAY_COUNT;
vec3 intRadiance = vec3(0.0);
float occlusion = 0.0;
vec3 occlude = vec3(0.0);
// lighting *= 1.50;
lighting *= 1.50;
float indoor = clamp(pow(lightmap,2)*2,0.0,AO_Strength);
for (int i = 0; i < nrays; i++){
@ -741,32 +663,25 @@ void rtGI(inout vec3 lighting, vec3 normal,vec2 noise,vec3 fragpos, float lightm
vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, fragpos, blueNoise(), 30.); // choc sspt
#endif
float skyLightDir = rayDir.y > 0.0 ? 0.0 : 0.0; // the positons where the occlusion happens
// vec3 AO = lighting * (normalize(rayHit.z - 1.0) / (1.1-rayDir.y));
if (rayHit.z < 1){
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rayHit)+ gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
float skyLightDir = rayDir.y > 0.0 ? 1.0 : max(rayDir.y,1.0-indoor); // the positons where the occlusion happens
if (rayHit.z < 1.){
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rayHit) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz;
previousPosition.xy = projMAD(gbufferPreviousProjection, previousPosition).xy / -previousPosition.z * 0.5 + 0.5;
if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0)
intRadiance = 0 + texture2D(colortex5,previousPosition.xy).rgb * GI_Strength ;
else
intRadiance += lighting*skyLightDir; // make sure ambient light exists but at screen edges when you turn
if (previousPosition.x > 0.0 && previousPosition.y > 0.0 && previousPosition.x < 1.0 && previousPosition.x < 1.0){
// intRadiance = DoContrast(texture2DLod(colortex5,previousPosition.xy,0).rgb, 55.0 ) * GI_Strength ;
intRadiance = texture2DLod(colortex5,previousPosition.xy,0).rgb * GI_Strength ;
}else{
intRadiance += lighting*skyLightDir;
}
occlusion += 1.0;
}
}
lighting = lighting * (1.0-occlusion/nrays) + intRadiance/nrays;
lighting = intRadiance/nrays;
}
void SubsurfaceScattering(inout float SSS, float Scattering, float Density, float LabDenisty){
#ifdef LabPBR_subsurface_scattering
float labcurve = pow(LabDenisty,LabSSS_Curve);
@ -1146,7 +1061,7 @@ void main() {
// SSGI
#if indirect_effect == 4
if (!hand) rtGI(gl_FragData[0].rgb, normal, blueNoise(gl_FragCoord.xy).rg, fragpos, newLightmap.y, albedo);
if (!hand) rtGI(Indirect_lighting, normal, blueNoise(gl_FragCoord.xy).rg, fragpos, newLightmap.y, albedo);
#endif
#ifndef AO_in_sunlight
@ -1218,7 +1133,7 @@ void main() {
//combine all light sources
vec3 FINAL_COLOR = Direct_lighting + Indirect_lighting;
vec3 FINAL_COLOR = Indirect_lighting + Direct_lighting;
#ifdef Variable_Penumbra_Shadows
FINAL_COLOR += SSS*DirectLightColor;

View File

@ -97,12 +97,12 @@ void main() {
vec4 TEXTURE = texture2D(texture, lmtexcoord.xy)*color;
#ifdef WEATHER
#ifdef WEATHER
gl_FragData[1].a = TEXTURE.a; // for bloomy rain
#endif
#endif
#ifndef WEATHER
gl_FragData[1].a = 0.0; // for bloomy rain
gl_FragData[1].a = pow(1.0-TEXTURE.a,2.0); // for bloomy rain
gl_FragData[0] = TEXTURE;
vec3 Albedo = toLinear(gl_FragData[0].rgb);

View File

@ -140,15 +140,6 @@ vec4 encode (vec3 n, vec2 lightmaps){
return vec4(encn,vec2(lightmaps.x,lightmaps.y));
}
#ifdef MC_NORMAL_MAP
vec3 applyBump(mat3 tbnMatrix, vec3 bump, float puddle_values){
float bumpmult = clamp(puddle_values,0.0,1.0);
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
return normalize(bump*tbnMatrix);
}
#endif
//encoding by jodie
float encodeVec2(vec2 a){
const vec2 constant1 = vec2( 1., 256.) / 65535.;
@ -159,6 +150,15 @@ float encodeVec2(float x,float y){
return encodeVec2(vec2(x,y));
}
#ifdef MC_NORMAL_MAP
vec3 applyBump(mat3 tbnMatrix, vec3 bump, float puddle_values){
float bumpmult = clamp(puddle_values,0.0,1.0);
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
return normalize(bump*tbnMatrix);
}
#endif
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
@ -419,11 +419,14 @@ void main() {
gl_FragData[1].a = 0.0;
#else
float bias = Texture_MipMap_Bias - blueNoise()*0.5;
////////////////////////////////
//////////////////////////////// NORMAL
////////////////////////////////
#ifdef WORLD
#ifdef MC_NORMAL_MAP
vec4 NormalTex = texture2D(normals, lmtexcoord.xy, bias).rgba;
NormalTex.xy = NormalTex.xy*2.0-1.0;
@ -439,12 +442,13 @@ void main() {
#endif
#endif
#endif
////////////////////////////////
//////////////////////////////// SPECULAR
////////////////////////////////
#ifdef WORLD
vec4 SpecularTex = texture2D(specular, lmtexcoord.xy, bias);
SpecularTex.r = max(SpecularTex.r, Puddle_shape);
@ -456,6 +460,7 @@ void main() {
#endif
gl_FragData[2] = SpecularTex;
#endif
if(EMISSIVE > 0) gl_FragData[2].a = 0.9;
@ -463,10 +468,9 @@ void main() {
//////////////////////////////// ALBEDO
////////////////////////////////
#ifdef WORLD
vec4 Albedo = texture2D(texture, lmtexcoord.xy, bias) * color;
// pain in my ass
#ifdef AEROCHROME_MODE
vec3 aerochrome_color = mix(vec3(1.0, 0.0, 0.0), vec3(0.715, 0.303, 0.631), AEROCHROME_PINKNESS);
float gray = dot(Albedo.rgb, vec3(0.2, 01.0, 0.07));
@ -527,9 +531,10 @@ void main() {
gl_FragData[0] = vec4(encodeVec2(Albedo.x,data1.x), encodeVec2(Albedo.y,data1.y), encodeVec2(Albedo.z,data1.z), encodeVec2(data1.w,Albedo.w));
gl_FragData[1].a = 0.0;
#endif
#endif
#ifdef WORLD
gl_FragData[5].x = 0;
#ifdef ENTITIES
@ -537,4 +542,5 @@ void main() {
#endif
gl_FragData[3] = vec4(FlatNormals * 0.5 + 0.5,VanillaAO);
#endif
}

View File

@ -151,12 +151,6 @@ void main() {
if(mc_Entity.x == 10005) EMISSIVE = 1;
#endif
#ifdef SPIDEREYES
// gl_Position.xy = gl_Position.xy * 0.9 + 0.9 * gl_Position.w - gl_Position.w;
if(gl_Color.a < 1.0 ) gl_Position = vec4(10,10,10,1);
EMISSIVE = 1;
#endif
lmtexcoord.xy = (gl_MultiTexCoord0).xy;
FlatNormals = normalize(gl_NormalMatrix * gl_Normal);

View File

@ -1,8 +1,60 @@
#version 120
// #define ENTITIES
// #define BLOCKENTITIES
// #define WORLD
#define SPIDEREYES
varying vec4 lmtexcoord;
varying vec4 color;
#include "gbuffers_all_solid.fsh"
uniform sampler2D texture;
//faster and actually more precise than pow 2.2
// vec3 toLinear(vec3 sRGB){
// return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
// }
// vec3 viewToWorld(vec3 viewPosition) {
// vec4 pos;
// pos.xyz = viewPosition;
// pos.w = 0.0;
// pos = gbufferModelViewInverse * pos;
// return pos.xyz;
// }
// vec3 worldToView(vec3 worldPos) {
// vec4 pos = vec4(worldPos, 0.0);
// pos = gbufferModelView * pos;
// return pos.xyz;
// }
vec4 encode (vec3 n, vec2 lightmaps){
n.xy = n.xy / dot(abs(n), vec3(1.0));
n.xy = n.z <= 0.0 ? (1.0 - abs(n.yx)) * sign(n.xy) : n.xy;
vec2 encn = clamp(n.xy * 0.5 + 0.5,-1.0,1.0);
return vec4(encn,vec2(lightmaps.x,lightmaps.y));
}
//encoding by jodie
float encodeVec2(vec2 a){
const vec2 constant1 = vec2( 1., 256.) / 65535.;
vec2 temp = floor( a * 255. );
return temp.x*constant1.x+temp.y*constant1.y;
}
float encodeVec2(float x,float y){
return encodeVec2(vec2(x,y));
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
/* DRAWBUFFERS:18 */
void main() {
vec3 albedo = texture2D(texture, lmtexcoord.xy).rgb * color.rgb;
vec4 data1 = clamp(encode(vec3(0.0), vec2(lmtexcoord.z,1)), 0.0, 1.0);
gl_FragData[0] = vec4(encodeVec2(albedo.r,data1.x), encodeVec2(albedo.g,data1.y), encodeVec2(albedo.b,data1.z), encodeVec2(data1.w,0.75));
gl_FragData[1].a = 0.9;
}

View File

@ -1,8 +1,54 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
// #define ENTITIES
// #define BLOCKENTITIES
// #define WORLD
#define SPIDEREYES
#include "lib/settings.glsl"
#include "/lib/res_params.glsl"
#include "gbuffers_all_solid.vsh"
/*
!! DO NOT REMOVE !!
This code is from Chocapic13' shaders
Read the terms of modification and sharing before changing something below please !
!! DO NOT REMOVE !!
*/
varying vec4 lmtexcoord;
varying vec4 color;
uniform vec2 texelSize;
uniform int framemod8;
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//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
gl_Position = ftransform();
lmtexcoord.xy = (gl_MultiTexCoord0).xy;
vec2 lmcoord = gl_MultiTexCoord1.xy/255.;
lmtexcoord.zw = lmcoord;
color = gl_Color;
if(gl_Color.a < 1.0 ) gl_Position = vec4(10,10,10,1);
#ifdef TAA_UPSCALING
gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w;
#endif
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
}

View File

@ -1,8 +1,28 @@
#version 120
// #define ENTITIES
// #define BLOCKENTITIES
// #define WORLD
#define SPIDEREYES
#include "gbuffers_all_solid.fsh"
varying vec4 color;
varying vec2 texcoord;
uniform sampler2D texture;
//faster and actually more precise than pow 2.2
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
/* DRAWBUFFERS:18 */
void main() {
vec3 albedo = (texture2D(texture, texcoord).rgb * color.rgb);
gl_FragData[0].rgb = albedo;
gl_FragData[1].a = 0.5;
}

View File

@ -1,8 +1,52 @@
#version 120
#extension GL_EXT_gpu_shader4 : enable
// #define ENTITIES
// #define BLOCKENTITIES
// #define WORLD
#define SPIDEREYES
#include "lib/settings.glsl"
#include "/lib/res_params.glsl"
#include "gbuffers_all_solid.vsh"
/*
!! DO NOT REMOVE !!
This code is from Chocapic13' shaders
Read the terms of modification and sharing before changing something below please !
!! DO NOT REMOVE !!
*/
varying vec4 lmtexcoord;
varying vec4 color;
varying vec2 texcoord;
uniform vec2 texelSize;
uniform int framemod8;
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//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
void main() {
gl_Position = ftransform();
// if(gl_Color.a < 1.0 ) gl_Position = vec4(10,10,10,1);
texcoord = (gl_MultiTexCoord0).xy;
color = gl_Color;
#ifdef TAA_UPSCALING
gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w;
#endif
#ifdef TAA
gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize;
#endif
}

View File

@ -13,8 +13,8 @@ vec3 DoAmbientLighting (vec3 SkyColor, vec3 TorchColor, vec2 Lightmap, float sky
TorchLight = exp(TorchLight * 30) - 1.0;
// vec3 SkyLight = max((SkyColor * 8./150./3.) * pow(Lightmap.y,3.0) , vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01)) ;
vec3 SkyLight = max((SkyColor * 8./150./3.) * pow(Lightmap.y,3.0),0.0) ;
vec3 SkyLight = max((SkyColor * 8./150./3.) * pow(Lightmap.y,3.0) , vec3(0.2,0.4,1.0) * (MIN_LIGHT_AMOUNT*0.01)) ;
// vec3 SkyLight = max((SkyColor * 8./150./3.) * pow(Lightmap.y,3.0),0.0) ;
return SkyLight * skyLightDir + TorchLight;

View File

@ -71,36 +71,33 @@ vec2 R2_samples_spec(int n){
vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){
vec3 clipPosition = toClipSpace3(position);
float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ? (-near -position.z) / dir.z : far*sqrt(3.);
float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ?
(-near -position.z) / dir.z : far*sqrt(3.);
vec3 direction = normalize(toClipSpace3(position+dir*rayLength)-clipPosition); //convert to clip space
direction.xy = normalize(direction.xy);
//get at which length the ray intersects with the edge of the screen
vec3 maxLengths = (step(0.,direction)-clipPosition) / direction;
float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z);
float mult = maxLengths.y;
vec3 stepv = direction * mult / quality*vec3(RENDER_SCALE,1.0) * dither;
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ;
vec3 stepv = direction * mult / quality*vec3(RENDER_SCALE,1.0);
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) + stepv*dither;
float minZ = clipPosition.z+stepv.z;
float maxZ = spos.z+stepv.z;
spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE;
float dist = 1.0 + clamp(position.z*position.z/50.0,0,2); // shrink sample size as distance increases
for (int i = 0; i <= int(quality); i++) {
float sp = texelFetch2D(depthtex1,ivec2(spos.xy/texelSize),0).r;
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ)) return vec3(spos.xy/RENDER_SCALE,sp);
float biasdist = clamp(position.z*position.z/50.0,1,2); // shrink sample size as distance increases
for(int i = 0; i < int(quality); i++){
spos += stepv;
//small bias
minZ = maxZ-(0.0001/dist)/ld(spos.z);
maxZ += stepv.z;
}
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0);
float currZ = linZ(spos.z);
if( sp < currZ) {
float dist = abs(sp-currZ)/currZ;
if (abs(dist) < biasdist*0.05) return vec3(spos.xy, invLinZ(sp))/vec3(RENDER_SCALE,1.0);
}
spos += stepv;
}
return vec3(1.1);
}

View File

@ -11,7 +11,7 @@ dynamicHandLight=true
program.composite4.enabled=TAA_UPSCALING
#Get the correct alpha value : S_A*(1-DST_A)+DST_A
blend.gbuffers_terrain = off
blend.gbuffers_textured= SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE
blend.gbuffers_armor_glint= SRC_ALPHA ZERO ONE_MINUS_DST_ALPHA ONE
blend.gbuffers_textured_lit= SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE
@ -19,6 +19,7 @@ blend.gbuffers_weather= SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE
blend.gbuffers_water = SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE
# SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE ZERO
# SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE_MINUS_DST_ALPHA ONE
blend.gbuffers_hand_water=SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE ZERO