mirror of
https://github.com/X0nk/Bliss-Shader.git
synced 2025-06-26 18:22:33 +08:00
smaller water fog tweaks. fix wrong normal usage in some parts of forward rendering
This commit is contained in:
@ -517,6 +517,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
|||||||
TangentNormal = NormalTex.xy;
|
TangentNormal = NormalTex.xy;
|
||||||
|
|
||||||
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
|
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
|
||||||
|
worldSpaceNormal = normalize(viewToWorld(normal).xyz);
|
||||||
|
|
||||||
// TangentNormal = clamp(TangentNormal + (blueNoise()*2.0-1.0)*0.005,-1.0,1.0);
|
// TangentNormal = clamp(TangentNormal + (blueNoise()*2.0-1.0)*0.005,-1.0,1.0);
|
||||||
float nameTagMask = 0.0;
|
float nameTagMask = 0.0;
|
||||||
@ -605,7 +606,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NETHER_SHADER
|
#ifdef NETHER_SHADER
|
||||||
Indirect_lighting = volumetricsFromTex(normalize(worldSpaceNormal), colortex4, 0).rgb / 1200.0 / 1.5;
|
Indirect_lighting = volumetricsFromTex(worldSpaceNormal, colortex4, 0).rgb / 1200.0 / 1.5;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef END_SHADER
|
#ifdef END_SHADER
|
||||||
@ -634,12 +635,12 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
|||||||
#ifdef IS_LPV_ENABLED
|
#ifdef IS_LPV_ENABLED
|
||||||
vec3 normalOffset = vec3(0.0);
|
vec3 normalOffset = vec3(0.0);
|
||||||
|
|
||||||
if (any(greaterThan(abs(worldSpaceNormal), vec3(1.0e-6))))
|
if (any(greaterThan(abs(viewToWorld(normalMat.xyz).xyz), vec3(1.0e-6))))
|
||||||
normalOffset = 0.5*worldSpaceNormal;
|
normalOffset = 0.5*worldSpaceNormal;
|
||||||
|
|
||||||
#if LPV_NORMAL_STRENGTH > 0
|
#if LPV_NORMAL_STRENGTH > 0
|
||||||
if (any(greaterThan(abs(normal), vec3(1.0e-6)))) {
|
if (any(greaterThan(abs(normal), vec3(1.0e-6)))) {
|
||||||
vec3 texNormalOffset = -normalOffset + viewToWorld(normal);
|
vec3 texNormalOffset = -normalOffset + worldSpaceNormal;
|
||||||
normalOffset = mix(normalOffset, texNormalOffset, (LPV_NORMAL_STRENGTH*0.01));
|
normalOffset = mix(normalOffset, texNormalOffset, (LPV_NORMAL_STRENGTH*0.01));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -653,7 +654,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
|||||||
|
|
||||||
vec4 flashLightSpecularData = vec4(0.0);
|
vec4 flashLightSpecularData = vec4(0.0);
|
||||||
#ifdef FLASHLIGHT
|
#ifdef FLASHLIGHT
|
||||||
Indirect_lighting += calculateFlashlight(FragCoord.xy*texelSize/RENDER_SCALE, viewPos, vec3(0.0), viewToWorld(normalize(normal)), flashLightSpecularData, false);
|
Indirect_lighting += calculateFlashlight(FragCoord.xy*texelSize/RENDER_SCALE, viewPos, vec3(0.0), worldSpaceNormal, flashLightSpecularData, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vec3 FinalColor = (Indirect_lighting + Direct_lighting) * Albedo;
|
vec3 FinalColor = (Indirect_lighting + Direct_lighting) * Albedo;
|
||||||
@ -708,7 +709,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
vec3 specularReflections = specularReflections(viewPos, normalize(feetPlayerPos), WsunVec, vec3(blueNoise(), vec2(interleaved_gradientNoise_temporal())), viewToWorld(normal), roughness, f0, Albedo, FinalColor*gl_FragData[0].a, DirectLightColor * Shadows, lightmap.y, isHand, reflectance, flashLightSpecularData);
|
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, reflectance, flashLightSpecularData);
|
||||||
|
|
||||||
gl_FragData[0].a = gl_FragData[0].a + (1.0-gl_FragData[0].a) * reflectance;
|
gl_FragData[0].a = gl_FragData[0].a + (1.0-gl_FragData[0].a) * reflectance;
|
||||||
|
|
||||||
@ -748,7 +749,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
|||||||
if(gl_FragCoord.x*texelSize.x < 0.47) gl_FragData[0] = vec4(0.0);
|
if(gl_FragCoord.x*texelSize.x < 0.47) gl_FragData[0] = vec4(0.0);
|
||||||
#endif
|
#endif
|
||||||
#if DEBUG_VIEW == debug_NORMALS
|
#if DEBUG_VIEW == debug_NORMALS
|
||||||
gl_FragData[0].rgb = viewToWorld(normalize(normal.xyz)) * 0.1;
|
gl_FragData[0].rgb = worldSpaceNormal * 0.1;
|
||||||
gl_FragData[0].a = 1;
|
gl_FragData[0].a = 1;
|
||||||
#endif
|
#endif
|
||||||
#if DEBUG_VIEW == debug_INDIRECT
|
#if DEBUG_VIEW == debug_INDIRECT
|
||||||
|
@ -286,7 +286,6 @@ vec4 waterVolumetrics(vec3 rayStart, vec3 rayEnd, float rayLength, vec2 dither,
|
|||||||
float phase = 0.0;
|
float phase = 0.0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// float thing = -normalize(dVWorld + (cameraPosition - vec3(cameraPosition.x, waterEnteredAltitude-1.0,cameraPosition.z))).y;
|
|
||||||
float thing = -normalize(dVWorld).y;
|
float thing = -normalize(dVWorld).y;
|
||||||
thing = clamp(thing + 0.333,0.0,1.0);
|
thing = clamp(thing + 0.333,0.0,1.0);
|
||||||
thing = pow(1.0-pow(1.0-thing,2.0),2.0);
|
thing = pow(1.0-pow(1.0-thing,2.0),2.0);
|
||||||
|
@ -109,35 +109,32 @@ float linearizeDepthFast(const in float depth, const in float near, const in flo
|
|||||||
#include "/lib/volumetricClouds.glsl"
|
#include "/lib/volumetricClouds.glsl"
|
||||||
#include "/lib/climate_settings.glsl"
|
#include "/lib/climate_settings.glsl"
|
||||||
#include "/lib/overworld_fog.glsl"
|
#include "/lib/overworld_fog.glsl"
|
||||||
|
|
||||||
// float fogPhase(float lightPoint){
|
|
||||||
// float linear = 1.0 - clamp(lightPoint*0.5+0.5,0.0,1.0);
|
|
||||||
// float linear2 = 1.0 - clamp(lightPoint,0.0,1.0);
|
|
||||||
|
|
||||||
// float exponential = exp2(pow(linear,0.3) * -15.0 ) * 1.5;
|
|
||||||
// exponential += sqrt(exp2(sqrt(linear) * -12.5));
|
|
||||||
|
|
||||||
// return exponential;
|
|
||||||
// }
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NETHER_SHADER
|
#ifdef NETHER_SHADER
|
||||||
uniform sampler2D colortex4;
|
uniform sampler2D colortex4;
|
||||||
#include "/lib/nether_fog.glsl"
|
#include "/lib/nether_fog.glsl"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef END_SHADER
|
#ifdef END_SHADER
|
||||||
uniform sampler2D colortex4;
|
uniform sampler2D colortex4;
|
||||||
#include "/lib/end_fog.glsl"
|
#include "/lib/end_fog.glsl"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.)
|
#define fsign(a) (clamp((a)*1e35,0.,1.)*2.-1.)
|
||||||
|
|
||||||
|
vec4 blueNoise(vec2 coord){
|
||||||
|
return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
float blueNoise(){
|
||||||
|
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a+ 1.0/1.6180339887 * frameCounter );
|
||||||
|
}
|
||||||
|
|
||||||
float interleaved_gradientNoise(){
|
float interleaved_gradientNoise(){
|
||||||
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+ 1.0/1.6180339887 * frameCounter);
|
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*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 );
|
|
||||||
}
|
|
||||||
float R2_dither(){
|
float R2_dither(){
|
||||||
#ifdef TAA
|
#ifdef TAA
|
||||||
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
|
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
|
||||||
@ -148,53 +145,6 @@ float R2_dither(){
|
|||||||
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
|
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void waterVolumetrics_notoverworld(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient){
|
|
||||||
inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value
|
|
||||||
|
|
||||||
int spCount = rayMarchSampleCount;
|
|
||||||
vec3 start = toShadowSpaceProjected(rayStart);
|
|
||||||
vec3 end = toShadowSpaceProjected(rayEnd);
|
|
||||||
vec3 dV = (end-start);
|
|
||||||
//limit ray length at 32 blocks for performance and reducing integration error
|
|
||||||
//you can't see above this anyway
|
|
||||||
float maxZ = min(rayLength,12.0)/(1e-8+rayLength);
|
|
||||||
dV *= maxZ;
|
|
||||||
|
|
||||||
|
|
||||||
rayLength *= maxZ;
|
|
||||||
|
|
||||||
float dY = normalize(mat3(gbufferModelViewInverse) * rayEnd).y * rayLength;
|
|
||||||
estEndDepth *= maxZ;
|
|
||||||
estSunDepth *= maxZ;
|
|
||||||
|
|
||||||
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
|
|
||||||
vec3 dVWorld = (wpos-gbufferModelViewInverse[3].xyz);
|
|
||||||
|
|
||||||
vec3 absorbance = vec3(1.0);
|
|
||||||
vec3 vL = vec3(0.0);
|
|
||||||
|
|
||||||
float expFactor = 11.0;
|
|
||||||
for (int i=0;i<spCount;i++) {
|
|
||||||
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
|
|
||||||
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
|
|
||||||
vec3 spPos = start.xyz + dV*d;
|
|
||||||
|
|
||||||
vec3 progressW = start.xyz+cameraPosition+dVWorld;
|
|
||||||
|
|
||||||
vec3 ambientMul = exp(-max(estEndDepth * d,0.0) * waterCoefs );
|
|
||||||
vec3 Indirectlight = ambientMul*ambient;
|
|
||||||
|
|
||||||
vec3 light = Indirectlight * scatterCoef;
|
|
||||||
|
|
||||||
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs * absorbance;
|
|
||||||
absorbance *= exp(-dd * rayLength * waterCoefs);
|
|
||||||
}
|
|
||||||
inColor += vL;
|
|
||||||
|
|
||||||
}
|
|
||||||
vec4 blueNoise(vec2 coord){
|
|
||||||
return texelFetch2D(colortex6, ivec2(coord)%512 , 0) ;
|
|
||||||
}
|
|
||||||
vec2 R2_samples(int n){
|
vec2 R2_samples(int n){
|
||||||
vec2 alpha = vec2(0.75487765, 0.56984026);
|
vec2 alpha = vec2(0.75487765, 0.56984026);
|
||||||
return fract(alpha * n);
|
return fract(alpha * n);
|
||||||
@ -228,22 +178,16 @@ vec4 waterVolumetrics( vec3 rayStart, vec3 rayEnd, float estEndDepth, float estS
|
|||||||
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
|
vec3 wpos = mat3(gbufferModelViewInverse) * rayStart + gbufferModelViewInverse[3].xyz;
|
||||||
vec3 dVWorld = (wpos - gbufferModelViewInverse[3].xyz);
|
vec3 dVWorld = (wpos - gbufferModelViewInverse[3].xyz);
|
||||||
|
|
||||||
// vec3 dVWorld = -mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ;
|
|
||||||
|
|
||||||
// vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef OVERWORLD_SHADER
|
#ifdef OVERWORLD_SHADER
|
||||||
float phase = fogPhase(VdotL) * 5.0;
|
float phase = fogPhase(VdotL) * 5.0;
|
||||||
#else
|
#else
|
||||||
float phase = 1.0;
|
float phase = 1.0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vec3 absorbance = vec3(1.0);
|
vec3 absorbance = vec3(1.0);
|
||||||
vec3 vL = vec3(0.0);
|
vec3 vL = vec3(0.0);
|
||||||
|
|
||||||
// ambient = max(ambient * (normalize(wpos).y*0.3+0.7),0.0);
|
|
||||||
float expFactor = 11.0;
|
float expFactor = 11.0;
|
||||||
|
|
||||||
vec3 sh = vec3(1.0);
|
vec3 sh = vec3(1.0);
|
||||||
|
|
||||||
// do this outside raymarch loop, masking the water surface is good enough
|
// do this outside raymarch loop, masking the water surface is good enough
|
||||||
@ -251,6 +195,11 @@ vec4 waterVolumetrics( vec3 rayStart, vec3 rayEnd, float estEndDepth, float estS
|
|||||||
sh *= GetCloudShadow(wpos+cameraPosition, WsunVec);
|
sh *= GetCloudShadow(wpos+cameraPosition, WsunVec);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
float thing = -normalize(dVWorld).y;
|
||||||
|
thing = clamp(thing - 0.333,0.0,1.0);
|
||||||
|
thing = pow(1.0-pow(1.0-thing,2.0),2.0);
|
||||||
|
thing *= 15.0;
|
||||||
|
|
||||||
for (int i=0;i<spCount;i++) {
|
for (int i=0;i<spCount;i++) {
|
||||||
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
|
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
|
||||||
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
|
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
|
||||||
@ -288,8 +237,7 @@ vec4 waterVolumetrics( vec3 rayStart, vec3 rayEnd, float estEndDepth, float estS
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
vec3 sunAbsorbance = exp(-waterCoefs * estSunDepth * d);
|
vec3 sunAbsorbance = exp(-waterCoefs * estSunDepth * d);
|
||||||
vec3 ambientAbsorbance = exp(-waterCoefs * estEndDepth * d);
|
vec3 ambientAbsorbance = exp(-waterCoefs * (estEndDepth * d + thing));
|
||||||
// vec3 WaterAbsorbance = exp(-waterCoefs * rayLength * d);
|
|
||||||
|
|
||||||
vec3 Directlight = lightSource * sh * phase * sunAbsorbance;
|
vec3 Directlight = lightSource * sh * phase * sunAbsorbance;
|
||||||
vec3 Indirectlight = ambient * ambientAbsorbance;
|
vec3 Indirectlight = ambient * ambientAbsorbance;
|
||||||
@ -303,48 +251,7 @@ vec4 waterVolumetrics( vec3 rayStart, vec3 rayEnd, float estEndDepth, float estS
|
|||||||
|
|
||||||
return vec4(vL, dot(absorbance,vec3(0.335)));
|
return vec4(vL, dot(absorbance,vec3(0.335)));
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
void waterVolumetrics(inout vec3 inColor, vec3 rayStart, vec3 rayEnd, float estEndDepth, float estSunDepth, float rayLength, float dither, vec3 waterCoefs, vec3 scatterCoef, vec3 ambient, vec3 lightSource, float VdotL){
|
|
||||||
inColor *= exp(-rayLength * waterCoefs); //No need to take the integrated value
|
|
||||||
int spCount = rayMarchSampleCount;
|
|
||||||
vec3 start = toShadowSpaceProjected(rayStart);
|
|
||||||
vec3 end = toShadowSpaceProjected(rayEnd);
|
|
||||||
vec3 dV = (end-start);
|
|
||||||
//limit ray length at 32 blocks for performance and reducing integration error
|
|
||||||
//you can't see above this anyway
|
|
||||||
float maxZ = min(rayLength,32.0)/(1e-8+rayLength);
|
|
||||||
dV *= maxZ;
|
|
||||||
vec3 dVWorld = -mat3(gbufferModelViewInverse) * (rayEnd - rayStart) * maxZ;
|
|
||||||
rayLength *= maxZ;
|
|
||||||
estEndDepth *= maxZ;
|
|
||||||
estSunDepth *= maxZ;
|
|
||||||
vec3 absorbance = vec3(1.0);
|
|
||||||
vec3 vL = vec3(0.0);
|
|
||||||
float phase = phaseg(VdotL, Dirt_Mie_Phase);
|
|
||||||
float expFactor = 11.0;
|
|
||||||
vec3 progressW = gbufferModelViewInverse[3].xyz+cameraPosition;
|
|
||||||
for (int i=0;i<spCount;i++) {
|
|
||||||
float d = (pow(expFactor, float(i+dither)/float(spCount))/expFactor - 1.0/expFactor)/(1-1.0/expFactor);
|
|
||||||
float dd = pow(expFactor, float(i+dither)/float(spCount)) * log(expFactor) / float(spCount)/(expFactor-1.0);
|
|
||||||
vec3 spPos = start.xyz + dV*d;
|
|
||||||
progressW = gbufferModelViewInverse[3].xyz+cameraPosition + d*dVWorld;
|
|
||||||
//project into biased shadowmap space
|
|
||||||
float distortFactor = calcDistort(spPos.xy);
|
|
||||||
vec3 pos = vec3(spPos.xy*distortFactor, spPos.z);
|
|
||||||
float sh = 1.0;
|
|
||||||
if (abs(pos.x) < 1.0-0.5/2048. && abs(pos.y) < 1.0-0.5/2048){
|
|
||||||
pos = pos*vec3(0.5,0.5,0.5/6.0)+0.5;
|
|
||||||
sh = shadow2D( shadow, pos).x;
|
|
||||||
}
|
|
||||||
vec3 ambientMul = exp(-estEndDepth * d * waterCoefs * 1.1);
|
|
||||||
vec3 sunMul = exp(-estSunDepth * d * waterCoefs);
|
|
||||||
vec3 light = (sh * lightSource*8./150./3.0 * phase * sunMul + ambientMul * ambient)*scatterCoef;
|
|
||||||
vL += (light - light * exp(-waterCoefs * dd * rayLength)) / waterCoefs *absorbance;
|
|
||||||
absorbance *= exp(-dd * rayLength * waterCoefs);
|
|
||||||
}
|
|
||||||
inColor += vL;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
vec2 decodeVec2(float a){
|
vec2 decodeVec2(float a){
|
||||||
const vec2 constant1 = 65535. / vec2( 256., 65536.);
|
const vec2 constant1 = 65535. / vec2( 256., 65536.);
|
||||||
const float constant2 = 256. / 255.;
|
const float constant2 = 256. / 255.;
|
||||||
|
@ -162,7 +162,7 @@ vec4 screenSpaceReflections(
|
|||||||
vec4 reflection = vec4(0.0);
|
vec4 reflection = vec4(0.0);
|
||||||
|
|
||||||
float reflectionLength = 0.0;
|
float reflectionLength = 0.0;
|
||||||
float quality = mix(10.0f, 30.0f, fresnel);
|
float quality = 30.0f;//mix(10.0f, 30.0f, fresnel);
|
||||||
|
|
||||||
vec3 raytracePos = rayTraceSpeculars(reflectedVector, viewPos, noise, quality, isHand, reflectionLength, fresnel);
|
vec3 raytracePos = rayTraceSpeculars(reflectedVector, viewPos, noise, quality, isHand, reflectionLength, fresnel);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user