mirror of
https://github.com/X0nk/Bliss-Shader.git
synced 2026-10-10 05:03:04 +08:00
add SSRT shadows for handheld lights. improve sudden position change when sneaking with handheld lights. make handheld light visible range feel more like what its set to.
This commit is contained in:
@@ -697,12 +697,12 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
vec3 offHandCol = vec3(0.0);
|
||||
|
||||
#if HANDHELD_LIGHTSOURCE_MODE > 0
|
||||
Indirect_lighting += doHandHeldLight(
|
||||
doHandHeldLight(
|
||||
viewPos, worldSpaceNormal
|
||||
#if defined HANDHELD_LIGHTSOURCE_SPECULAR && defined FORWARD_SPECULAR
|
||||
,mainHandPos, mainHandCol, offHandPos, offHandCol
|
||||
#endif
|
||||
,mainHandPos, mainHandCol, offHandPos, offHandCol
|
||||
);
|
||||
|
||||
Indirect_lighting += mainHandCol + offHandCol;
|
||||
#endif
|
||||
|
||||
#if defined LIGHTNING_FLASH
|
||||
@@ -760,7 +760,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
float Shadows = 0.0;
|
||||
#endif
|
||||
|
||||
vec3 specularReflections = specularReflections(viewPos, normalize(feetPlayerPos), WsunVec, vec3(blueNoise(), vec2(interleaved_gradientNoise_temporal())), worldSpaceNormal, roughness, f0, Albedo, FinalColor*gl_FragData[0].a, DirectLightColor * Shadows, lightmap.y, isHand, isWater, reflectance, mainHandPos, mainHandCol, offHandPos, offHandCol);
|
||||
vec3 specularReflections = specularReflections(viewPos, normalize(feetPlayerPos), WsunVec, vec3(blueNoise(), vec2(interleaved_gradientNoise_temporal())), worldSpaceNormal, roughness, f0, Albedo, FinalColor*gl_FragData[0].a, DirectLightColor * Shadows, lightmap.y, isHand, isWater, reflectance, normalize(mainHandPos), mainHandCol, normalize(offHandPos), offHandCol);
|
||||
|
||||
gl_FragData[0].a = gl_FragData[0].a + (1.0-gl_FragData[0].a) * reflectance;
|
||||
|
||||
|
||||
@@ -389,7 +389,7 @@ vec2 SSRT_Shadows(vec3 viewPos, bool depthCheck, vec3 lightDir, float noise, boo
|
||||
float dist = abs(linearSampledDepth - linearCurrentPos) / linearCurrentPos;
|
||||
|
||||
// if (dist < 0.035){
|
||||
if (dist < 0.035/(1.0+linearCurrentPos) && (sampleDepth < newPos.z )) shadows = 0.0;
|
||||
if (dist < 0.035/(1.0+linearCurrentPos)) shadows = 0.0;
|
||||
|
||||
// if (dist < 0.3/(1.0+linearCurrentPos)) SSS += distanceScale2;
|
||||
if (dist < SSSdistanceScale) SSS += distanceScale2;
|
||||
@@ -400,64 +400,49 @@ vec2 SSRT_Shadows(vec3 viewPos, bool depthCheck, vec3 lightDir, float noise, boo
|
||||
}
|
||||
return vec2(shadows, SSS / samples );
|
||||
}
|
||||
#ifdef HANDHELD_LIGHTSOURCE_SSRT_SHADOWS
|
||||
float handHeldLight_SSRT_Shadows(vec3 viewPos, vec3 shadowHandPos, float noise){
|
||||
|
||||
float SSRT_FlashLight_Shadows(vec3 viewPos, bool depthCheck, vec3 lightDir, float noise){
|
||||
|
||||
vec3 shadowHandViewPos = mat3(gbufferModelView) * shadowHandPos;
|
||||
// funnt little thing to exaggerate the effec to shadows
|
||||
shadowHandViewPos.xy += (shadowHandViewPos.xy / (1.0+length(shadowHandPos)))*0.5;
|
||||
vec3 lightDir = -shadowHandViewPos;
|
||||
|
||||
float steps = 16.0;
|
||||
float Shadow = 1.0;
|
||||
float SSS = 0.0;
|
||||
// isSSS = true;
|
||||
float _near = near;
|
||||
float _far = far*4.0;
|
||||
|
||||
float _near = near; float _far = far*4.0;
|
||||
|
||||
if (depthCheck) {
|
||||
_near = dhNearPlane;
|
||||
_far = dhFarPlane;
|
||||
}
|
||||
|
||||
|
||||
vec3 clipPosition = toClipSpace3_DH(viewPos, depthCheck);
|
||||
vec3 position = toClipSpace3_DH(viewPos, false);
|
||||
//prevents the ray from going behind the camera
|
||||
float rayLength = ((viewPos.z + lightDir.z * _far*sqrt(3.)) > -_near) ?
|
||||
(-_near -viewPos.z) / lightDir.z : _far*sqrt(3.);
|
||||
|
||||
vec3 direction = toClipSpace3_DH(viewPos + lightDir*rayLength, depthCheck) - clipPosition; //convert to clip space
|
||||
|
||||
direction.xyz = direction.xyz / max(abs(direction.x)/0.0005, abs(direction.y)/0.0005); //fixed step size
|
||||
|
||||
float Stepmult = 6.0;
|
||||
|
||||
vec3 rayDir = direction * Stepmult * vec3(RENDER_SCALE,1.0);
|
||||
vec3 screenPos = clipPosition * vec3(RENDER_SCALE,1.0) + rayDir*noise;
|
||||
|
||||
|
||||
for (int i = 0; i < int(steps); i++) {
|
||||
|
||||
#ifdef USING_LOD_MOD
|
||||
float samplePos = 0.0;
|
||||
if(depthCheck){
|
||||
samplePos = texture(LOD_DEPTHTEX1, screenPos.xy).x;
|
||||
}else{
|
||||
samplePos = texture(depthtex2, screenPos.xy).x;
|
||||
}
|
||||
#else
|
||||
float samplePos = texture(depthtex2, screenPos.xy).x;
|
||||
#endif
|
||||
|
||||
if(samplePos < screenPos.z){// && (samplePos <= max(minZ,maxZ) && samplePos >= min(minZ,maxZ))){
|
||||
// vec2 linearZ = vec2(swapperlinZ(screenPos.z, _near, _far), swapperlinZ(samplePos, _near, _far));
|
||||
// float calcthreshold = abs(linearZ.x - linearZ.y) / linearZ.x;
|
||||
|
||||
// if (calcthreshold < 0.035)
|
||||
Shadow = 0.0;
|
||||
}
|
||||
|
||||
screenPos += rayDir;
|
||||
vec3 direction = toClipSpace3_DH(viewPos + lightDir*rayLength, false) - position;
|
||||
|
||||
if(firstPersonCamera){
|
||||
direction *= 0.001;
|
||||
}else{
|
||||
direction.xyz = direction.xyz / max(abs(direction.x)/0.0005, abs(direction.y)/0.0005); //fixed step size
|
||||
direction *= 12.0;
|
||||
}
|
||||
|
||||
return Shadow;
|
||||
position.xy *= RENDER_SCALE;
|
||||
direction.xy *= RENDER_SCALE;
|
||||
|
||||
vec3 newPos = position + direction*noise;
|
||||
newPos += direction*0.3;
|
||||
for (int i = 0; i < int(steps); i++) {
|
||||
|
||||
float samplePos = texture(depthtex2, newPos.xy).x;
|
||||
|
||||
if(samplePos < newPos.z) return 0.0;
|
||||
|
||||
newPos += direction;
|
||||
}
|
||||
|
||||
return 1.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void Emission(
|
||||
inout vec3 Lighting,
|
||||
@@ -1257,16 +1242,32 @@ void main() {
|
||||
vec3 offHandCol = vec3(0.0);
|
||||
|
||||
#if HANDHELD_LIGHTSOURCE_MODE > 0
|
||||
// float flashlightshadows = SSRT_FlashLight_Shadows(shiftedViewPos, isDHrange, normalize(shiftedPlayerPos), interleaved_gradientNoise_temporal());
|
||||
vec3 handheldViewPos = viewPos;
|
||||
if(hand) handheldViewPos.z += 0.7;
|
||||
|
||||
Indirect_lighting += doHandHeldLight(
|
||||
doHandHeldLight(
|
||||
handheldViewPos, slopednormal
|
||||
#if defined HANDHELD_LIGHTSOURCE_SPECULAR && defined DEFERRED_SPECULAR
|
||||
,mainHandPos, mainHandCol, offHandPos, offHandCol
|
||||
#endif
|
||||
,mainHandPos, mainHandCol, offHandPos, offHandCol
|
||||
);
|
||||
|
||||
#ifdef HANDHELD_LIGHTSOURCE_SSRT_SHADOWS
|
||||
// make sure not to calculate ssrt shadows if there is no light being held.
|
||||
if(!hand && (heldBlockLightValue > 0 || heldBlockLightValue2 > 0)){
|
||||
// whichever held light is brighter gets the shadows
|
||||
vec3 shadowHandPos = heldBlockLightValue > heldBlockLightValue2 ? mainHandPos : offHandPos;
|
||||
|
||||
float handHeldLightShadow = handHeldLight_SSRT_Shadows(viewPos, shadowHandPos, ig_noise);
|
||||
|
||||
// whichever held light is brighter gets the shadows 2x
|
||||
if(heldBlockLightValue < heldBlockLightValue2){
|
||||
offHandCol *= handHeldLightShadow;
|
||||
}else{
|
||||
mainHandCol *= handHeldLightShadow;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Indirect_lighting += mainHandCol + offHandCol;
|
||||
#endif
|
||||
|
||||
#if defined LIGHTNING_FLASH
|
||||
|
||||
@@ -209,6 +209,7 @@ screen.Ambient_light = Ambient Light
|
||||
option.HANDHELD_LIGHTSOURCE_R = Light Color R
|
||||
option.HANDHELD_LIGHTSOURCE_G = Light Color G
|
||||
option.HANDHELD_LIGHTSOURCE_B = Light Color B
|
||||
option.HANDHELD_LIGHTSOURCE_SSRT_SHADOWS = Shadows from Handheld Light
|
||||
|
||||
option.FLASHLIGHT_BOUNCED_INDIRECT = (Flashlight) Bounced light §c⚠ CURRENTLY BROKEN§r
|
||||
option.FLASHLIGHT_FOG_ILLUMINATION = (Flashlight) Fog illumination §c⚠ CURRENTLY BROKEN§r
|
||||
@@ -217,7 +218,7 @@ screen.Ambient_light = Ambient Light
|
||||
option.FLASHLIGHT_BRIGHTNESS_FALLOFF_MULT = (Flashlight) Range Falloff Multiplier
|
||||
|
||||
###################################################### ↑↑↑ THIS SUBMENU'S DESCRIPTIONS
|
||||
|
||||
|
||||
screen.Ambient_light.comment = Configure settings related to the lighting in shaded places
|
||||
option.AO_Strength.comment = Configure the strength of the ambient occlusion created by SSAO, GTAO, and SSRT. §bⓘ What is this?§r ambient occlusion is the small soft shadows in corners and such.
|
||||
option.GI_Strength.comment = Configure the strength of the global illumination created by SSRT. §bⓘ What is this?§r global illumination in this scenario specifically is the light bouncing off a surface and onto some other area.
|
||||
|
||||
@@ -91,8 +91,10 @@ vec3 doIndirectLighting(
|
||||
// uniform int heldItemId;
|
||||
// uniform int heldItemId2;
|
||||
// uniform float centerDepthSmooth;
|
||||
uniform vec3 eyePosition;
|
||||
// uniform vec3 eyePosition;
|
||||
uniform vec3 relativeEyePosition;
|
||||
uniform vec3 playerLookVector;
|
||||
uniform bool firstPersonCamera;
|
||||
|
||||
#if defined VIVECRAFT
|
||||
uniform bool vivecraftIsVR;
|
||||
@@ -149,7 +151,7 @@ void calculateFinishedPointLight(
|
||||
handPos = mat3(gbufferModelViewInverse) * (viewPos + handOffset) + gbufferModelViewInverse[3].xyz;
|
||||
|
||||
// make sure the position is centered on the player, not the camera.
|
||||
handPos += cameraPosition - eyePosition;
|
||||
if(!firstPersonCamera) handPos += relativeEyePosition;
|
||||
|
||||
#if HANDHELD_LIGHTSOURCE_MODE > 1
|
||||
/// previous frame data to lag the light behind to seem handheld.
|
||||
@@ -177,7 +179,7 @@ void calculateFinishedPointLight(
|
||||
#endif
|
||||
|
||||
// combine ndotl, attentuation, color, and pass it on.
|
||||
lighting *= createHandheldPointlight(handPos, normal, max(lightRange,1e-6));
|
||||
lighting *= createHandheldPointlight(handPos, normal, max(lightRange + 2,1e-6));
|
||||
|
||||
#if HANDHELD_LIGHTSOURCE_MODE > 1
|
||||
/// previous frame data to lag the light behind to seem handheld.
|
||||
@@ -214,31 +216,16 @@ void calculateFinishedPointLight(
|
||||
}
|
||||
}
|
||||
|
||||
vec3 doHandHeldLight(
|
||||
void doHandHeldLight(
|
||||
in vec3 viewPos, in vec3 normal
|
||||
#if defined HANDHELD_LIGHTSOURCE_SPECULAR && (defined DEFERRED_SPECULAR || defined FORWARD_SPECULAR)
|
||||
,out vec3 passMainHandPos, out vec3 passMainHandCol, out vec3 passOffHandPos, out vec3 passOffHandCol
|
||||
#endif
|
||||
){
|
||||
|
||||
vec3 mainHandLight = vec3(0.0);
|
||||
vec3 mainHandPos = vec3(0.0);
|
||||
vec3 offHandLight = vec3(0.0);
|
||||
vec3 offHandPos = vec3(0.0);
|
||||
,inout vec3 passMainHandPos, inout vec3 passMainHandCol, inout vec3 passOffHandPos, inout vec3 passOffHandCol
|
||||
){
|
||||
|
||||
#if HANDHELD_LIGHTSOURCE_MODE == 3
|
||||
calculateFinishedPointLight(viewPos, normal, 16.0, heldItemId, vec3(-0.25, 0.1-playerLookVector.y*0.2, 0.1), mainHandPos, mainHandLight);
|
||||
calculateFinishedPointLight(viewPos, normal, 16.0, heldItemId, vec3(-0.25, 0.1-playerLookVector.y*0.2, 0.1), passMainHandPos, passMainHandCol);
|
||||
#else
|
||||
calculateFinishedPointLight(viewPos, normal, float(heldBlockLightValue), heldItemId, vec3(-0.25, 0.1-playerLookVector.y*0.2, 0.1), mainHandPos, mainHandLight);
|
||||
calculateFinishedPointLight(viewPos, normal, float(heldBlockLightValue2), heldItemId2, vec3( 0.25, 0.1-playerLookVector.y*0.2, 0.1), offHandPos, offHandLight);
|
||||
calculateFinishedPointLight(viewPos, normal, float(heldBlockLightValue), heldItemId, vec3(-0.25, 0.1-playerLookVector.y*0.2, 0.1), passMainHandPos, passMainHandCol);
|
||||
calculateFinishedPointLight(viewPos, normal, float(heldBlockLightValue2), heldItemId2, vec3( 0.25, 0.1-playerLookVector.y*0.2, 0.1), passOffHandPos, passOffHandCol);
|
||||
#endif
|
||||
|
||||
#if defined HANDHELD_LIGHTSOURCE_SPECULAR && (defined DEFERRED_SPECULAR || defined FORWARD_SPECULAR)
|
||||
passMainHandCol = mainHandLight;
|
||||
passMainHandPos = normalize(mainHandPos);
|
||||
passOffHandCol = offHandLight;
|
||||
passOffHandPos = normalize(offHandPos);
|
||||
#endif
|
||||
|
||||
return mainHandLight + offHandLight;
|
||||
}
|
||||
@@ -96,6 +96,7 @@
|
||||
#define HANDHELD_LIGHTSOURCE_G 0.5 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
|
||||
#define HANDHELD_LIGHTSOURCE_B 0.25 // [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.0]
|
||||
#define HANDHELD_LIGHTSOURCE_SPECULAR
|
||||
#define HANDHELD_LIGHTSOURCE_SSRT_SHADOWS
|
||||
|
||||
// #define FLASHLIGHT_BOUNCED_INDIRECT
|
||||
// #define FLASHLIGHT_FOG_ILLUMINATION
|
||||
@@ -901,4 +902,6 @@
|
||||
#ifdef TERRIBLE_SSR_LOD_FALLBACK
|
||||
#endif
|
||||
#ifdef HANDHELD_LIGHTSOURCE_SPECULAR
|
||||
#endif
|
||||
#ifdef HANDHELD_LIGHTSOURCE_SSRT_SHADOWS
|
||||
#endif
|
||||
@@ -207,7 +207,7 @@ screen = \
|
||||
screen.Ambient_Colors = MINIMUM_OUTDOOR_LIGHT MINIMUM_INDOOR_LIGHT ambient_brightness <empty> AmbientLight_R AmbientLight_G AmbientLight_B
|
||||
|
||||
screen.HANDHELD_LIGHTSOURCE_SETTINGS.columns=1
|
||||
screen.HANDHELD_LIGHTSOURCE_SETTINGS = HANDHELD_LIGHTSOURCE_RANGE HANDHELD_LIGHTSOURCE_SPECULAR <empty> HANDHELD_LIGHTSOURCE_R HANDHELD_LIGHTSOURCE_G HANDHELD_LIGHTSOURCE_B <empty> FLASHLIGHT_BOUNCED_INDIRECT FLASHLIGHT_FOG_ILLUMINATION FLASHLIGHT_BRIGHTNESS_MULT FLASHLIGHT_SIZE FLASHLIGHT_BRIGHTNESS_FALLOFF_MULT
|
||||
screen.HANDHELD_LIGHTSOURCE_SETTINGS = HANDHELD_LIGHTSOURCE_RANGE HANDHELD_LIGHTSOURCE_SPECULAR HANDHELD_LIGHTSOURCE_SSRT_SHADOWS <empty> HANDHELD_LIGHTSOURCE_R HANDHELD_LIGHTSOURCE_G HANDHELD_LIGHTSOURCE_B <empty> FLASHLIGHT_BOUNCED_INDIRECT FLASHLIGHT_FOG_ILLUMINATION FLASHLIGHT_BRIGHTNESS_MULT FLASHLIGHT_SIZE FLASHLIGHT_BRIGHTNESS_FALLOFF_MULT
|
||||
|
||||
######## RESOURCE PACK SUPPORT
|
||||
profile.labPBR = EMISSIVE_TYPE=3 SSS_TYPE=3 DEFERRED_SPECULAR:true
|
||||
|
||||
Reference in New Issue
Block a user