mirror of
https://github.com/X0nk/Bliss-Shader.git
synced 2025-06-22 00:37:35 +08:00
tweak indirect SSS to be a little bright like it used to be. Tweak sampling for shadow filtering, ssao, rtao, ssgi, and specular reflections.
This commit is contained in:
@ -34,40 +34,46 @@ mat4 BuildTranslationMatrix(const in vec3 delta) {
|
||||
vec4(delta, 1.0));
|
||||
}
|
||||
|
||||
|
||||
vec3 LightDir = vec3(0.0, 1.0, 0.0);
|
||||
|
||||
// vec3 LightDir = vec3(sin(frameTimeCounter*10), 0.2, -cos(frameTimeCounter*10));
|
||||
uniform vec3 CamPos;
|
||||
|
||||
// vec3 LightDir = vec3(1.0, 0.5, 1.0);
|
||||
|
||||
float rate = frameTimeCounter;
|
||||
vec3 LightDir = vec3(sin(rate), 0.3, cos(rate));
|
||||
// vec3 LightDir = vec3(cos(rate),sin(rate),cos(rate));
|
||||
|
||||
const float shadowIntervalSize = 2.0f;
|
||||
vec3 GetShadowIntervalOffset() {
|
||||
return fract(CamPos / shadowIntervalSize) * shadowIntervalSize - vec3(3,0,1);
|
||||
}
|
||||
|
||||
mat4 BuildShadowViewMatrix(const in vec3 localLightDir) {
|
||||
//#ifndef WORLD_END
|
||||
// return shadowModelView;
|
||||
//#else
|
||||
const vec3 worldUp = vec3(0, 0, -1);
|
||||
const vec3 worldUp = vec3(1, 0, 0);
|
||||
|
||||
vec3 zaxis = localLightDir;
|
||||
vec3 xaxis = normalize(cross(worldUp, zaxis));
|
||||
vec3 yaxis = normalize(cross(zaxis, xaxis));
|
||||
vec3 zaxis = localLightDir;
|
||||
|
||||
mat4 shadowModelViewEx = mat4(1.0);
|
||||
shadowModelViewEx[0].xyz = vec3(xaxis.x, yaxis.x, zaxis.x);
|
||||
shadowModelViewEx[1].xyz = vec3(xaxis.y, yaxis.y, zaxis.y);
|
||||
shadowModelViewEx[2].xyz = vec3(xaxis.z, yaxis.z, zaxis.z);
|
||||
// float check = localLightDir.y;
|
||||
// if(check < 0.0) zaxis.y = -zaxis.y;
|
||||
|
||||
vec3 intervalOffset = GetShadowIntervalOffset();
|
||||
mat4 translation = BuildTranslationMatrix(intervalOffset);
|
||||
|
||||
return shadowModelViewEx * translation ;
|
||||
//#endif
|
||||
vec3 xaxis = normalize(cross(worldUp, zaxis));
|
||||
vec3 yaxis = normalize(cross(zaxis, xaxis));
|
||||
|
||||
mat4 shadowModelViewEx = mat4(1.0);
|
||||
shadowModelViewEx[0].xyz = vec3(xaxis.x, yaxis.x, zaxis.x);
|
||||
shadowModelViewEx[1].xyz = vec3(xaxis.y, yaxis.y, zaxis.y);
|
||||
shadowModelViewEx[2].xyz = vec3(xaxis.z, yaxis.z, zaxis.z);
|
||||
|
||||
vec3 intervalOffset = GetShadowIntervalOffset();
|
||||
mat4 translation = BuildTranslationMatrix(intervalOffset);
|
||||
|
||||
return shadowModelViewEx * translation;
|
||||
}
|
||||
|
||||
mat4 BuildShadowProjectionMatrix() {
|
||||
float maxDist = min(shadowDistance, far);
|
||||
return BuildOrthoProjectionMatrix(maxDist, maxDist, -far, far);
|
||||
}
|
||||
|
||||
// mat4 Custom_ViewMatrix = BuildShadowViewMatrix(LightDir);
|
||||
// mat4 Custom_ProjectionMatrix = BuildShadowProjectionMatrix();
|
||||
*/
|
@ -40,7 +40,7 @@ vec3 ToneMap_Hejl2015(in vec3 hdr)
|
||||
}
|
||||
vec3 HableTonemap(vec3 linearColor) {
|
||||
// A = shoulder strength
|
||||
const float A = 0.45;
|
||||
const float A = 0.6;
|
||||
// B = linear strength
|
||||
const float B = 0.5;
|
||||
// C = linear angle
|
||||
|
@ -3,29 +3,48 @@ vec2 R2_samples(int n){
|
||||
return fract(alpha * n);
|
||||
}
|
||||
|
||||
vec3 cosineHemisphereSample(vec2 Xi){
|
||||
float theta = 2.0 * 3.14159265359 * Xi.y;
|
||||
|
||||
float r = sqrt(Xi.x);
|
||||
float x = r * cos(theta);
|
||||
float y = r * sin(theta);
|
||||
|
||||
return vec3(x, y, sqrt(clamp(1.0 - Xi.x,0.,1.)));
|
||||
}
|
||||
|
||||
vec3 TangentToWorld(vec3 N, vec3 H, float roughness){
|
||||
vec3 UpVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
|
||||
vec3 T = normalize(cross(UpVector, N));
|
||||
vec3 B = cross(N, T);
|
||||
|
||||
return vec3((T * H.x) + (B * H.y) + (N * H.z));
|
||||
}
|
||||
|
||||
vec2 SpiralSample(
|
||||
int samples, int totalSamples, float rotation, float Xi
|
||||
){
|
||||
float alpha = float(samples + Xi) * (1.0 / float(totalSamples));
|
||||
|
||||
float theta = 3.14159265359 * alpha * rotation ;
|
||||
|
||||
float r = sqrt(Xi);
|
||||
float x = r * sin(theta);
|
||||
float y = r * cos(theta);
|
||||
|
||||
return vec2(x, y);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////
|
||||
///////////////////////////// SSAO ////////////////////////
|
||||
////////////////////////////////////////////////////////////////
|
||||
const float PI = 3.141592653589793238462643383279502884197169;
|
||||
|
||||
vec2 tapLocation_alternate(
|
||||
int samples, int totalSamples, float rotation, float rng
|
||||
){
|
||||
float alpha = float(samples + rng) * (1.0 / float(totalSamples));
|
||||
float angle = alpha * (rotation * PI);
|
||||
|
||||
float sin_v = sin(angle);
|
||||
float cos_v = cos(angle);
|
||||
|
||||
return vec2(cos_v, sin_v) * alpha;
|
||||
}
|
||||
|
||||
vec2 SSAO(
|
||||
vec3 viewPos, vec3 normal, bool hand, bool leaves
|
||||
vec3 viewPos, vec3 normal, bool hand, bool leaves, float noise
|
||||
){
|
||||
if(hand) return vec2(1,0);
|
||||
if(hand) return vec2(1.0,0.0);
|
||||
int samples = 7;
|
||||
float occlusion = 0.0;
|
||||
float sss = 0.0;
|
||||
|
||||
|
||||
float dist = 1.0 + clamp(viewPos.z*viewPos.z/50.0,0,5); // shrink sample size as distance increases
|
||||
@ -41,23 +60,11 @@ vec2 SSAO(
|
||||
|
||||
vec2 acc = -(TAA_Offset*(texelSize/2))*RENDER_SCALE ;
|
||||
|
||||
// int seed = (frameCounter%40000)*2 + (1+frameCounter);
|
||||
// vec2 samplePos = fract(R2_samples(seed).xy + blueNoise(gl_FragCoord.xy).xy);
|
||||
|
||||
int samples = 7;
|
||||
|
||||
int seed = (frameCounter%40000) + frameCounter*2;
|
||||
float samplePos = fract(R2_samples(seed).y + blueNoise(gl_FragCoord.xy).y);
|
||||
|
||||
float occlusion = 0.0; float sss = 0.0;
|
||||
int n = 0;
|
||||
for (int i = 0; i < samples; i++) {
|
||||
|
||||
vec2 sp = tapLocation_alternate(i, 7, 9, samplePos) * 0.2;
|
||||
vec2 sampleOffset = SpiralSample(i, 7, 8, noise) * 0.2 * mulfov2;
|
||||
|
||||
float rd = mulfov2 ;
|
||||
|
||||
vec2 sampleOffset = sp * rd;
|
||||
ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight*aspectRatio)*RENDER_SCALE);
|
||||
|
||||
if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth*RENDER_SCALE.x && offset.y < viewHeight*RENDER_SCALE.y ) {
|
||||
@ -85,19 +92,13 @@ vec2 SSAO(
|
||||
return max(1.0 - vec2(occlusion, sss)/n, 0.0);
|
||||
}
|
||||
float ScreenSpace_SSS(
|
||||
vec3 viewPos, vec3 normal, bool hand, bool leaves
|
||||
vec3 viewPos, vec3 normal, bool hand, bool leaves, float noise
|
||||
){
|
||||
if(hand) return 1.0;
|
||||
if(hand) return 0.0;
|
||||
int samples = 7;
|
||||
float occlusion = 0.0;
|
||||
float sss = 0.0;
|
||||
|
||||
// float radius[7] = float[](
|
||||
// 0.15,
|
||||
// 0.15,
|
||||
// 0.15,
|
||||
// 0.15,
|
||||
// 0.15,
|
||||
// 0.15,
|
||||
// 0.15
|
||||
// );
|
||||
|
||||
float dist = 1.0 + clamp(viewPos.z*viewPos.z/50.0,0,5); // shrink sample size as distance increases
|
||||
float mulfov2 = gbufferProjection[1][1]/(3 * dist);
|
||||
@ -106,22 +107,15 @@ float ScreenSpace_SSS(
|
||||
|
||||
float dist3 = clamp(1-exp( viewPos.z*viewPos.z / -50),0,1);
|
||||
if(leaves) maxR2_2 = mix(10, maxR2_2, dist3);
|
||||
|
||||
|
||||
vec2 acc = -(TAA_Offset*(texelSize/2))*RENDER_SCALE ;
|
||||
|
||||
int seed = (frameCounter%40000) * 2 + (1+frameCounter);
|
||||
float samplePos = fract(R2_samples(seed).x + blueNoise(gl_FragCoord.xy).x) * 1.61803398874;
|
||||
|
||||
int samples = 7;
|
||||
|
||||
float sss = 0.0;
|
||||
int n = 0;
|
||||
for (int i = 0; i < samples; i++) {
|
||||
|
||||
vec2 sp = tapLocation_alternate(i, samples, 20, samplePos)* 0.2;
|
||||
float rd = mulfov2 ;
|
||||
vec2 sampleOffset = SpiralSample(i, 7, 8, noise) * 0.2 * mulfov2;
|
||||
|
||||
vec2 sampleOffset = sp * rd;
|
||||
ivec2 offset = ivec2(gl_FragCoord.xy + sampleOffset*vec2(viewWidth,viewHeight*aspectRatio)*RENDER_SCALE);
|
||||
|
||||
if (offset.x >= 0 && offset.y >= 0 && offset.x < viewWidth*RENDER_SCALE.x && offset.y < viewHeight*RENDER_SCALE.y ) {
|
||||
@ -130,12 +124,10 @@ float ScreenSpace_SSS(
|
||||
float dsquared = dot(vec, vec);
|
||||
|
||||
if (dsquared > 1e-5){
|
||||
|
||||
if(dsquared > maxR2_2){
|
||||
float NdotV = 1.0 - clamp(dot(vec*dsquared, normalize(normal)),0.,1.);
|
||||
sss += max((NdotV - (1.0-NdotV)) * clamp(1.0-maxR2_2/dsquared,0.0,1.0) ,0.0);
|
||||
}
|
||||
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
@ -146,6 +138,7 @@ float ScreenSpace_SSS(
|
||||
////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////// RTAO/SSGI ////////////////////////
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
vec3 rayTrace_GI(vec3 dir,vec3 position,float dither, float quality){
|
||||
|
||||
vec3 clipPosition = toClipSpace3(position);
|
||||
@ -222,24 +215,6 @@ vec3 RT(vec3 dir, vec3 position, float noise, float stepsizes){
|
||||
return vec3(1.1);
|
||||
}
|
||||
|
||||
vec3 cosineHemisphereSample(vec2 Xi, float roughness){
|
||||
float r = sqrt(Xi.x);
|
||||
float theta = 2.0 * 3.14159265359 * Xi.y;
|
||||
|
||||
float x = r * cos(theta);
|
||||
float y = r * sin(theta);
|
||||
|
||||
return vec3(x, y, sqrt(clamp(1.0 - Xi.x,0.,1.)));
|
||||
}
|
||||
|
||||
vec3 TangentToWorld(vec3 N, vec3 H, float roughness){
|
||||
vec3 UpVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
|
||||
vec3 T = normalize(cross(UpVector, N));
|
||||
vec3 B = cross(N, T);
|
||||
|
||||
return vec3((T * H.x) + (B * H.y) + (N * H.z));
|
||||
}
|
||||
|
||||
void ApplySSRT(inout vec3 lighting, vec3 normal,vec2 noise,vec3 viewPos, vec2 lightmaps, vec3 skylightcolor, vec3 torchcolor, bool isGrass){
|
||||
int nrays = RAY_COUNT;
|
||||
|
||||
@ -255,14 +230,15 @@ void ApplySSRT(inout vec3 lighting, vec3 normal,vec2 noise,vec3 viewPos, vec2 li
|
||||
vec3 torchlight = vec3(0.0);
|
||||
DoRTAmbientLighting(torchcolor, lightmaps, skyLM, torchlight, skylightcolor);
|
||||
|
||||
vec2 noisey = blueNoise(gl_FragCoord.xy).xy;
|
||||
|
||||
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);
|
||||
vec2 ij = fract(R2_samples(seed) + noise);
|
||||
vec3 rayDir = TangentToWorld(normal, normalize(cosineHemisphereSample(ij)) ,1.0);
|
||||
|
||||
#ifdef HQ_SSGI
|
||||
vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, viewPos, blueNoise(), 50.); // ssr rt
|
||||
vec3 rayHit = rayTrace_GI( mat3(gbufferModelView) * rayDir, viewPos, blueNoise(), 50.); // ssr rt
|
||||
#else
|
||||
vec3 rayHit = RT(mat3(gbufferModelView)*rayDir, viewPos, blueNoise(), 30.); // choc sspt
|
||||
#endif
|
||||
|
@ -252,7 +252,7 @@ const float sunPathRotation = -35; //[-90 -89 -88 -87 -86 -85 -84 -83 -82 -81 -8
|
||||
#define MOB_SSS
|
||||
// #define MISC_BLOCK_SSS
|
||||
#define Ambient_SSS
|
||||
#define ambientsss_brightness 1 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 ]
|
||||
#define ambientsss_brightness 1.0 // [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0]
|
||||
|
||||
|
||||
// #define Porosity
|
||||
@ -500,5 +500,4 @@ uniform int moonPhase;
|
||||
#ifdef LIGHTNING_FLASH
|
||||
#endif
|
||||
#if BLISS_SHADERS == 0
|
||||
#endif
|
||||
|
||||
#endif
|
@ -106,7 +106,7 @@ vec3 rayTraceSpeculars(vec3 dir, vec3 position, float dither, float quality, boo
|
||||
return vec3(1.1);
|
||||
}
|
||||
|
||||
float xonk_fma(float a,float b,float c){
|
||||
float fma(float a,float b,float c){
|
||||
return a * b + c;
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ float xonk_fma(float a,float b,float c){
|
||||
vec3 SampleVNDFGGX(
|
||||
vec3 viewerDirection, // Direction pointing towards the viewer, oriented such that +Z corresponds to the surface normal
|
||||
vec2 alpha, // Roughness parameter along X and Y of the distribution
|
||||
vec2 xy // Pair of uniformly distributed numbers in [0, 1)
|
||||
float xy // Pair of uniformly distributed numbers in [0, 1)
|
||||
) {
|
||||
// alpha *= alpha;
|
||||
// Transform viewer direction to the hemisphere configuration
|
||||
@ -122,9 +122,9 @@ vec3 SampleVNDFGGX(
|
||||
|
||||
// Sample a reflection direction off the hemisphere
|
||||
const float tau = 6.2831853; // 2 * pi
|
||||
float phi = tau * xy.x;
|
||||
float phi = tau * xy;
|
||||
|
||||
float cosTheta = xonk_fma(1.0 - xy.y, 1.0 + viewerDirection.z, -viewerDirection.z) ;
|
||||
float cosTheta = fma(1.0 - xy, 1.0 + viewerDirection.z, -viewerDirection.z) ;
|
||||
float sinTheta = sqrt(clamp(1.0 - cosTheta * cosTheta, 0.0, 1.0));
|
||||
|
||||
// xonk note, i dont know what im doing but this kinda does what i want so whatever
|
||||
@ -169,7 +169,7 @@ void DoSpecularReflections(
|
||||
vec3 FragPos, // toScreenspace(vec3(screenUV, depth)
|
||||
vec3 WorldPos,
|
||||
vec3 LightPos, // should be in world space
|
||||
vec3 Noise, // xy = noise texure. z = simple blue noise
|
||||
vec2 Noise, // x = bluenoise z = interleaved gradient noise
|
||||
|
||||
vec3 Normal, // normals in world space
|
||||
float Roughness, // red channel of specular texture _S
|
||||
@ -199,7 +199,7 @@ void DoSpecularReflections(
|
||||
vec3 ViewDir = -WorldPos*Basis;
|
||||
|
||||
#ifdef Rough_reflections
|
||||
vec3 SamplePoints = SampleVNDFGGX(ViewDir, vec2(Roughness), fract(R2_Sample(frameCounter%40000) + Noise.xy));
|
||||
vec3 SamplePoints = SampleVNDFGGX(ViewDir, vec2(Roughness), Noise.x);
|
||||
if(Hand) SamplePoints = normalize(vec3(0.0,0.0,1.0));
|
||||
#else
|
||||
vec3 SamplePoints = normalize(vec3(0.0,0.0,1.0));
|
||||
@ -247,7 +247,7 @@ void DoSpecularReflections(
|
||||
#endif
|
||||
|
||||
float reflectLength = 0.0;
|
||||
vec3 RaytracePos = rayTraceSpeculars(mat3(gbufferModelView) * L, FragPos, Noise.z, float(SSR_Quality), Hand, reflectLength);
|
||||
vec3 RaytracePos = rayTraceSpeculars(mat3(gbufferModelView) * L, FragPos, Noise.y, float(SSR_Quality), Hand, reflectLength);
|
||||
float LOD = clamp(pow(reflectLength, pow(1.0-sqrt(Roughness),5.0) * 3.0) * 6.0, 0.0, 6.0); // use higher LOD as the reflection goes on, to blur it. this helps denoise a little.
|
||||
|
||||
if(Roughness <= 0.0) LOD = 0.0;
|
||||
|
@ -86,6 +86,13 @@ vec4 GetVolumetricFog(
|
||||
vec3 fragposition = mat3(shadowModelView) * wpos + shadowModelView[3].xyz;
|
||||
fragposition = diagonal3(shadowProjection) * fragposition + shadowProjection[3].xyz;
|
||||
|
||||
// mat4 Custom_ViewMatrix = BuildShadowViewMatrix(LightDir);
|
||||
// mat4 Custom_ProjectionMatrix = BuildShadowProjectionMatrix();
|
||||
|
||||
// vec3 fragposition = mat3(Custom_ViewMatrix) * wpos + Custom_ViewMatrix[3].xyz;
|
||||
// fragposition = diagonal3(Custom_ProjectionMatrix) * fragposition + Custom_ProjectionMatrix[3].xyz;
|
||||
|
||||
|
||||
//project view origin into projected shadowmap space
|
||||
vec3 start = toShadowSpaceProjected(vec3(0.0));
|
||||
|
||||
@ -105,6 +112,7 @@ vec4 GetVolumetricFog(
|
||||
vec3 vL = vec3(0.);
|
||||
|
||||
float SdotV = dot(sunVec,normalize(viewPosition))*lightCol.a;
|
||||
// float SdotV = dot(normalize(LightDir * mat3(gbufferModelViewInverse)), normalize(viewPosition))*lightCol.a;
|
||||
float dL = length(dVWorld);
|
||||
|
||||
//Mie phase + somewhat simulates multiple scattering (Horizon zero down cloud approx)
|
||||
@ -203,11 +211,8 @@ vec4 GetVolumetricFog(
|
||||
|
||||
vec3 AtmosphericFog = skyCol0 * (rL*3.0 + m);// + (LightSourceColor * sh) * (rayL*rL*3.0 + m*mie);
|
||||
|
||||
// extra fog effects
|
||||
// vec3 rainRays = (LightSourceColor*sh) * (rayL*(phaseg(SdotV,0.7))) * clamp(pow(WsunVec.y,5)*2,0.0,1) * rainStrength * noPuddleAreas * RainFog_amount;
|
||||
// vec3 CaveRays = (LightSourceColor*sh) * phaseg(SdotV,0.7) * 0.001 * (1.0 - lightleakfix);
|
||||
|
||||
vec3 vL0 = (AtmosphericFog + AmbientLight + DirectLight + Lightning) * lightleakfix;
|
||||
// vec3 vL0 = DirectLight;
|
||||
|
||||
// #if defined Cave_fog && defined TEST
|
||||
// vL0 += cavefogCol;
|
||||
|
Reference in New Issue
Block a user