mirror of
https://github.com/X0nk/Bliss-Shader.git
synced 2025-06-22 00:37:35 +08:00
Clean specular.glsl and make it easier to use for myself across dimension. make grass brighter in ambient light.
This commit is contained in:
@ -87,7 +87,7 @@ vec3 sky_opticalDepth(vec3 position, vec3 direction, const float steps) {
|
||||
}
|
||||
|
||||
vec3 sky_transmittance(vec3 position, vec3 direction, const float steps) {
|
||||
return exp2(-sky_opticalDepth(position, direction, steps) * rLOG2);
|
||||
return exp(-sky_opticalDepth(position, direction, steps) * rLOG2);
|
||||
}
|
||||
|
||||
|
||||
@ -95,7 +95,7 @@ vec3 sky_transmittance(vec3 position, vec3 direction, const float steps) {
|
||||
vec3 calculateAtmosphere(vec3 background, vec3 viewVector, vec3 upVector, vec3 sunVector, vec3 moonVector, out vec2 pid, out vec3 transmittance, const int iSteps, float noise) {
|
||||
const int jSteps = 4;
|
||||
|
||||
|
||||
vec3 sunvec2 = sunVector;
|
||||
|
||||
vec3 viewPosition = (sky_planetRadius + eyeAltitude) * upVector;
|
||||
|
||||
@ -111,7 +111,9 @@ vec3 calculateAtmosphere(vec3 background, vec3 viewVector, vec3 upVector, vec3 s
|
||||
vec3 increment = viewVector * stepSize;
|
||||
vec3 position = viewVector * sd.x + viewPosition;
|
||||
position += increment * (0.34*noise);
|
||||
vec2 phaseSun = sky_phase(dot(viewVector, sunVector ), sky_mieg) ;
|
||||
vec2 phaseSun = (pow(sky_phase(dot(viewVector, sunVector ), 0.6)*3, vec2(2)) + sky_phase(dot(viewVector, sunVector ), 0.8))/2;
|
||||
|
||||
// phaseSun = sky_phase(dot(viewVector, sunVector ), 0.8);
|
||||
vec2 phaseMoon = sky_phase(dot(viewVector, moonVector), sky_mieg);
|
||||
|
||||
vec3 scatteringSun = vec3(0.0);
|
||||
@ -123,8 +125,8 @@ vec3 calculateAtmosphere(vec3 background, vec3 viewVector, vec3 upVector, vec3 s
|
||||
|
||||
// float low_sun = clamp(pow(1.0-sunVector.y,10.0) + 1.0,1.0, 2.0);
|
||||
|
||||
float high_sun = clamp(pow(sunVector.y+0.6,5),0.0,1.0) * 3.0; // make sunrise less blue, and allow sunset to be bluer
|
||||
float low_sun = clamp(((1.0-abs(sunVector.y))*3.) - high_sun,1.0,2.0) ;
|
||||
float high_sun = clamp(pow(sunvec2.y+0.6,5),0.0,1.0) * 3.0; // make sunrise less blue, and allow sunset to be bluer
|
||||
float low_sun = clamp(((1.0-abs(sunvec2.y))*3.) - high_sun,1.0,2.0) ;
|
||||
|
||||
for (int i = 0; i < iSteps; ++i, position += increment) {
|
||||
vec3 density = sky_density(length(position));
|
||||
@ -139,12 +141,12 @@ vec3 calculateAtmosphere(vec3 background, vec3 viewVector, vec3 upVector, vec3 s
|
||||
scatteringSun += sky_coefficientsScattering * (stepAirmass.xy * phaseSun ) * stepScatteringVisible * sky_transmittance(position, sunVector*0.5+0.1, jSteps) ;
|
||||
scatteringMoon += sky_coefficientsScattering * (stepAirmass.xy * phaseMoon) * stepScatteringVisible * sky_transmittance(position, moonVector, jSteps);
|
||||
// Nice way to fake multiple scattering.
|
||||
scatteringAmbient += sky_coefficientsScattering * stepAirmass.xy * (stepScatteringVisible * low_sun);
|
||||
scatteringAmbient += sky_coefficientsScattering * stepAirmass.xy * stepScatteringVisible * low_sun;
|
||||
|
||||
transmittance *= stepTransmittance ;
|
||||
}
|
||||
|
||||
vec3 scattering = scatteringSun * sunColorBase + (scatteringAmbient) * background + scatteringMoon*moonColorBase ;
|
||||
vec3 scattering = scatteringSun * sunColorBase + scatteringAmbient * background + scatteringMoon*moonColorBase ;
|
||||
// scattering = vec3(0,high_sun*255.,0);
|
||||
return scattering;
|
||||
}
|
||||
|
@ -188,6 +188,9 @@ const float sunPathRotation = -35; //[-90 -89 -88 -87 -86 -85 -84 -83 -82 -81 -8
|
||||
#define reflection_quality 30 // [6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0 20.0 25.0 30.0 35.0 40.0 45.0 50.0 55.0 60.0 65.0 70.0 75.0 80.0 85.0 90.0 95.0 100.0 ]
|
||||
#define Roughness_Threshold 1.5 // [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 ]
|
||||
|
||||
#ifdef Specular_Reflections
|
||||
#define LIGHTSOURCE_REFLECTION
|
||||
#endif
|
||||
|
||||
#define EMISSIVE_TYPE 2 // [0 1 2 3]
|
||||
#define Emissive_Brightness 10.0 // [1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 15.0 20.0 25.0 30.0 35.0 40.0 45.0 50.0 100.]
|
||||
@ -205,7 +208,7 @@ const float sunPathRotation = -35; //[-90 -89 -88 -87 -86 -85 -84 -83 -82 -81 -8
|
||||
#define SSS_TYPE 2 // [0 1 2 3]
|
||||
#define LabSSS_Curve 1.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 MOB_SSS
|
||||
#define MISC_BLOCK_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 ]
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
|
||||
uniform sampler2D gaux1;
|
||||
uniform int framemod8;
|
||||
|
||||
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
|
||||
@ -11,28 +10,26 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
|
||||
vec2(3,7.)/8.,
|
||||
vec2(7.,-7.)/8.);
|
||||
|
||||
|
||||
|
||||
vec3 mix_vec3(vec3 X, vec3 Y, float A){
|
||||
return X * (1.0 - A) + Y * A;
|
||||
}
|
||||
|
||||
float mix_float(float X, float Y, float A){
|
||||
return X * (1.0 - A) + Y * A;
|
||||
}
|
||||
|
||||
float square(float x){
|
||||
return x*x;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// other shit
|
||||
float invLinZ (float lindepth){
|
||||
return -((2.0*near/lindepth)-far-near)/(far-near);
|
||||
}
|
||||
|
||||
vec3 toClipSpace3(vec3 viewSpacePosition) {
|
||||
return projMAD(gbufferProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
float linZ(float depth) {
|
||||
return (2.0 * near) / (far + near - depth * (far - near));
|
||||
// l = (2*n)/(f+n-d(f-n))
|
||||
@ -42,7 +39,6 @@ float linZ(float depth) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void frisvad(in vec3 n, out vec3 f, out vec3 r){
|
||||
if(n.z < -0.9) {
|
||||
f = vec3(0.,-1,0);
|
||||
@ -54,54 +50,24 @@ void frisvad(in vec3 n, out vec3 f, out vec3 r){
|
||||
r = vec3(b, 1. - n.y*n.y*a , -n.y);
|
||||
}
|
||||
}
|
||||
|
||||
mat3 CoordBase(vec3 n){
|
||||
vec3 x,y;
|
||||
frisvad(n,x,y);
|
||||
return mat3(x,y,n);
|
||||
}
|
||||
|
||||
float unpackRoughness(float x){
|
||||
float r = 1.0 - x;
|
||||
return clamp(r*r,0,1);
|
||||
}
|
||||
vec2 R2_samples_spec(int n){
|
||||
|
||||
vec2 R2_Sample(int n){
|
||||
vec2 alpha = vec2(0.75487765, 0.56984026);
|
||||
return fract(alpha * 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.);
|
||||
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 = maxLengths.y;
|
||||
|
||||
vec3 stepv = direction * mult / quality*vec3(RENDER_SCALE,1.0) * dither;
|
||||
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) ;
|
||||
|
||||
spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE;
|
||||
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
vec3 rayTraceSpeculars(vec3 dir,vec3 position,float dither, float quality, bool hand, inout float reflectLength){
|
||||
vec3 rayTraceSpeculars(vec3 dir, vec3 position, float dither, float quality, bool hand, inout float reflectLength){
|
||||
|
||||
vec3 clipPosition = toClipSpace3(position);
|
||||
float rayLength = ((position.z + dir.z * far*sqrt(3.)) > -near) ?
|
||||
@ -143,34 +109,13 @@ vec3 rayTraceSpeculars(vec3 dir,vec3 position,float dither, float quality, bool
|
||||
reflectLength += 1.0 / quality; // for shit
|
||||
|
||||
}
|
||||
|
||||
|
||||
return vec3(1.1);
|
||||
}
|
||||
|
||||
|
||||
// vec3 sampleGGXVNDF(vec3 V_, float roughness, float U1, float U2){
|
||||
// // stretch view
|
||||
// vec3 V = normalize(vec3(roughness * V_.x, roughness * V_.y, V_.z));
|
||||
// // orthonormal basis
|
||||
// vec3 T1 = (V.z < 0.9999) ? normalize(cross(V, vec3(0,0,1))) : vec3(1,0,0);
|
||||
// vec3 T2 = cross(T1, V);
|
||||
// // sample point with polar coordinates (r, phi)
|
||||
// float a = 1.0 / (1.0 + V.z);
|
||||
// float r = sqrt(U1*0.25);
|
||||
// float phi = (U2<a) ? U2/a * 3.141592653589793 : 3.141592653589793 + (U2-a)/(1.0-a) * 3.141592653589793;
|
||||
// float P1 = r*cos(phi);
|
||||
// float P2 = r*sin(phi)*((U2<a) ? 1.0 : V.z);
|
||||
// // compute normal
|
||||
// vec3 N = P1*T1 + P2*T2 + sqrt(max(0.0, 1.0 - P1*P1 - P2*P2))*V;
|
||||
// // unstretch
|
||||
// N = normalize(vec3(roughness*N.x, roughness*N.y, N.z));
|
||||
// return N;
|
||||
// }
|
||||
|
||||
float xonk_fma(float a,float b,float c){
|
||||
return a * b + c;
|
||||
}
|
||||
|
||||
//// thank you Zombye | the paper: https://ggx-research.github.io/publication/2023/06/09/publication-ggx.html
|
||||
vec3 SampleVNDFGGX(
|
||||
vec3 viewerDirection, // Direction pointing towards the viewer, oriented such that +Z corresponds to the surface normal
|
||||
@ -204,8 +149,7 @@ vec3 SampleVNDFGGX(
|
||||
return normalize(vec3(alpha * halfway.xy, halfway.z));
|
||||
}
|
||||
|
||||
|
||||
vec3 GGX(vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
|
||||
float GGX(vec3 n, vec3 v, vec3 l, float r, float f0) {
|
||||
r = max(pow(r,2.5), 0.0001);
|
||||
|
||||
vec3 h = l + v;
|
||||
@ -218,333 +162,118 @@ vec3 GGX(vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
|
||||
|
||||
float denom = dotNHsq * r - dotNHsq + 1.;
|
||||
float D = r / (3.141592653589793 * denom * denom);
|
||||
vec3 F = F0 + (1. - F0) * exp2((-5.55473*dotLH-6.98316)*dotLH);
|
||||
|
||||
float F = f0 + (1. - f0) * exp2((-5.55473*dotLH-6.98316)*dotLH);
|
||||
float k2 = .25 * r;
|
||||
|
||||
return dotNL * D * F / (dotLH*dotLH*(1.0-k2)+k2);
|
||||
}
|
||||
|
||||
// pain
|
||||
void MaterialReflections(
|
||||
void DoSpecularReflections(
|
||||
inout vec3 Output,
|
||||
float roughness,
|
||||
vec3 f0,
|
||||
vec3 albedo,
|
||||
vec3 sunPos,
|
||||
vec3 directlighting,
|
||||
float lightmap,
|
||||
vec3 normal,
|
||||
vec3 np3,
|
||||
vec3 fragpos,
|
||||
vec3 noise,
|
||||
bool hand,
|
||||
bool isEntities
|
||||
|
||||
vec3 FragPos, // toScreenspace(vec3(screenUV, depth)
|
||||
vec3 WorldPos,
|
||||
vec3 LightPos, // should be in world space
|
||||
vec3 Noise, // xy = noise texure. z = simple blue noise
|
||||
|
||||
vec3 Normal, // normals in world space
|
||||
float Roughness, // red channel of specular texture _S
|
||||
float F0, // green channel of specular texture _S
|
||||
|
||||
vec3 Albedo,
|
||||
vec3 Diffuse, // should contain the light color and NdotL. and maybe shadows.
|
||||
|
||||
float Lightmap, // in anything other than world0, this should be 1.0;
|
||||
bool Hand // mask for the hand
|
||||
){
|
||||
vec3 Reflections_Final = Output;
|
||||
vec3 SkyReflection = Output;
|
||||
vec3 SunReflection = vec3(0.0);
|
||||
vec4 Reflections = vec4(0.0);
|
||||
vec3 Final_Reflection = Output;
|
||||
vec3 Background_Reflection = Output;
|
||||
vec3 Lightsource_Reflection = vec3(0.0);
|
||||
vec4 SS_Reflections = vec4(0.0);
|
||||
|
||||
float reflectLength;
|
||||
float Outdoors = clamp((lightmap-0.6)*5.0, 0.0,1.0);
|
||||
Lightmap = clamp((Lightmap-0.6)*5.0, 0.0,1.0);
|
||||
|
||||
roughness = unpackRoughness(roughness);
|
||||
f0 = f0.y == 0.0 ? vec3(0.02) : f0;
|
||||
Roughness = unpackRoughness(Roughness);
|
||||
F0 = F0 == 0.0 ? 0.02 : F0;
|
||||
|
||||
// Roughness = 0.0;
|
||||
// F0 = 0.9;
|
||||
|
||||
// f0 = vec3(0.9);
|
||||
// roughness = 0.5;
|
||||
mat3 Basis = CoordBase(Normal);
|
||||
vec3 ViewDir = -WorldPos*Basis;
|
||||
|
||||
mat3 basis = CoordBase(normal);
|
||||
vec3 normSpaceView = -np3*basis ;
|
||||
|
||||
|
||||
// roughness stuff
|
||||
#ifdef Rough_reflections
|
||||
int seed = frameCounter%40000;
|
||||
vec2 ij = fract(R2_samples_spec(seed) + noise.rg) ;
|
||||
vec3 H = SampleVNDFGGX(normSpaceView, vec2(roughness), ij.xy);
|
||||
|
||||
if(hand) H = normalize(vec3(0.0,0.0,1.0));
|
||||
vec3 SamplePoints = SampleVNDFGGX(ViewDir, vec2(Roughness), fract(R2_Sample(frameCounter%40000) + Noise.xy));
|
||||
if(Hand) SamplePoints = normalize(vec3(0.0,0.0,1.0));
|
||||
#else
|
||||
vec3 H = normalize(vec3(0.0,0.0,1.0));
|
||||
vec3 SamplePoints = normalize(vec3(0.0,0.0,1.0));
|
||||
#endif
|
||||
|
||||
vec3 Ln = reflect(-ViewDir, SamplePoints);
|
||||
vec3 L = Basis * Ln;
|
||||
|
||||
float Fresnel = pow(clamp(1.0 + dot(-Ln, SamplePoints),0.0,1.0), 5.0); // Schlick's approximation
|
||||
float RayContribution = mix_float(F0, 1.0, Fresnel); // ensure that when the angle is 0 that the correct F0 is used.
|
||||
|
||||
vec3 Ln = reflect(-normSpaceView, H);
|
||||
vec3 L = basis * Ln;
|
||||
#ifdef Rough_reflections
|
||||
if(Hand) RayContribution = RayContribution * pow(1.0-Roughness,3.0);
|
||||
#else
|
||||
RayContribution = RayContribution * pow(1.0-Roughness,3.0);
|
||||
#endif
|
||||
|
||||
// fresnel stuff
|
||||
float fresnel = pow(clamp(1.0 + dot(-Ln, H),0.0,1.0),5.0);
|
||||
vec3 F = mix_vec3(f0, vec3(1.0), fresnel);
|
||||
vec3 rayContrib = F;
|
||||
bool hasReflections = Roughness_Threshold == 1.0 ? true : F0 * (1.0 - Roughness * Roughness_Threshold) > 0.01;
|
||||
|
||||
float rayContribLuma = dot(rayContrib,vec3(0.333333));
|
||||
float VisibilityFactor = rayContribLuma * pow(1.0-roughness,3.0);
|
||||
bool hasReflections = Roughness_Threshold == 1.0 ? true : (f0.y * (1.0 - roughness * Roughness_Threshold)) > 0.01;
|
||||
// mulitply all reflections by the albedo if it is a metal.
|
||||
vec3 Metals = F0 > 229.5/255.0 ? mix_vec3(Albedo, vec3(1.0), Fresnel) : vec3(1.0);
|
||||
|
||||
SunReflection = directlighting * GGX(normal, -np3, sunPos, roughness, vec3(f0.y));
|
||||
|
||||
// --------------- BACKGROUND REFLECTIONS
|
||||
// apply background reflections to the final color. make sure it does not exist based on the lightmap
|
||||
#ifdef Sky_reflection
|
||||
//pow(clamp(1.0-VisibilityFactor,0,1),0.3)*
|
||||
if( Roughness_Threshold == 1.0 || (f0.y * (1.0 - roughness * Roughness_Threshold)) > 0.005) SkyReflection = skyCloudsFromTex(L, colortex4).rgb / 30.;
|
||||
if(hasReflections) Background_Reflection = (skyCloudsFromTexLOD(L, colortex4, sqrt(Roughness) * 9.0).rgb / 30.0) * Metals;
|
||||
|
||||
// take fresnel and lightmap levels into account and write to the final color
|
||||
Final_Reflection = mix_vec3(Output, Background_Reflection, Lightmap * RayContribution);
|
||||
#endif
|
||||
|
||||
if (hasReflections) { // Skip sky reflection and SSR if its just not very visible anyway
|
||||
|
||||
#ifdef Screen_Space_Reflections
|
||||
float rayQuality = mix_float(reflection_quality,6.0,rayContribLuma); // Scale quality with ray contribution
|
||||
|
||||
#ifndef Dynamic_SSR_quality
|
||||
rayQuality = reflection_quality;
|
||||
// --------------- SCREENSPACE REFLECTIONS
|
||||
// apply screenspace reflections to the final color and mask out background reflections.
|
||||
#ifdef Screen_Space_Reflections
|
||||
if(hasReflections){
|
||||
#ifdef Dynamic_SSR_quality
|
||||
float SSR_Quality = mix_float(reflection_quality, 6.0, RayContribution); // Scale quality with ray contribution
|
||||
#else
|
||||
float SSR_Quality = reflection_quality;
|
||||
#endif
|
||||
|
||||
noise.b = mix_float(noise.b, 0.5 + (noise.b-0.5),rayContribLuma);
|
||||
if(hand) {rayQuality = max(rayQuality,30.0); noise.b = 0.5 + (noise.b-0.5);}
|
||||
|
||||
vec3 rtPos = rayTraceSpeculars(mat3(gbufferModelView) * L, fragpos.xyz, (noise.b), rayQuality, hand, reflectLength);
|
||||
|
||||
float LOD = clamp(reflectLength * 6.0, 0.0,6.0);
|
||||
// LOD = 0.0;
|
||||
|
||||
if (rtPos.z < 1.0) { // Reproject on previous frame
|
||||
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rtPos) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
|
||||
float reflectLength = 0.0;
|
||||
vec3 RaytracePos = rayTraceSpeculars(mat3(gbufferModelView) * L, FragPos, Noise.z, 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 (RaytracePos.z < 1.0){
|
||||
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(RaytracePos) + 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) {
|
||||
Reflections.a = 1.0;
|
||||
Reflections.rgb = texture2DLod(colortex5,previousPosition.xy,LOD).rgb;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// check if the f0 is within the metal ranges, then tint by albedo if it's true.
|
||||
// // the brightening is disgusting
|
||||
// vec3 Metals = f0.y > 229.5/255.0 ? clamp((albedo / max(pow(luma(albedo),0.1),0.4)) + fresnel,0.0,1.0) : vec3(1.0);
|
||||
vec3 Metals = f0.y > 229.5/255.0 ? clamp(albedo + fresnel,0.0,1.0) : vec3(1.0);
|
||||
|
||||
SunReflection *= Metals;
|
||||
|
||||
#ifdef Sky_reflection
|
||||
SkyReflection *= Metals;
|
||||
#endif
|
||||
#ifdef Screen_Space_Reflections
|
||||
Reflections.rgb *= Metals;
|
||||
#endif
|
||||
|
||||
// background reflections
|
||||
SkyReflection = mix_vec3(Output, SkyReflection, Outdoors);
|
||||
|
||||
// composite background and SSR.
|
||||
Reflections.rgb = mix_vec3(SkyReflection, Reflections.rgb, Reflections.a);
|
||||
|
||||
// put reflections onto the scene
|
||||
#ifdef Rough_reflections
|
||||
Output = hand ? mix_vec3(Output, Reflections.rgb, VisibilityFactor) : mix_vec3(Output, Reflections.rgb, rayContribLuma);
|
||||
#else
|
||||
Output = mix_vec3(Output, Reflections.rgb, VisibilityFactor);
|
||||
#endif
|
||||
|
||||
Output += SunReflection;
|
||||
}
|
||||
|
||||
void MaterialReflections_N(
|
||||
inout vec3 Output,
|
||||
float roughness,
|
||||
vec3 f0,
|
||||
vec3 albedo,
|
||||
vec3 normal,
|
||||
vec3 np3,
|
||||
vec3 fragpos,
|
||||
vec3 noise,
|
||||
bool hand
|
||||
){
|
||||
vec3 Reflections_Final = Output;
|
||||
float reflectLength = 0.0;
|
||||
|
||||
roughness = unpackRoughness(roughness);
|
||||
f0 = f0.y == 0.0 ? vec3(0.02) : f0;
|
||||
|
||||
// roughness = 0.0;
|
||||
// f0 = vec3(0.9);
|
||||
|
||||
float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0.y) * -4),0,1);
|
||||
|
||||
mat3 basis = CoordBase(normal);
|
||||
vec3 normSpaceView = -np3*basis ;
|
||||
|
||||
// roughness stuff
|
||||
#ifdef Rough_reflections
|
||||
int seed = (frameCounter%40000);
|
||||
vec2 ij = fract(R2_samples_spec(seed) + noise.rg) ;
|
||||
vec3 H = SampleVNDFGGX(normSpaceView, vec2(roughness), ij.xy);
|
||||
|
||||
if(hand) H = normalize(vec3(0.0,0.0,1.0));
|
||||
#else
|
||||
vec3 H = normalize(vec3(0.0,0.0,1.0));
|
||||
#endif
|
||||
|
||||
vec3 Ln = reflect(-normSpaceView, H);
|
||||
vec3 L = basis * Ln;
|
||||
|
||||
// fresnel stuff
|
||||
float fresnel = pow(clamp(1.0 + dot(-Ln, H),0.0,1.0),5.0);
|
||||
vec3 F = mix(f0, vec3(1.0), fresnel);
|
||||
vec3 rayContrib = F;
|
||||
|
||||
// float NdotV = clamp(normalize(dot(np3, L))*10000.,0.,1.);
|
||||
bool hasReflections = (f0.y * (1.0 - roughness * Roughness_Threshold)) >= 0.0;
|
||||
if (Roughness_Threshold == 1.0){ hasReflections = true; }
|
||||
|
||||
|
||||
// SSR, Sky, and Sun reflections
|
||||
vec4 Reflections = vec4(0.0);
|
||||
vec3 FogReflection = vec3(0.0);
|
||||
#ifdef Screen_Space_Reflections
|
||||
if ( hasReflections ) { // Skip SSR if ray contribution is low
|
||||
|
||||
float rayQuality = reflection_quality;
|
||||
vec3 rtPos = rayTraceSpeculars( mat3(gbufferModelView) * L,fragpos.xyz, noise.b, reflection_quality, hand, reflectLength);
|
||||
|
||||
float LOD = clamp( reflectLength * 6.0 ,0.0,6.0);
|
||||
|
||||
if (rtPos.z < 1. ){ // Reproject on previous frame
|
||||
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rtPos) + 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) {
|
||||
Reflections.a = 1.0;
|
||||
Reflections.rgb = texture2DLod(colortex5,previousPosition.xy,LOD).rgb;
|
||||
SS_Reflections.a = 1.0;
|
||||
SS_Reflections.rgb = texture2DLod(colortex5, previousPosition.xy, LOD).rgb * Metals;
|
||||
}
|
||||
}
|
||||
// make sure it takes the fresnel into account for SSR.
|
||||
SS_Reflections.rgb = mix_vec3(Output, SS_Reflections.rgb, RayContribution);
|
||||
|
||||
// occlude the background with the SSR and write to the final color.
|
||||
Final_Reflection = mix_vec3(Final_Reflection, SS_Reflections.rgb, SS_Reflections.a);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// check if the f0 is within the metal ranges, then tint by albedo if it's true.
|
||||
vec3 Metals = f0.y > 229.5/255.0 ? clamp(albedo + fresnel,0.0,1.0) : vec3(1.0);
|
||||
Reflections.rgb *= Metals;
|
||||
|
||||
#ifdef Sky_reflection
|
||||
// reflect nether fog color instead of a sky.
|
||||
FogReflection = gl_Fog.color.rgb * 0.5 * NetherFog_brightness;
|
||||
FogReflection *= 1.0 + sqrt(roughness) * 15.0; // brighten rough spots for some highlights that look neat
|
||||
FogReflection *= Metals;
|
||||
|
||||
FogReflection = mix(Output, FogReflection, pow(fresnel, 0.2)+0.1); // make sure the background contains the fog reflection.
|
||||
#else
|
||||
FogReflection = Output;
|
||||
// --------------- LIGHTSOURCE REFLECTIONS
|
||||
// slap the main lightsource reflections to the final color.
|
||||
#ifdef LIGHTSOURCE_REFLECTION
|
||||
Lightsource_Reflection = Diffuse * GGX(Normal, -WorldPos, LightPos, Roughness, F0) * Metals;
|
||||
Final_Reflection += Lightsource_Reflection;
|
||||
#endif
|
||||
|
||||
Reflections.rgb = mix(FogReflection, Reflections.rgb, Reflections.a); // make background only where ssr is not.
|
||||
Reflections_Final = mix(Output, Reflections.rgb, luma(rayContrib)); // apply reflections to final scene color.
|
||||
|
||||
#ifdef Rough_reflections
|
||||
Output = hand ? mix_vec3(Output, Reflections_Final, visibilityFactor) : Reflections_Final;
|
||||
#else
|
||||
Output = mix_vec3(Output, Reflections_Final, visibilityFactor);
|
||||
#endif
|
||||
|
||||
// Output = vec3(reflectLength);
|
||||
}
|
||||
|
||||
void MaterialReflections_E(
|
||||
inout vec3 Output,
|
||||
float roughness,
|
||||
vec3 f0,
|
||||
vec3 albedo,
|
||||
vec3 normal,
|
||||
vec3 np3,
|
||||
vec3 fragpos,
|
||||
vec3 noise,
|
||||
bool hand,
|
||||
vec3 lightCol,
|
||||
vec3 lightDir,
|
||||
bool isEntities
|
||||
){
|
||||
vec3 Reflections_Final = Output;
|
||||
float reflectLength = 0.0;
|
||||
|
||||
roughness = unpackRoughness(roughness);
|
||||
f0 = f0.y == 0.0 ? vec3(0.02) : f0;
|
||||
|
||||
// roughness = 0.1;
|
||||
// f0 = vec3(0.9);
|
||||
|
||||
float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0.y) * -4),0,1);
|
||||
|
||||
mat3 basis = CoordBase(normal);
|
||||
vec3 normSpaceView = -np3*basis ;
|
||||
|
||||
// roughness stuff
|
||||
#ifdef Rough_reflections
|
||||
int seed = (frameCounter%40000);
|
||||
vec2 ij = fract(R2_samples_spec(seed) + noise.rg) ;
|
||||
vec3 H = SampleVNDFGGX(normSpaceView, vec2(roughness), ij.xy);
|
||||
|
||||
if(hand) H = normalize(vec3(0.0,0.0,1.0));
|
||||
#else
|
||||
vec3 H = normalize(vec3(0.0,0.0,1.0));
|
||||
#endif
|
||||
|
||||
vec3 Ln = reflect(-normSpaceView, H);
|
||||
vec3 L = basis * Ln;
|
||||
|
||||
// fresnel stuff
|
||||
float fresnel = pow(clamp(1.0 + dot(-Ln, H),0.0,1.0),5.0);
|
||||
vec3 F = mix(f0, vec3(1.0), fresnel);
|
||||
vec3 rayContrib = F;
|
||||
|
||||
// float NdotV = clamp(normalize(dot(np3, L))*10000.,0.,1.);
|
||||
bool hasReflections = (f0.y * (1.0 - roughness * Roughness_Threshold)) >= 0.0;
|
||||
if (Roughness_Threshold == 1.0){ hasReflections = true; }
|
||||
|
||||
|
||||
vec3 Ln_2 = reflect(-normSpaceView, normalize(vec3(0.0,0.0,1.0)));
|
||||
vec3 L_2 = basis * Ln_2;
|
||||
|
||||
vec3 FogReflection = skyCloudsFromTexLOD(L_2, colortex4, sqrt(roughness) * 9.0).rgb / 150.0;
|
||||
FogReflection = mix(FogReflection, lightCol * 2 * clamp(dot(L_2, lightDir),0,1), roughness);
|
||||
|
||||
|
||||
FogReflection *= 1.0 + roughness * 2.0;
|
||||
vec4 Reflections = vec4(0.0);
|
||||
|
||||
#ifdef Screen_Space_Reflections
|
||||
if ( hasReflections ) { // Skip SSR if ray contribution is low
|
||||
|
||||
float rayQuality = reflection_quality;
|
||||
vec3 rtPos = rayTraceSpeculars( mat3(gbufferModelView) * L,fragpos.xyz, noise.b, reflection_quality, hand, reflectLength);
|
||||
|
||||
float LOD = clamp( reflectLength * 6.0 ,0.0,6.0);
|
||||
|
||||
if(hand) LOD = 6.0;
|
||||
if(isEntities) LOD = 4.0;
|
||||
|
||||
if (rtPos.z < 1. ){ // Reproject on previous frame
|
||||
vec3 previousPosition = mat3(gbufferModelViewInverse) * toScreenSpace(rtPos) + 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) {
|
||||
Reflections.a = 1.0;
|
||||
Reflections.rgb = texture2DLod(colortex5,previousPosition.xy,LOD).rgb;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// check if the f0 is within the metal ranges, then tint by albedo if it's true.
|
||||
vec3 Metals = f0.y > 229.5/255.0 ? clamp(albedo + fresnel,0.0,1.0) : vec3(1.0);
|
||||
Reflections.rgb *= Metals;
|
||||
FogReflection *= Metals;
|
||||
|
||||
Reflections.rgb = mix(FogReflection, Reflections.rgb, Reflections.a); // make background only where ssr is not.
|
||||
Reflections_Final = mix(Output, Reflections.rgb, luma(rayContrib)); // apply reflections to final scene color.
|
||||
|
||||
#ifdef Rough_reflections
|
||||
Output = hand ? mix_vec3(Output, Reflections_Final, visibilityFactor) : Reflections_Final;
|
||||
#else
|
||||
Output = mix_vec3(Output, Reflections_Final, visibilityFactor);
|
||||
#endif
|
||||
Output = Final_Reflection;
|
||||
}
|
@ -171,8 +171,6 @@ vec3 Cloud_lighting(
|
||||
vec3 moonLighting = exp(MoonShadowing * coeeff/4 + powder) * moonContribution;
|
||||
|
||||
return skyLighting + moonLighting + sunLighting ;
|
||||
|
||||
// return skyLighting;
|
||||
}
|
||||
|
||||
|
||||
@ -193,13 +191,6 @@ float CustomPhase(float LightPos, float S_1, float S_2){
|
||||
return A;
|
||||
}
|
||||
|
||||
float PhaseHG(float cosTheta, float g) {
|
||||
float denom = 1 + g * g + 2 * g * cosTheta;
|
||||
const float Inv4Pi = 0.07957747154594766788;
|
||||
|
||||
return Inv4Pi * (1 - g * g) / (denom * sqrt(denom));
|
||||
}
|
||||
|
||||
uniform vec3 lightningEffect;
|
||||
|
||||
vec4 renderClouds(
|
||||
@ -299,7 +290,6 @@ vec4 renderClouds(
|
||||
Sunlight += HighAlt_shadow;
|
||||
#endif
|
||||
|
||||
// float phase = PhaseHG(-SdotV, (1.0-cumulus));
|
||||
|
||||
float ambientlightshadow = 1.0 - clamp(exp((progress_view.y - (MaxCumulusHeight - 50)) / 100.0),0.0,1.0) ;
|
||||
|
||||
|
Reference in New Issue
Block a user