mirror of
https://github.com/X0nk/Bliss-Shader.git
synced 2025-06-22 00:37:35 +08:00
do stupid thing
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
|
||||
varying vec4 lmtexcoord;
|
||||
varying vec4 color;
|
||||
flat varying float exposure;
|
||||
|
||||
#ifdef LINES
|
||||
flat varying int SELECTION_BOX;
|
||||
@ -34,7 +35,6 @@ uniform int isEyeInWater;
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D noisetex;
|
||||
uniform sampler2D colortex4;
|
||||
|
||||
#ifdef IS_LPV_ENABLED
|
||||
uniform sampler3D texLpv1;
|
||||
uniform sampler3D texLpv2;
|
||||
@ -118,6 +118,135 @@ float encodeVec2(float x,float y){
|
||||
}
|
||||
|
||||
|
||||
|
||||
// #undef BASIC_SHADOW_FILTER
|
||||
#ifdef OVERWORLD_SHADER
|
||||
float ComputeShadowMap(inout vec3 directLightColor, vec3 playerPos, float maxDistFade){
|
||||
|
||||
if(maxDistFade <= 0.0) return 1.0;
|
||||
|
||||
// setup shadow projection
|
||||
vec3 projectedShadowPosition = mat3(shadowModelView) * playerPos + shadowModelView[3].xyz;
|
||||
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
|
||||
|
||||
// un-distort
|
||||
#ifdef DISTORT_SHADOWMAP
|
||||
float distortFactor = calcDistort(projectedShadowPosition.xy);
|
||||
projectedShadowPosition.xy *= distortFactor;
|
||||
#else
|
||||
float distortFactor = 1.0;
|
||||
#endif
|
||||
|
||||
// hamburger
|
||||
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
|
||||
|
||||
float shadowmap = 0.0;
|
||||
vec3 translucentTint = vec3(0.0);
|
||||
|
||||
#ifdef TRANSLUCENT_COLORED_SHADOWS
|
||||
|
||||
// determine when opaque shadows are overlapping translucent shadows by getting the difference of opaque depth and translucent depth
|
||||
float shadowDepthDiff = pow(clamp((shadow2D(shadowtex1, projectedShadowPosition).x - projectedShadowPosition.z) * 2.0,0.0,1.0),2.0);
|
||||
|
||||
// get opaque shadow data to get opaque data from translucent shadows.
|
||||
float opaqueShadow = shadow2D(shadowtex0, projectedShadowPosition).x;
|
||||
shadowmap += max(opaqueShadow, shadowDepthDiff);
|
||||
|
||||
// get translucent shadow data
|
||||
vec4 translucentShadow = texture2D(shadowcolor0, projectedShadowPosition.xy);
|
||||
|
||||
// this curve simply looked the nicest. it has no other meaning.
|
||||
float shadowAlpha = pow(1.0 - pow(translucentShadow.a,5.0),0.2);
|
||||
|
||||
// normalize the color to remove luminance, and keep the hue. remove all opaque color.
|
||||
// mulitply shadow alpha to shadow color, but only on surfaces facing the lightsource. this is a tradeoff to protect subsurface scattering's colored shadow tint from shadow bias on the back of the caster.
|
||||
translucentShadow.rgb = max(normalize(translucentShadow.rgb + 0.0001), max(opaqueShadow, 1.0-shadowAlpha)) * shadowAlpha;
|
||||
|
||||
// make it such that full alpha areas that arent in a shadow have a value of 1.0 instead of 0.0
|
||||
translucentTint += mix(translucentShadow.rgb, vec3(1.0), opaqueShadow*shadowDepthDiff);
|
||||
|
||||
#else
|
||||
shadowmap += shadow2D(shadow, projectedShadowPosition).x;
|
||||
#endif
|
||||
|
||||
#ifdef TRANSLUCENT_COLORED_SHADOWS
|
||||
// tint the lightsource color with the translucent shadow color
|
||||
directLightColor *= mix(vec3(1.0), translucentTint.rgb, maxDistFade);
|
||||
#endif
|
||||
|
||||
return mix(1.0, shadowmap, maxDistFade);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined DAMAGE_BLOCK_EFFECT && defined POM
|
||||
#extension GL_ARB_shader_texture_lod : enable
|
||||
|
||||
mat3 inverseMatrix(mat3 m) {
|
||||
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
|
||||
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
|
||||
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
|
||||
|
||||
float b01 = a22 * a11 - a12 * a21;
|
||||
float b11 = -a22 * a10 + a12 * a20;
|
||||
float b21 = a21 * a10 - a11 * a20;
|
||||
|
||||
float det = a00 * b01 + a01 * b11 + a02 * b21;
|
||||
|
||||
return mat3(b01, (-a22 * a01 + a02 * a21), (a12 * a01 - a02 * a11),
|
||||
b11, (a22 * a00 - a02 * a20), (-a12 * a00 + a02 * a10),
|
||||
b21, (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) / det;
|
||||
}
|
||||
const float MAX_OCCLUSION_DISTANCE = MAX_DIST;
|
||||
const float MIX_OCCLUSION_DISTANCE = MAX_DIST*0.9;
|
||||
const int MAX_OCCLUSION_POINTS = MAX_ITERATIONS;
|
||||
|
||||
varying vec4 vtexcoordam; // .st for add, .pq for mul
|
||||
varying vec4 vtexcoord;
|
||||
|
||||
vec2 dcdx = dFdx(vtexcoord.st*vtexcoordam.pq)*exp2(Texture_MipMap_Bias);
|
||||
vec2 dcdy = dFdy(vtexcoord.st*vtexcoordam.pq)*exp2(Texture_MipMap_Bias);
|
||||
|
||||
|
||||
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
|
||||
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
|
||||
|
||||
uniform mat4 gbufferProjection;
|
||||
|
||||
vec3 toClipSpace3(vec3 viewSpacePosition) {
|
||||
return projMAD(gbufferProjection, viewSpacePosition) / -viewSpacePosition.z * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
flat varying vec3 WsunVec2;
|
||||
const float mincoord = 1.0/4096.0;
|
||||
const float maxcoord = 1.0-mincoord;
|
||||
|
||||
uniform sampler2D normals;
|
||||
varying vec4 tangent;
|
||||
varying vec4 normalMat;
|
||||
|
||||
vec4 readNormal(in vec2 coord)
|
||||
{
|
||||
return texture2DGradARB(normals,fract(coord)*vtexcoordam.pq+vtexcoordam.st,dcdx,dcdy);
|
||||
}
|
||||
vec4 readTexture(in vec2 coord)
|
||||
{
|
||||
return texture2DGradARB(texture,fract(coord)*vtexcoordam.pq+vtexcoordam.st,dcdx,dcdy);
|
||||
}
|
||||
#endif
|
||||
uniform float near;
|
||||
// uniform float far;
|
||||
float ld(float dist) {
|
||||
return (2.0 * near) / (far + near - dist * (far - near));
|
||||
}
|
||||
|
||||
vec3 texture2D_POMSwitch(
|
||||
sampler2D sampler,
|
||||
vec2 lightmapCoord,
|
||||
vec4 dcdxdcdy
|
||||
){
|
||||
return texture2DGradARB(sampler, lightmapCoord, dcdxdcdy.xy, dcdxdcdy.zw).rgb;
|
||||
}
|
||||
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -132,6 +261,73 @@ float encodeVec2(float x,float y){
|
||||
|
||||
void main() {
|
||||
|
||||
#ifdef DAMAGE_BLOCK_EFFECT
|
||||
vec2 adjustedTexCoord = lmtexcoord.xy;
|
||||
#ifdef POM
|
||||
vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(0.0));
|
||||
vec3 worldpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition;
|
||||
|
||||
vec3 normal = normalMat.xyz;
|
||||
vec3 tangent2 = normalize(cross(tangent.rgb,normal)*tangent.w);
|
||||
mat3 tbnMatrix = mat3(tangent.x, tangent2.x, normal.x,
|
||||
tangent.y, tangent2.y, normal.y,
|
||||
tangent.z, tangent2.z, normal.z);
|
||||
|
||||
adjustedTexCoord = fract(vtexcoord.st)*vtexcoordam.pq+vtexcoordam.st;
|
||||
vec3 viewVector = normalize(tbnMatrix*fragpos);
|
||||
|
||||
float dist = length(fragpos);
|
||||
|
||||
float maxdist = MAX_OCCLUSION_DISTANCE;
|
||||
|
||||
// float depth = gl_FragCoord.z;
|
||||
if (dist < maxdist) {
|
||||
|
||||
float depthmap = readNormal(vtexcoord.st).a;
|
||||
float used_POM_DEPTH = 1.0;
|
||||
|
||||
if ( viewVector.z < 0.0 && depthmap < 0.9999 && depthmap > 0.00001) {
|
||||
|
||||
#ifdef Adaptive_Step_length
|
||||
vec3 interval = (viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS * POM_DEPTH) * clamp(1.0-pow(depthmap,2),0.1,1.0);
|
||||
used_POM_DEPTH = 1.0;
|
||||
#else
|
||||
vec3 interval = viewVector.xyz/-viewVector.z/ MAX_OCCLUSION_POINTS*POM_DEPTH;
|
||||
#endif
|
||||
vec3 coord = vec3(vtexcoord.st, 1.0);
|
||||
|
||||
coord += interval * used_POM_DEPTH;
|
||||
|
||||
float sumVec = 0.5;
|
||||
for (int loopCount = 0; (loopCount < MAX_OCCLUSION_POINTS) && (1.0 - POM_DEPTH + POM_DEPTH * readNormal(coord.st).a ) < coord.p && coord.p >= 0.0; ++loopCount) {
|
||||
coord = coord + interval * used_POM_DEPTH;
|
||||
sumVec += used_POM_DEPTH;
|
||||
}
|
||||
|
||||
if (coord.t < mincoord) {
|
||||
if (readTexture(vec2(coord.s,mincoord)).a == 0.0) {
|
||||
coord.t = mincoord;
|
||||
discard;
|
||||
}
|
||||
}
|
||||
|
||||
adjustedTexCoord = mix(fract(coord.st)*vtexcoordam.pq+vtexcoordam.st, adjustedTexCoord, max(dist-MIX_OCCLUSION_DISTANCE,0.0)/(MAX_OCCLUSION_DISTANCE-MIX_OCCLUSION_DISTANCE));
|
||||
|
||||
// vec3 truePos = fragpos + sumVec*inverseMatrix(tbnMatrix)*interval;
|
||||
|
||||
// depth = toClipSpace3(truePos).z;
|
||||
}
|
||||
}
|
||||
|
||||
vec3 Albedo = toLinear(texture2D_POMSwitch(texture, adjustedTexCoord.xy, vec4(dcdx,dcdy)));
|
||||
#else
|
||||
vec3 Albedo = toLinear(texture2D(texture, adjustedTexCoord.xy).rgb);
|
||||
#endif
|
||||
|
||||
gl_FragData[0] = vec4(encodeVec2(vec2(0.5)), encodeVec2(Albedo.rg), encodeVec2(vec2(Albedo.b,0.02)), 1.0);
|
||||
#endif
|
||||
|
||||
#if !defined DAMAGE_BLOCK_EFFECT
|
||||
#ifdef LINES
|
||||
#ifndef SELECT_BOX
|
||||
if(SELECTION_BOX > 0) discard;
|
||||
@ -145,8 +341,9 @@ void main() {
|
||||
|
||||
vec4 TEXTURE = texture2D(texture, lmtexcoord.xy)*color;
|
||||
|
||||
|
||||
|
||||
#ifdef WhiteWorld
|
||||
TEXTURE.rgb = vec3(0.5);
|
||||
#endif
|
||||
|
||||
vec3 Albedo = toLinear(TEXTURE.rgb);
|
||||
|
||||
@ -160,104 +357,77 @@ void main() {
|
||||
lightmap.x = max(lightmap.x, HELD_ITEM_BRIGHTNESS * clamp( pow(max(1.0-length(viewPos)/HANDHELD_LIGHT_RANGE,0.0),1.5),0.0,1.0));
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef WEATHER
|
||||
gl_FragData[1].a = TEXTURE.a; // for bloomy rain and stuff
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef WEATHER
|
||||
#ifndef LINES
|
||||
gl_FragData[0].a = TEXTURE.a;
|
||||
#else
|
||||
gl_FragData[0].a = 1.0;
|
||||
#endif
|
||||
#ifndef BLOOMY_PARTICLES
|
||||
gl_FragData[1].a = 0.0; // for bloomy rain and stuff
|
||||
#endif
|
||||
|
||||
vec3 Direct_lighting = vec3(0.0);
|
||||
vec3 Indirect_lighting = vec3(0.0);
|
||||
|
||||
vec3 MinimumLightColor = vec3(1.0);
|
||||
if(isEyeInWater == 1) MinimumLightColor = vec3(10.0);
|
||||
|
||||
vec3 Torch_Color = vec3(TORCH_R,TORCH_G,TORCH_B);
|
||||
|
||||
|
||||
if(lightmap.x >= 0.9) Torch_Color *= LIT_PARTICLE_BRIGHTNESS;
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
vec3 Shadows = vec3(1.0);
|
||||
|
||||
vec3 feetPlayerPos_shadow = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
|
||||
vec3 projectedShadowPosition = mat3(shadowModelView) * feetPlayerPos_shadow + shadowModelView[3].xyz;
|
||||
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
|
||||
|
||||
//apply distortion
|
||||
#ifdef DISTORT_SHADOWMAP
|
||||
float distortFactor = calcDistort(projectedShadowPosition.xy);
|
||||
projectedShadowPosition.xy *= distortFactor;
|
||||
#else
|
||||
float distortFactor = 1.0;
|
||||
#endif
|
||||
|
||||
//do shadows only if on shadow map
|
||||
if (abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution){
|
||||
Shadows = vec3(0.0);
|
||||
|
||||
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
|
||||
|
||||
#ifdef TRANSLUCENT_COLORED_SHADOWS
|
||||
float opaqueShadow = shadow2D(shadowtex0, projectedShadowPosition).x;
|
||||
Shadows += vec3(opaqueShadow);
|
||||
|
||||
if(shadow2D(shadowtex1, projectedShadowPosition).x > projectedShadowPosition.z){
|
||||
vec4 translucentShadow = texture2D(shadowcolor0, projectedShadowPosition.xy);
|
||||
if(translucentShadow.a < 0.9) Shadows += normalize(translucentShadow.rgb+0.0001) * (1.0-opaqueShadow);
|
||||
}
|
||||
#else
|
||||
Shadows = vec3(shadow2D(shadow, projectedShadowPosition).x);
|
||||
#endif
|
||||
}
|
||||
|
||||
float cloudShadow = GetCloudShadow(feetPlayerPos);
|
||||
|
||||
Direct_lighting = (lightCol.rgb/80.0) * Shadows * cloudShadow;
|
||||
|
||||
|
||||
#ifndef WEATHER
|
||||
#ifndef LINES
|
||||
Direct_lighting *= phaseg(clamp(dot(feetPlayerPos_normalized, WsunVec),0.0,1.0), 0.65)*2 + 0.5;
|
||||
gl_FragData[0].a = TEXTURE.a;
|
||||
#else
|
||||
gl_FragData[0].a = 1.0;
|
||||
#endif
|
||||
#ifndef BLOOMY_PARTICLES
|
||||
gl_FragData[1].a = 0.0; // for bloomy rain and stuff
|
||||
#endif
|
||||
|
||||
vec3 AmbientLightColor = (averageSkyCol_Clouds / 30.0) * 3.0;
|
||||
vec3 Direct_lighting = vec3(0.0);
|
||||
vec3 directLightColor = vec3(0.0);
|
||||
|
||||
vec3 Indirect_lighting = vec3(0.0);
|
||||
vec3 AmbientLightColor = vec3(0.0);
|
||||
vec3 Torch_Color = vec3(TORCH_R,TORCH_G,TORCH_B);
|
||||
vec3 MinimumLightColor = vec3(1.0);
|
||||
|
||||
if(isEyeInWater == 1) MinimumLightColor = vec3(10.0);
|
||||
if(lightmap.x >= 0.9) Torch_Color *= LIT_PARTICLE_BRIGHTNESS;
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
directLightColor = lightCol.rgb/80.0;
|
||||
float Shadows = 1.0;
|
||||
|
||||
vec3 shadowPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
|
||||
|
||||
float shadowMapFalloff = smoothstep(0.0, 1.0, min(max(1.0 - length(shadowPlayerPos) / (shadowDistance+16),0.0)*5.0,1.0));
|
||||
float shadowMapFalloff2 = smoothstep(0.0, 1.0, min(max(1.0 - length(shadowPlayerPos) / (shadowDistance+11),0.0)*5.0,1.0));
|
||||
|
||||
float LM_shadowMapFallback = min(max(lightmap.y-0.8, 0.0) * 25,1.0);
|
||||
|
||||
Shadows = ComputeShadowMap(directLightColor, shadowPlayerPos, shadowMapFalloff);
|
||||
|
||||
Shadows = mix(LM_shadowMapFallback, Shadows, shadowMapFalloff2);
|
||||
|
||||
float cloudShadow = GetCloudShadow(feetPlayerPos);
|
||||
|
||||
Direct_lighting = directLightColor * Shadows * cloudShadow;
|
||||
|
||||
#ifndef LINES
|
||||
Direct_lighting *= phaseg(clamp(dot(feetPlayerPos_normalized, WsunVec),0.0,1.0), 0.65)*2 + 0.5;
|
||||
#endif
|
||||
|
||||
AmbientLightColor = averageSkyCol_Clouds / 30.0;
|
||||
AmbientLightColor *= 2.5;
|
||||
#endif
|
||||
|
||||
#ifdef IS_LPV_ENABLED
|
||||
vec3 lpvPos = GetLpvPosition(feetPlayerPos);
|
||||
#else
|
||||
const vec3 lpvPos = vec3(0.0);
|
||||
#endif
|
||||
|
||||
Indirect_lighting = DoAmbientLightColor(lpvPos, AmbientLightColor, MinimumLightColor, Torch_Color, clamp(lightmap.xy,0,1), exposure);
|
||||
|
||||
#ifdef LINES
|
||||
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * toLinear(color.rgb);
|
||||
#else
|
||||
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * Albedo;
|
||||
#endif
|
||||
|
||||
// distance fade targeting the world border...
|
||||
if(TEXTURE.a < 0.7 && TEXTURE.a > 0.2) gl_FragData[0] *= clamp(1.0 - length(feetPlayerPos) / 100.0 ,0.0,1.0);
|
||||
|
||||
gl_FragData[0].rgb *= 0.1;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef NETHER_SHADER
|
||||
// vec3 AmbientLightColor = skyCloudsFromTexLOD2(vec3( 0, 1, 0), colortex4, 6).rgb / 15;
|
||||
vec3 AmbientLightColor = vec3(0.1);
|
||||
#endif
|
||||
|
||||
#ifdef END_SHADER
|
||||
vec3 AmbientLightColor = vec3(1.0);
|
||||
#endif
|
||||
|
||||
Indirect_lighting = DoAmbientLightColor(feetPlayerPos, AmbientLightColor,MinimumLightColor, Torch_Color, clamp(lightmap.xy,0,1));
|
||||
|
||||
#ifdef LINES
|
||||
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * toLinear(color.rgb);
|
||||
#else
|
||||
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * Albedo;
|
||||
#endif
|
||||
|
||||
#ifdef DAMAGE_BLOCK_EFFECT
|
||||
|
||||
gl_FragData[0] = vec4(0.0, encodeVec2(TEXTURE.rg), encodeVec2(vec2(TEXTURE.b,0.0)), TEXTURE.a);
|
||||
#endif
|
||||
|
||||
// distance fade targeting the world border...
|
||||
if(TEXTURE.a < 0.7 && TEXTURE.a > 0.2) gl_FragData[0] *= clamp(1.0 - length(feetPlayerPos) / 100.0 ,0.0,1.0);
|
||||
#endif
|
||||
}
|
@ -280,12 +280,10 @@ vec4 texture2D_POMSwitch(
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
varying vec3 pos;
|
||||
|
||||
#ifdef HAND
|
||||
/* RENDERTARGETS: 1,7,8,15,2 */
|
||||
#if defined HAND || defined ENTITIES
|
||||
/* RENDERTARGETS:1,7,8,15,2 */
|
||||
#else
|
||||
/* RENDERTARGETS: 1,7,8,15 */
|
||||
/* RENDERTARGETS:1,7,8,15 */
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
@ -312,19 +310,9 @@ void main() {
|
||||
vec3 fragpos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
|
||||
vec3 worldpos = mat3(gbufferModelViewInverse) * fragpos + gbufferModelViewInverse[3].xyz + cameraPosition;
|
||||
|
||||
// #if defined DH_OVERDRAW_PREVENTION && defined DISTANT_HORIZONS
|
||||
// // overdraw prevention
|
||||
// if(clamp(1.0-length(pos.xyz)/max(far - 16.0 * sqrt(interleaved_gradientNoise_temporal()),0.0),0.0,1.0) <= 0.0 ){
|
||||
// discard;
|
||||
// return;
|
||||
// }
|
||||
// #endif
|
||||
|
||||
float torchlightmap = lmtexcoord.z;
|
||||
|
||||
#ifdef Hand_Held_lights
|
||||
|
||||
|
||||
if(HELD_ITEM_BRIGHTNESS > 0.0) torchlightmap = max(torchlightmap, HELD_ITEM_BRIGHTNESS * clamp( pow(max(1.0-length(fragpos)/HANDHELD_LIGHT_RANGE,0.0),1.5),0.0,1.0));
|
||||
|
||||
#ifdef HAND
|
||||
@ -365,7 +353,7 @@ void main() {
|
||||
float used_POM_DEPTH = 1.0;
|
||||
|
||||
if ( viewVector.z < 0.0 && depthmap < 0.9999 && depthmap > 0.00001) {
|
||||
float noise = blueNoise();
|
||||
// float noise = blueNoise();
|
||||
#ifdef Adaptive_Step_length
|
||||
vec3 interval = (viewVector.xyz /-viewVector.z/MAX_OCCLUSION_POINTS * POM_DEPTH) * clamp(1.0-pow(depthmap,2),0.1,1.0);
|
||||
used_POM_DEPTH = 1.0;
|
||||
@ -374,9 +362,9 @@ void main() {
|
||||
#endif
|
||||
vec3 coord = vec3(vtexcoord.st , 1.0);
|
||||
|
||||
coord += interval * noise * used_POM_DEPTH;
|
||||
coord += interval * used_POM_DEPTH;
|
||||
|
||||
float sumVec = noise;
|
||||
float sumVec = 0.5;
|
||||
for (int loopCount = 0; (loopCount < MAX_OCCLUSION_POINTS) && (1.0 - POM_DEPTH + POM_DEPTH * readNormal(coord.st).a ) < coord.p && coord.p >= 0.0; ++loopCount) {
|
||||
coord = coord + interval * used_POM_DEPTH;
|
||||
sumVec += used_POM_DEPTH;
|
||||
@ -392,13 +380,11 @@ void main() {
|
||||
adjustedTexCoord = mix(fract(coord.st)*vtexcoordam.pq+vtexcoordam.st, adjustedTexCoord, max(dist-MIX_OCCLUSION_DISTANCE,0.0)/(MAX_OCCLUSION_DISTANCE-MIX_OCCLUSION_DISTANCE));
|
||||
|
||||
vec3 truePos = fragpos + sumVec*inverseMatrix(tbnMatrix)*interval;
|
||||
// #ifdef Depth_Write_POM
|
||||
gl_FragDepth = toClipSpace3(truePos).z;
|
||||
// #endif
|
||||
|
||||
gl_FragDepth = toClipSpace3(truePos).z;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!ifPOM) adjustedTexCoord = lmtexcoord.xy;
|
||||
|
||||
|
||||
@ -408,7 +394,6 @@ void main() {
|
||||
float textureLOD = bias();
|
||||
vec4 Albedo = texture2D_POMSwitch(texture, adjustedTexCoord.xy, vec4(dcdx,dcdy), ifPOM, textureLOD) * color;
|
||||
|
||||
|
||||
#if defined HAND
|
||||
if (Albedo.a < 0.1) discard;
|
||||
#endif
|
||||
@ -432,7 +417,7 @@ void main() {
|
||||
blockID == BLOCK_SSS_STRONG || blockID == BLOCK_SSS_WEAK ||
|
||||
blockID >= 10 && blockId < 80
|
||||
) {
|
||||
// IR Reflective (Pink-red)
|
||||
// IR Reflective (Pink-red)
|
||||
Albedo.rgb = mix(vec3(gray), aerochrome_color, 0.7);
|
||||
}
|
||||
else if(blockID == BLOCK_GRASS) {
|
||||
@ -462,10 +447,14 @@ void main() {
|
||||
if (Albedo.a > 0.1){
|
||||
Albedo.a = 0.75;
|
||||
gl_FragData[4].a = 0.0;
|
||||
} else Albedo.a = 1.0;
|
||||
|
||||
} else {
|
||||
Albedo.a = 1.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENTITIES
|
||||
gl_FragData[4].a = 0.0;
|
||||
#endif
|
||||
|
||||
//////////////////////////////// ////////////////////////////////
|
||||
//////////////////////////////// NORMAL ////////////////////////////////
|
||||
@ -483,15 +472,14 @@ void main() {
|
||||
NormalTex.xy = NormalTex.xy * 2.0-1.0;
|
||||
NormalTex.z = sqrt(max(1.0 - dot(NormalTex.xy, NormalTex.xy), 0.0));
|
||||
|
||||
#if defined HEIGTHMAP_DEPTH_OFFSET && !defined HAND
|
||||
gl_FragDepth = gl_FragCoord.z;
|
||||
vec3 truePos = fragpos;
|
||||
truePos.z -= Heightmap * POM_DEPTH * (1.0 + ld(truePos.z));
|
||||
// #if defined HEIGTHMAP_DEPTH_OFFSET && !defined HAND
|
||||
// gl_FragDepth = gl_FragCoord.z;
|
||||
// vec3 truePos = fragpos;
|
||||
// truePos.z -= Heightmap * POM_DEPTH * (1.0 + ld(truePos.z));
|
||||
|
||||
gl_FragDepth = toClipSpace3(truePos).z;
|
||||
#endif
|
||||
// gl_FragDepth = toClipSpace3(truePos).z;
|
||||
// #endif
|
||||
|
||||
|
||||
normal = applyBump(tbnMatrix, NormalTex.xyz, mix(1.0,1-Puddle_shape,rainfall) );
|
||||
// normal = applyBump(tbnMatrix, NormalTex.xyz, 0.0);
|
||||
#endif
|
||||
@ -572,10 +560,6 @@ void main() {
|
||||
// apply noise to lightmaps to reduce banding.
|
||||
vec2 PackLightmaps = vec2(torchlightmap, lmtexcoord.w);
|
||||
|
||||
#if !defined ENTITIES && !defined HAND
|
||||
// PackLightmaps = clamp(PackLightmaps*blueNoise()*0.05 + PackLightmaps,0.0,1.0);
|
||||
#endif
|
||||
|
||||
vec4 data1 = clamp( encode(viewToWorld(normal), PackLightmaps), 0.0, 1.0);
|
||||
// gl_FragData[0] = vec4(.0);
|
||||
gl_FragData[0] = vec4(encodeVec2(Albedo.x,data1.x), encodeVec2(Albedo.y,data1.y), encodeVec2(Albedo.z,data1.z), encodeVec2(data1.w,Albedo.w));
|
||||
|
@ -185,26 +185,18 @@ float luma(vec3 color) {
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
|
||||
varying vec3 pos;
|
||||
void main() {
|
||||
|
||||
gl_Position = ftransform();
|
||||
|
||||
|
||||
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
|
||||
|
||||
pos = position;
|
||||
|
||||
/////// ----- COLOR STUFF ----- ///////
|
||||
color = gl_Color;
|
||||
|
||||
VanillaAO = 1.0 - clamp(color.a,0,1);
|
||||
if (color.a < 0.3) color.a = 1.0; // fix vanilla ao on some custom block models.
|
||||
|
||||
|
||||
|
||||
|
||||
/////// ----- RANDOM STUFF ----- ///////
|
||||
// gl_TextureMatrix[0] for animated things like charged creepers
|
||||
lmtexcoord.xy = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
|
||||
@ -217,7 +209,8 @@ void main() {
|
||||
vtexcoord.xy = sign(texcoordminusmid)*0.5+0.5;
|
||||
// #endif
|
||||
|
||||
vec2 lmcoord = gl_MultiTexCoord1.xy / 255.0; // is this even correct? lol'
|
||||
|
||||
vec2 lmcoord = gl_MultiTexCoord1.xy / 240.0;
|
||||
lmtexcoord.zw = lmcoord;
|
||||
|
||||
|
||||
@ -239,7 +232,6 @@ void main() {
|
||||
SIGN = 0;
|
||||
|
||||
#ifdef WORLD
|
||||
// disallow POM to work on signs.
|
||||
if(blockEntityId == BLOCK_SIGN) SIGN = 1;
|
||||
|
||||
if(blockEntityId == BLOCK_END_PORTAL) PORTAL = 1;
|
||||
@ -257,7 +249,6 @@ void main() {
|
||||
// if( dot(gl_Color.rgb, vec3(1.0/3.0)) < 1.0) NameTags = 1;
|
||||
// if(gl_Color.a < 1.0) NameTags = 1;
|
||||
// if(gl_Color.a >= 0.24 && gl_Color.a <= 0.25 ) gl_Position = vec4(10,10,10,1);
|
||||
|
||||
if(entityId == ENTITY_SSS_MEDIUM || entityId == ENTITY_SSS_WEAK || entityId == ENTITY_PLAYER || entityId == 2468) normalMat.a = 0.45;
|
||||
|
||||
#endif
|
||||
@ -265,8 +256,8 @@ void main() {
|
||||
if(mc_Entity.x == BLOCK_AIR_WAVING) normalMat.a = 0.55;
|
||||
|
||||
/////// ----- EMISSIVE STUFF ----- ///////
|
||||
EMISSIVE = 0.0;
|
||||
LIGHTNING = 0;
|
||||
EMISSIVE = 0.0;
|
||||
LIGHTNING = 0;
|
||||
// if(NameTags > 0) EMISSIVE = 0.9;
|
||||
|
||||
// normal block lightsources
|
||||
@ -281,18 +272,16 @@ void main() {
|
||||
#endif
|
||||
|
||||
/////// ----- SSS STUFF ----- ///////
|
||||
SSSAMOUNT = 0.0;
|
||||
SSSAMOUNT = 0.0;
|
||||
|
||||
HELD_ITEM_BRIGHTNESS = 0.0;
|
||||
|
||||
#ifdef Hand_Held_lights
|
||||
if(heldItemId == ITEM_LIGHT_SOURCES || heldItemId2 == ITEM_LIGHT_SOURCES) HELD_ITEM_BRIGHTNESS = 0.9;
|
||||
if(heldItemId == ITEM_LIGHT_SOURCES || heldItemId2 == ITEM_LIGHT_SOURCES) HELD_ITEM_BRIGHTNESS = 0.9;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WORLD
|
||||
|
||||
|
||||
/////// ----- SSS ON BLOCKS ----- ///////
|
||||
// strong
|
||||
if (
|
||||
@ -311,7 +300,6 @@ void main() {
|
||||
) {
|
||||
SSSAMOUNT = 0.75;
|
||||
}
|
||||
|
||||
// low
|
||||
#ifdef MISC_BLOCK_SSS
|
||||
if(mc_Entity.x == BLOCK_SSS_WEIRD || mc_Entity.x == BLOCK_GRASS) SSSAMOUNT = 0.5; // weird SSS on blocks like grass and stuff
|
||||
@ -352,7 +340,7 @@ void main() {
|
||||
mc_Entity.x == BLOCK_SAPLING
|
||||
) && istopv && abs(position.z) < 64.0
|
||||
) {
|
||||
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz + cameraPosition;
|
||||
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz + cameraPosition;
|
||||
worldpos.xyz += calcMovePlants(worldpos.xyz)*lmtexcoord.w - cameraPosition;
|
||||
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
|
||||
}
|
||||
@ -363,9 +351,7 @@ void main() {
|
||||
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
|
||||
}
|
||||
#endif
|
||||
|
||||
gl_Position = toClipSpace3(position);
|
||||
|
||||
#endif
|
||||
|
||||
#if defined Seasons && defined WORLD && !defined ENTITIES && !defined BLOCKENTITIES && !defined HAND
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
varying vec4 lmtexcoord;
|
||||
varying vec4 color;
|
||||
uniform vec4 entityColor;
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
const bool shadowHardwareFiltering = true;
|
||||
@ -26,14 +27,7 @@ varying vec4 color;
|
||||
flat varying vec4 lightCol;
|
||||
#endif
|
||||
|
||||
#ifdef BLOCKENTITIES
|
||||
#undef WATER_REFLECTIONS
|
||||
#endif
|
||||
|
||||
#ifdef ENTITIES
|
||||
#undef WATER_BACKGROUND_SPECULAR
|
||||
#undef SCREENSPACE_REFLECTIONS
|
||||
#endif
|
||||
|
||||
flat varying float HELD_ITEM_BRIGHTNESS;
|
||||
|
||||
@ -41,10 +35,14 @@ const bool colortex4MipmapEnabled = true;
|
||||
uniform sampler2D noisetex;
|
||||
uniform sampler2D depthtex1;
|
||||
uniform sampler2D depthtex0;
|
||||
#ifdef DISTANT_HORIZONS
|
||||
uniform sampler2D dhDepthTex1;
|
||||
#endif
|
||||
uniform sampler2D colortex7;
|
||||
uniform sampler2D colortex12;
|
||||
uniform sampler2D colortex14;
|
||||
uniform sampler2D colortex5;
|
||||
uniform sampler2D colortex6;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D specular;
|
||||
@ -61,6 +59,7 @@ varying vec3 binormal;
|
||||
varying vec3 flatnormal;
|
||||
|
||||
|
||||
flat varying float exposure;
|
||||
|
||||
|
||||
uniform vec3 sunVec;
|
||||
@ -114,26 +113,22 @@ uniform vec3 nsunColor;
|
||||
#endif
|
||||
|
||||
#include "/lib/diffuse_lighting.glsl"
|
||||
|
||||
float blueNoise(){
|
||||
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
|
||||
}
|
||||
float R2_dither(){
|
||||
vec2 alpha = vec2(0.75487765, 0.56984026);
|
||||
return fract(alpha.x * gl_FragCoord.x + alpha.y * gl_FragCoord.y + 1.0/1.6180339887 * frameCounter) ;
|
||||
float interleaved_gradientNoise_temporal(){
|
||||
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521);
|
||||
}
|
||||
float interleaved_gradientNoise(){
|
||||
vec2 coord = gl_FragCoord.xy + (frameCounter%40000);
|
||||
// vec2 coord = gl_FragCoord.xy + frameTimeCounter;
|
||||
// vec2 coord = gl_FragCoord.xy;
|
||||
float noise = fract( 52.9829189 * fract( (coord.x * 0.06711056) + (coord.y * 0.00583715)) );
|
||||
return noise ;
|
||||
}
|
||||
float interleaved_gradientNoise(float temporal){
|
||||
vec2 coord = gl_FragCoord.xy;
|
||||
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y)+temporal);
|
||||
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
|
||||
return noise;
|
||||
}
|
||||
float R2_dither(){
|
||||
vec2 coord = gl_FragCoord.xy + (frameCounter%40000) * 2.0;
|
||||
vec2 alpha = vec2(0.75487765, 0.56984026);
|
||||
return fract(alpha.x * coord.x + alpha.y * coord.y ) ;
|
||||
}
|
||||
|
||||
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
|
||||
vec2(-1.,3.)/8.,
|
||||
@ -150,35 +145,26 @@ const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
|
||||
|
||||
|
||||
|
||||
#define PW_DEPTH 1.0 //[0.5 1.0 1.5 2.0 2.5 3.0]
|
||||
#define PW_POINTS 1 //[2 4 6 8 16 32]
|
||||
#define PW_DEPTH 1.5 //[0.5 1.0 1.5 2.0 2.5 3.0]
|
||||
#define PW_POINTS 2 //[2 4 6 8 16 32]
|
||||
|
||||
varying vec3 viewVector;
|
||||
vec3 getParallaxDisplacement(vec3 posxz) {
|
||||
|
||||
vec3 parallaxPos = posxz;
|
||||
vec2 vec = viewVector.xy * (1.0 / float(PW_POINTS)) * 22.0;
|
||||
float waterHeight = getWaterHeightmap(posxz.xz);
|
||||
parallaxPos.xz += waterHeight * vec;
|
||||
vec2 vec = viewVector.xy * (1.0 / float(PW_POINTS)) * 22.0 * PW_DEPTH;
|
||||
// float waterHeight = (1.0 - (getWaterHeightmap(posxz.xz)*0.5+0.5)) * 2.0 - 1.0;
|
||||
float waterHeight = getWaterHeightmap(posxz.xz) * 2.0;
|
||||
parallaxPos.xz -= waterHeight * vec;
|
||||
|
||||
return parallaxPos;
|
||||
}
|
||||
|
||||
// vec3 getParallaxDisplacement(vec3 posxz,float bumpmult,vec3 viewVec) {
|
||||
|
||||
// vec3 parallaxPos = posxz;
|
||||
// vec2 vec = viewVector.xy * (1.0 / float(PW_POINTS)) * 22.0 * PW_DEPTH;
|
||||
// float waterHeight = getWaterHeightmap(posxz.xz) ;
|
||||
|
||||
// parallaxPos.xz += waterHeight * vec;
|
||||
|
||||
// return parallaxPos;
|
||||
|
||||
// }
|
||||
|
||||
vec3 applyBump(mat3 tbnMatrix, vec3 bump, float puddle_values){
|
||||
float bumpmult = 1;
|
||||
float bumpmult = puddle_values;
|
||||
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
|
||||
//
|
||||
return normalize(bump*tbnMatrix);
|
||||
}
|
||||
|
||||
@ -275,12 +261,8 @@ vec3 rayTrace(vec3 dir, vec3 position,float dither, float fresnel, bool inwater)
|
||||
|
||||
// decode depth buffer
|
||||
// float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4),0).w/65000.0);
|
||||
#ifdef HAND
|
||||
vec2 testthing = spos.xy*texelSize; // fix for ssr on hand
|
||||
#else
|
||||
vec2 testthing = spos.xy/texelSize/4.0;
|
||||
#endif
|
||||
float sp = sqrt((texelFetch2D(colortex4,ivec2(testthing),0).a)/65000.0);
|
||||
|
||||
float sp = sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4.0),0).a/65000.0);
|
||||
sp = invLinZ(sp);
|
||||
|
||||
if(sp <= max(maxZ,minZ) && sp >= min(maxZ,minZ)) return vec3(spos.xy/RENDER_SCALE,sp);
|
||||
@ -299,8 +281,8 @@ vec3 rayTrace(vec3 dir, vec3 position,float dither, float fresnel, bool inwater)
|
||||
return vec3(1.1);
|
||||
}
|
||||
|
||||
vec3 GGX (vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
|
||||
r = pow(r,2.5);
|
||||
float GGX(vec3 n, vec3 v, vec3 l, float r, float f0) {
|
||||
r = max(pow(r,2.5), 0.0001);
|
||||
|
||||
vec3 h = l + v;
|
||||
float hn = inversesqrt(dot(h, h));
|
||||
@ -310,94 +292,202 @@ vec3 GGX (vec3 n, vec3 v, vec3 l, float r, vec3 F0) {
|
||||
float dotNL = clamp(dot(n,l),0.,1.);
|
||||
float dotNHsq = dotNH*dotNH;
|
||||
|
||||
float denom = dotNHsq * r - dotNHsq + 1.0;
|
||||
float denom = dotNHsq * r - dotNHsq + 1.;
|
||||
float D = r / (3.141592653589793 * denom * denom);
|
||||
vec3 F = 0.2 + (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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uniform float dhFarPlane;
|
||||
|
||||
#include "/lib/DistantHorizons_projections.glsl"
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
float darkSpecularHighlight(vec3 playerPos, vec3 normal, float roughness, float f0){
|
||||
|
||||
roughness = max(pow(1.0 - roughness, 2.0),0.002);
|
||||
|
||||
float distanceFalloff = clamp( exp(-7.0 * (length(playerPos) / 16.0)) ,0.0,1.0);
|
||||
|
||||
float NdotP = clamp(1.0 + dot(normal, normalize(playerPos)),0.0,1.0);
|
||||
// #undef BASIC_SHADOW_FILTER
|
||||
|
||||
float specularHighlight = exp( -(1.0 / roughness) * NdotP ) * f0;
|
||||
#ifdef OVERWORLD_SHADER
|
||||
float ComputeShadowMap(inout vec3 directLightColor, vec3 playerPos, float maxDistFade, float noise){
|
||||
|
||||
return specularHighlight * distanceFalloff;
|
||||
if(maxDistFade <= 0.0) return 1.0;
|
||||
|
||||
// setup shadow projection
|
||||
vec3 projectedShadowPosition = mat3(shadowModelView) * playerPos + shadowModelView[3].xyz;
|
||||
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
|
||||
|
||||
// un-distort
|
||||
#ifdef DISTORT_SHADOWMAP
|
||||
float distortFactor = calcDistort(projectedShadowPosition.xy);
|
||||
projectedShadowPosition.xy *= distortFactor;
|
||||
#else
|
||||
float distortFactor = 1.0;
|
||||
#endif
|
||||
|
||||
// hamburger
|
||||
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
|
||||
|
||||
float shadowmap = 0.0;
|
||||
vec3 translucentTint = vec3(0.0);
|
||||
|
||||
#ifndef HAND
|
||||
projectedShadowPosition.z -= 0.0001;
|
||||
#endif
|
||||
|
||||
#if defined ENTITIES
|
||||
projectedShadowPosition.z -= 0.0002;
|
||||
#endif
|
||||
|
||||
#ifdef BASIC_SHADOW_FILTER
|
||||
int samples = int(SHADOW_FILTER_SAMPLE_COUNT * 0.5);
|
||||
float rdMul = 14.0*distortFactor*d0*k/shadowMapResolution;
|
||||
|
||||
for(int i = 0; i < samples; i++){
|
||||
vec2 offsetS = tapLocation_simple(i, 7, 9, noise) *0.5;
|
||||
projectedShadowPosition.xy += rdMul*offsetS;
|
||||
#else
|
||||
int samples = 1;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef TRANSLUCENT_COLORED_SHADOWS
|
||||
|
||||
// determine when opaque shadows are overlapping translucent shadows by getting the difference of opaque depth and translucent depth
|
||||
float shadowDepthDiff = pow(clamp((shadow2D(shadowtex1, projectedShadowPosition).x - projectedShadowPosition.z) * 2.0,0.0,1.0),2.0);
|
||||
|
||||
// get opaque shadow data to get opaque data from translucent shadows.
|
||||
float opaqueShadow = shadow2D(shadowtex0, projectedShadowPosition).x;
|
||||
shadowmap += max(opaqueShadow, shadowDepthDiff);
|
||||
|
||||
// get translucent shadow data
|
||||
vec4 translucentShadow = texture2D(shadowcolor0, projectedShadowPosition.xy);
|
||||
|
||||
// this curve simply looked the nicest. it has no other meaning.
|
||||
float shadowAlpha = pow(1.0 - pow(translucentShadow.a,5.0),0.2);
|
||||
|
||||
// normalize the color to remove luminance, and keep the hue. remove all opaque color.
|
||||
// mulitply shadow alpha to shadow color, but only on surfaces facing the lightsource. this is a tradeoff to protect subsurface scattering's colored shadow tint from shadow bias on the back of the caster.
|
||||
translucentShadow.rgb = max(normalize(translucentShadow.rgb + 0.0001), max(opaqueShadow, 1.0-shadowAlpha)) * shadowAlpha;
|
||||
|
||||
// make it such that full alpha areas that arent in a shadow have a value of 1.0 instead of 0.0
|
||||
translucentTint += mix(translucentShadow.rgb, vec3(1.0), opaqueShadow*shadowDepthDiff);
|
||||
|
||||
#else
|
||||
shadowmap += shadow2D(shadow, projectedShadowPosition).x;
|
||||
#endif
|
||||
|
||||
#ifdef BASIC_SHADOW_FILTER
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TRANSLUCENT_COLORED_SHADOWS
|
||||
// tint the lightsource color with the translucent shadow color
|
||||
directLightColor *= mix(vec3(1.0), translucentTint.rgb / samples, maxDistFade);
|
||||
#endif
|
||||
|
||||
return mix(1.0, shadowmap / samples, maxDistFade);
|
||||
}
|
||||
#endif
|
||||
|
||||
void convertHandDepth(inout float depth) {
|
||||
float ndcDepth = depth * 2.0 - 1.0;
|
||||
ndcDepth /= MC_HAND_DEPTH;
|
||||
depth = ndcDepth * 0.5 + 0.5;
|
||||
}
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
|
||||
|
||||
uniform vec4 entityColor;
|
||||
/* RENDERTARGETS:2,7,11,14 */
|
||||
|
||||
|
||||
void main() {
|
||||
if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 ) {
|
||||
|
||||
vec3 FragCoord = gl_FragCoord.xyz;
|
||||
|
||||
#ifdef HAND
|
||||
convertHandDepth(FragCoord.z);
|
||||
#endif
|
||||
|
||||
vec2 tempOffset = offsets[framemod8];
|
||||
|
||||
vec3 viewPos = toScreenSpace(FragCoord*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5, 0.0));
|
||||
|
||||
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos;
|
||||
|
||||
vec3 viewPos = toScreenSpace(gl_FragCoord.xyz*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5,0.0));
|
||||
|
||||
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////// MATERIAL MASKS ////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
float MATERIALS = normalMat.w;
|
||||
|
||||
////////////////////////////////
|
||||
//////////////////////////////// ALBEDO
|
||||
////////////////////////////////
|
||||
// 1.0 = water mask
|
||||
// 0.9 = entity mask
|
||||
// 0.8 = reflective entities
|
||||
// 0.7 = reflective blocks
|
||||
// 0.1 = hand mask
|
||||
|
||||
#ifdef HAND
|
||||
MATERIALS = 0.1;
|
||||
#endif
|
||||
|
||||
// bool isHand = abs(MATERIALS - 0.1) < 0.01;
|
||||
bool isWater = MATERIALS > 0.99;
|
||||
bool isReflectiveEntity = abs(MATERIALS - 0.8) < 0.01;
|
||||
bool isReflective = abs(MATERIALS - 0.7) < 0.01 || isWater || isReflectiveEntity;
|
||||
bool isEntity = abs(MATERIALS - 0.9) < 0.01 || isReflectiveEntity;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////// ALBEDO /////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
gl_FragData[0] = texture2D(texture, lmtexcoord.xy, Texture_MipMap_Bias) * color;
|
||||
|
||||
|
||||
|
||||
vec3 Albedo = toLinear(gl_FragData[0].rgb);
|
||||
float UnchangedAlpha = gl_FragData[0].a;
|
||||
|
||||
float iswater = normalMat.w;
|
||||
|
||||
#ifdef HAND
|
||||
iswater = 0.1;
|
||||
|
||||
#ifdef WhiteWorld
|
||||
gl_FragData[0].rgb = vec3(0.5);
|
||||
gl_FragData[0].a = 1.0;
|
||||
#endif
|
||||
|
||||
#ifdef Vanilla_like_water
|
||||
if (iswater > 0.95){
|
||||
Albedo *= sqrt(luma(Albedo));
|
||||
// Albedo = toLinear( gl_FragData[0].rgb * sqrt(luma(gl_FragData[0].rgb)));
|
||||
}
|
||||
#else
|
||||
if (iswater > 0.95){
|
||||
Albedo = vec3(0.0);
|
||||
gl_FragData[0].a = 1.0/255.0;
|
||||
}
|
||||
vec3 Albedo = toLinear(gl_FragData[0].rgb);
|
||||
|
||||
#ifndef WhiteWorld
|
||||
#ifdef Vanilla_like_water
|
||||
if (isWater) Albedo *= sqrt(luma(Albedo));
|
||||
#else
|
||||
if (isWater){
|
||||
Albedo = vec3(0.0);
|
||||
gl_FragData[0].a = 1.0/255.0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ENTITIES
|
||||
Albedo.rgb = mix(Albedo.rgb, entityColor.rgb, clamp(entityColor.a*1.5,0,1));
|
||||
#endif
|
||||
|
||||
vec4 COLORTEST = vec4(Albedo, UnchangedAlpha);
|
||||
vec4 GLASS_TINT_COLORS = vec4(Albedo, UnchangedAlpha);
|
||||
|
||||
#ifdef BIOME_TINT_WATER
|
||||
if (iswater > 0.95) COLORTEST.rgb = color.rgb;
|
||||
if (isWater) GLASS_TINT_COLORS.rgb = toLinear(color.rgb);
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////// NORMALS ///////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////
|
||||
//////////////////////////////// NORMAL
|
||||
////////////////////////////////
|
||||
|
||||
vec3 normal = normalMat.xyz;
|
||||
vec3 normal = normalMat.xyz; // in viewSpace
|
||||
vec3 worldSpaceNormal = viewToWorld(normal).xyz;
|
||||
vec2 TangentNormal = vec2(0); // for refractions
|
||||
|
||||
vec3 tangent2 = normalize(cross(tangent.rgb,normal)*tangent.w);
|
||||
@ -405,40 +495,44 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
tangent.y, tangent2.y, normal.y,
|
||||
tangent.z, tangent2.z, normal.z);
|
||||
|
||||
vec4 NormalTex = texture2D(normals, lmtexcoord.xy, Texture_MipMap_Bias).rgba;
|
||||
|
||||
vec3 NormalTex = vec3(texture2D(normals, lmtexcoord.xy, Texture_MipMap_Bias).xy,0.0);
|
||||
NormalTex.xy = NormalTex.xy*2.0-1.0;
|
||||
NormalTex.z = clamp(sqrt(1.0 - dot(NormalTex.xy, NormalTex.xy)),0.0,1.0) ;
|
||||
|
||||
// tangent space normals for refraction
|
||||
TangentNormal = NormalTex.xy*0.5+0.5;
|
||||
|
||||
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
|
||||
|
||||
|
||||
#ifndef HAND
|
||||
if (iswater > 0.95){
|
||||
vec3 posxz = feetPlayerPos + cameraPosition;
|
||||
if (isWater){
|
||||
vec3 posxz = (mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz) + cameraPosition;
|
||||
|
||||
// make the waves flow in the direction the water faces, except for perfectly up facing parts.
|
||||
if(abs(worldSpaceNormal.y) < 0.9995) posxz.xz -= (posxz.y + frameTimeCounter*3 * WATER_WAVE_SPEED) * normalize(worldSpaceNormal.xz) ;
|
||||
|
||||
float bumpmult = 1.0;
|
||||
|
||||
posxz.xyz = getParallaxDisplacement(posxz) ;
|
||||
|
||||
posxz.xyz = getParallaxDisplacement(posxz);
|
||||
vec3 bump = normalize(getWaveNormal(posxz, false));
|
||||
|
||||
TangentNormal = (bump.xy/3.0)*0.5+0.5; // tangent space normals for refraction
|
||||
|
||||
float bumpmult = 10.0 * WATER_WAVE_STRENGTH;
|
||||
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
|
||||
normal = normalize(bump * tbnMatrix);
|
||||
|
||||
NormalTex.xyz = bump;
|
||||
|
||||
// tangent space normals for refraction
|
||||
TangentNormal = (bump.xy/3.0)*0.5+0.5;
|
||||
}
|
||||
#endif
|
||||
|
||||
gl_FragData[2] = vec4(encodeVec2(TangentNormal), encodeVec2(COLORTEST.rg), encodeVec2(COLORTEST.ba), UnchangedAlpha);
|
||||
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
|
||||
|
||||
vec3 WS_normal = viewToWorld(normal);
|
||||
////////////////////////////////
|
||||
//////////////////////////////// DIFFUSE LIGHTING
|
||||
////////////////////////////////
|
||||
gl_FragData[2] = vec4(encodeVec2(TangentNormal), encodeVec2(GLASS_TINT_COLORS.rg), encodeVec2(GLASS_TINT_COLORS.ba), 1.0);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////// DIFFUSE LIGHTING //////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
vec2 lightmap = lmtexcoord.zw;
|
||||
|
||||
// lightmap.y = 1.0;
|
||||
|
||||
#ifndef OVERWORLD_SHADER
|
||||
lightmap.y = 1.0;
|
||||
@ -451,127 +545,62 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
vec3 Indirect_lighting = vec3(0.0);
|
||||
vec3 MinimumLightColor = vec3(1.0);
|
||||
if(isEyeInWater == 1) MinimumLightColor = vec3(10.0);
|
||||
|
||||
vec3 Direct_lighting = vec3(0.0);
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
vec3 DirectLightColor = lightCol.rgb/80.0;
|
||||
float NdotL = clamp(dot(normal, normalize(WsunVec*mat3(gbufferModelViewInverse))),0.0,1.0); NdotL = clamp((-15 + NdotL*255.0) / 240.0 ,0.0,1.0);
|
||||
vec3 Shadows = vec3(0.0);
|
||||
bool inShadowmapBounds = false;
|
||||
float Shadows = 1.0;
|
||||
|
||||
vec3 feetPlayerPos_shadow = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
|
||||
float shadowMapFalloff = smoothstep(0.0, 1.0, min(max(1.0 - length(feetPlayerPos) / (shadowDistance+16),0.0)*5.0,1.0));
|
||||
float shadowMapFalloff2 = smoothstep(0.0, 1.0, min(max(1.0 - length(feetPlayerPos) / shadowDistance,0.0)*5.0,1.0));
|
||||
|
||||
// mat4 Custom_ViewMatrix = BuildShadowViewMatrix(LightDir);
|
||||
// vec3 projectedShadowPosition = mat3(Custom_ViewMatrix) * feetPlayerPos_shadow + Custom_ViewMatrix[3].xyz;
|
||||
vec3 projectedShadowPosition = mat3(shadowModelView) * feetPlayerPos_shadow + shadowModelView[3].xyz;
|
||||
projectedShadowPosition = diagonal3(shadowProjection) * projectedShadowPosition + shadowProjection[3].xyz;
|
||||
float LM_shadowMapFallback = min(max(lightmap.y-0.8, 0.0) * 25,1.0);
|
||||
|
||||
//apply distortion
|
||||
#ifdef DISTORT_SHADOWMAP
|
||||
float distortFactor = calcDistort(projectedShadowPosition.xy);
|
||||
projectedShadowPosition.xy *= distortFactor;
|
||||
#else
|
||||
float distortFactor = 1.0;
|
||||
#endif
|
||||
|
||||
bool ShadowBounds = false;
|
||||
if(shadowDistanceRenderMul > 0.0) ShadowBounds = length(feetPlayerPos_shadow) < max(shadowDistance - 20,0.0);
|
||||
|
||||
if(shadowDistanceRenderMul < 0.0) ShadowBounds = abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.z) < 6.0;
|
||||
vec3 shadowPlayerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
|
||||
|
||||
// sample shadows only if on shadow map
|
||||
if(ShadowBounds){
|
||||
if (NdotL > 0.0){
|
||||
Shadows = vec3(0.0);
|
||||
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
|
||||
Shadows = ComputeShadowMap(DirectLightColor, shadowPlayerPos, shadowMapFalloff, blueNoise());
|
||||
|
||||
#ifndef HAND
|
||||
#ifdef BASIC_SHADOW_FILTER
|
||||
const float threshMul = max(2048.0/shadowMapResolution*shadowDistance/128.0,0.95);
|
||||
float distortThresh = (sqrt(1.0-NdotL*NdotL)/NdotL+0.7)/distortFactor;
|
||||
float diffthresh = distortThresh/6000.0*threshMul;
|
||||
Shadows = mix(LM_shadowMapFallback, Shadows, shadowMapFalloff2);
|
||||
|
||||
float rdMul = 4.0/shadowMapResolution;
|
||||
float noise = blueNoise();
|
||||
Shadows *= pow(GetCloudShadow(feetPlayerPos),3);
|
||||
|
||||
int SampleCount = 7;
|
||||
for(int i = 0; i < SampleCount; i++){
|
||||
vec2 offsetS = tapLocation_simple(i, 7, 9, noise) * 0.5;
|
||||
float weight = 1.0+(i+noise)*rdMul/9.0*shadowMapResolution;
|
||||
|
||||
#ifdef TRANSLUCENT_COLORED_SHADOWS
|
||||
vec3 shadowProjOffsets = projectedShadowPosition + vec3(rdMul*offsetS, -diffthresh*weight);
|
||||
|
||||
float opaqueShadow = shadow2D(shadowtex0, shadowProjOffsets).x;
|
||||
Shadows += vec3(opaqueShadow/SampleCount);
|
||||
|
||||
if(shadow2D(shadowtex1, shadowProjOffsets).x > shadowProjOffsets.z){
|
||||
vec4 translucentShadow = texture2D(shadowcolor0, shadowProjOffsets.xy);
|
||||
if(translucentShadow.a < 0.9) Shadows += (normalize(translucentShadow.rgb+0.0001) * clamp(1.0-opaqueShadow,0.0,1.0)) / SampleCount;
|
||||
}
|
||||
|
||||
#else
|
||||
Shadows += vec3(shadow2D(shadow, projectedShadowPosition + vec3(rdMul*offsetS, -diffthresh*weight)).x / SampleCount);
|
||||
#endif
|
||||
|
||||
}
|
||||
#else
|
||||
|
||||
#ifdef TRANSLUCENT_COLORED_SHADOWS
|
||||
projectedShadowPosition -= vec3(0.0,0.0,0.0001);
|
||||
Shadows = vec3(shadow2D(shadowtex0, projectedShadowPosition ).x);
|
||||
|
||||
if(shadow2D(shadowtex1, projectedShadowPosition).x > projectedShadowPosition.z){
|
||||
vec4 shadowLightColor = texture2D(shadowcolor0, projectedShadowPosition.xy);
|
||||
if(shadowLightColor.a < 0.9) Shadows += normalize(shadowLightColor.rgb+0.0001);
|
||||
}
|
||||
#else
|
||||
Shadows = vec3(shadow2D(shadow, projectedShadowPosition - vec3(0.0,0.0,0.0001)).x);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#else
|
||||
Shadows = vec3(shadow2D(shadow, projectedShadowPosition - vec3(0.0,0.0,0.0005)).x);
|
||||
#endif
|
||||
}
|
||||
inShadowmapBounds = true;
|
||||
}
|
||||
|
||||
if(!inShadowmapBounds) Shadows = vec3(1.0);
|
||||
|
||||
Shadows *= GetCloudShadow(feetPlayerPos);
|
||||
|
||||
Direct_lighting = (lightCol.rgb/80.0) * NdotL * Shadows;
|
||||
Direct_lighting = DirectLightColor * NdotL * Shadows;
|
||||
|
||||
vec3 AmbientLightColor = averageSkyCol_Clouds/30.0;
|
||||
|
||||
vec3 ambientcoefs = WS_normal / dot(abs(WS_normal), vec3(1));
|
||||
|
||||
|
||||
// vec3 ambientcoefs = slopednormal / dot(abs(slopednormal), vec3(1.0));
|
||||
|
||||
// float SkylightDir = ambientcoefs.y*1.5;
|
||||
// if(isGrass) SkylightDir = 1.25;
|
||||
|
||||
// float skylight = max(pow(viewToWorld(FlatNormals).y*0.5+0.5,0.1) + SkylightDir, 0.2 + (1.0-lightmap.y)*0.8) ;
|
||||
|
||||
|
||||
vec3 ambientcoefs = worldSpaceNormal / dot(abs(worldSpaceNormal), vec3(1.0));
|
||||
float SkylightDir = ambientcoefs.y*1.5;
|
||||
|
||||
float skylight = max(pow(viewToWorld(flatnormal).y*0.5+0.5,0.1) + SkylightDir, 0.25);
|
||||
float skylight = max(pow(viewToWorld(flatnormal).y*0.5+0.5,0.1) + SkylightDir, 0.2);
|
||||
AmbientLightColor *= skylight;
|
||||
#endif
|
||||
|
||||
#ifdef NETHER_SHADER
|
||||
// vec3 AmbientLightColor = skyCloudsFromTexLOD2(WS_normal, colortex4, 6).rgb / 15.0;
|
||||
// vec3 AmbientLightColor = skyCloudsFromTexLOD2(worldSpaceNormal, colortex4, 6).rgb / 15.0;
|
||||
|
||||
// vec3 up = skyCloudsFromTexLOD2(vec3( 0, 1, 0), colortex4, 6).rgb/ 30.0;
|
||||
// vec3 down = skyCloudsFromTexLOD2(vec3( 0,-1, 0), colortex4, 6).rgb/ 30.0;
|
||||
|
||||
// up *= pow( max( WS_normal.y, 0), 2);
|
||||
// down *= pow( max(-WS_normal.y, 0), 2);
|
||||
// up *= pow( max( worldSpaceNormal.y, 0), 2);
|
||||
// down *= pow( max(-worldSpaceNormal.y, 0), 2);
|
||||
// AmbientLightColor += up + down;
|
||||
|
||||
vec3 AmbientLightColor = vec3(0.1);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef END_SHADER
|
||||
|
||||
|
||||
float vortexBounds = clamp(vortexBoundRange - length(feetPlayerPos+cameraPosition), 0.0,1.0);
|
||||
vec3 lightPos = LightSourcePosition(feetPlayerPos+cameraPosition, cameraPosition,vortexBounds);
|
||||
|
||||
@ -579,56 +608,91 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
float lightningflash = texelFetch2D(colortex4,ivec2(1,1),0).x/150.0;
|
||||
vec3 lightColors = LightSourceColors(vortexBounds, lightningflash);
|
||||
|
||||
float NdotL = clamp(dot(WS_normal, normalize(-lightPos))*0.5+0.5,0.0,1.0);
|
||||
float NdotL = clamp(dot(worldSpaceNormal, normalize(-lightPos))*0.5+0.5,0.0,1.0);
|
||||
|
||||
NdotL *= NdotL;
|
||||
|
||||
Direct_lighting = lightColors * endFogPhase(lightPos) * NdotL;
|
||||
|
||||
vec3 AmbientLightColor = vec3(0.5,0.75,1.0) * 0.9 + 0.1;
|
||||
AmbientLightColor *= clamp(1.5 + dot(WS_normal, normalize(feetPlayerPos))*0.5,0,2);
|
||||
|
||||
#endif
|
||||
Indirect_lighting = DoAmbientLightColor(feetPlayerPos, AmbientLightColor, MinimumLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.xy);
|
||||
|
||||
#ifdef ENTITIES
|
||||
Albedo.rgb = mix(Albedo.rgb, entityColor.rgb, clamp(entityColor.a*1.5,0,1));
|
||||
AmbientLightColor *= clamp(1.5 + dot(worldSpaceNormal, normalize(feetPlayerPos))*0.5,0,2);
|
||||
#endif
|
||||
|
||||
#ifdef IS_LPV_ENABLED
|
||||
vec3 lpvPos = GetLpvPosition(feetPlayerPos);
|
||||
|
||||
#ifdef LPV_NORMAL_OFFSET
|
||||
lpvPos += -0.5*worldSpaceNormal + viewToWorld(normal);
|
||||
#else
|
||||
lpvPos += 0.5*worldSpaceNormal;
|
||||
#endif
|
||||
#else
|
||||
const vec3 lpvPos = vec3(0.0);
|
||||
#endif
|
||||
|
||||
Indirect_lighting = DoAmbientLightColor(lpvPos, AmbientLightColor, MinimumLightColor, vec3(TORCH_R,TORCH_G,TORCH_B), lightmap.xy, exposure);
|
||||
|
||||
vec3 FinalColor = (Indirect_lighting + Direct_lighting) * Albedo;
|
||||
|
||||
// #ifdef Glass_Tint
|
||||
// FinalColor *= min(pow(gl_FragData[0].a,2.0),1.0);
|
||||
// #endif
|
||||
|
||||
////////////////////////////////
|
||||
//////////////////////////////// SPECULAR
|
||||
////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////// SPECULAR LIGHTING /////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef DAMAGE_BLOCK_EFFECT
|
||||
#undef WATER_REFLECTIONS
|
||||
#endif
|
||||
|
||||
// #ifdef ENTITIES
|
||||
// #undef WATER_BACKGROUND_SPECULAR
|
||||
// #endif
|
||||
|
||||
#ifndef OVERWORLD_SHADER
|
||||
#undef WATER_SUN_SPECULAR
|
||||
#endif
|
||||
|
||||
#ifdef WATER_REFLECTIONS
|
||||
vec2 SpecularTex = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rg;
|
||||
|
||||
SpecularTex = (iswater > 0.0 && iswater < 0.9) && SpecularTex.r > 0.0 && SpecularTex.g < 0.9 ? SpecularTex : vec2(1.0,0.02);
|
||||
|
||||
float roughness = max(pow(1.0-SpecularTex.r,2.0),0.05);
|
||||
float f0 = SpecularTex.g;
|
||||
// if nothing is chosen, no smoothness and no reflectance
|
||||
vec2 specularValues = vec2(1.0, 0.0);
|
||||
|
||||
// roughness = 0.1;
|
||||
// f0 = 0.1;
|
||||
// hardcode specular values for select blocks like glass, water, and slime
|
||||
if(isReflective) specularValues = vec2(1.0, 0.02);
|
||||
|
||||
// detect if the specular texture is used, if it is, overwrite hardcoded values
|
||||
if(SpecularTex.r > 0.0 && SpecularTex.g <= 1.0) specularValues = SpecularTex;
|
||||
|
||||
float roughness = pow(1.0-specularValues.r,2.0);
|
||||
float f0 = isReflective ? max(specularValues.g, 0.02) : specularValues.g;
|
||||
|
||||
|
||||
#ifdef HAND
|
||||
f0 = max(specularValues.g, 0.02);
|
||||
#endif
|
||||
|
||||
// specularValues = SpecularTex;
|
||||
// f0 = 0.9;
|
||||
// roughness = 0.0;
|
||||
|
||||
vec3 Metals = f0 > 229.5/255.0 ? normalize(Albedo+1e-7) * (dot(Albedo,vec3(0.21, 0.72, 0.07)) * 0.7 + 0.3) : vec3(1.0);
|
||||
|
||||
// make sure zero alpha is not forced to be full alpha by fresnel on items with funny normal padding
|
||||
if(UnchangedAlpha <= 0.0 && !isReflective) f0 = 0.0;
|
||||
|
||||
|
||||
if (f0 > 0.0){
|
||||
|
||||
if(isReflective) f0 = max(f0, 0.02);
|
||||
|
||||
if (iswater > 0.0 && gl_FragData[0].a < 0.9999999){
|
||||
vec3 Reflections_Final = vec3(0.0);
|
||||
vec4 Reflections = vec4(0.0);
|
||||
vec3 SkyReflection = vec3(0.0);
|
||||
vec3 BackgroundReflection = FinalColor;
|
||||
vec3 SunReflection = vec3(0.0);
|
||||
|
||||
float indoors = clamp((lightmap.y-0.6)*5.0, 0.0,1.0);
|
||||
|
||||
vec3 reflectedVector = reflect(normalize(viewPos), normal);
|
||||
float indoors = pow(1.0-pow(1.0-min(max(lightmap.y-0.6,0.0)*3.0,1.0),0.5),2.0);
|
||||
|
||||
vec3 reflectedVector = reflect(normalize(viewPos), normal);
|
||||
float normalDotEye = dot(normal, normalize(viewPos));
|
||||
|
||||
float fresnel = pow(clamp(1.0 + normalDotEye, 0.0, 1.0),5.0);
|
||||
|
||||
#ifdef SNELLS_WINDOW
|
||||
@ -638,90 +702,80 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
|
||||
|
||||
fresnel = mix(f0, 1.0, fresnel);
|
||||
|
||||
vec3 Metals = f0 > 229.5/255.0 ? normalize(Albedo+1e-7) * (dot(Albedo,vec3(0.21, 0.72, 0.07)) * 0.7 + 0.3) : vec3(1.0);
|
||||
|
||||
|
||||
// Sun, Sky, and screen-space reflections
|
||||
#ifdef OVERWORLD_SHADER
|
||||
#ifdef WATER_SUN_SPECULAR
|
||||
SunReflection = Direct_lighting * GGX(normal, -normalize(viewPos), WsunVec*mat3(gbufferModelViewInverse), roughness, vec3(f0)) ;
|
||||
SunReflection = Direct_lighting * GGX(normal, -normalize(viewPos), WsunVec*mat3(gbufferModelViewInverse), max(roughness,0.035), f0) * Metals;
|
||||
#endif
|
||||
#ifdef WATER_BACKGROUND_SPECULAR
|
||||
if(isEyeInWater == 0) SkyReflection = skyCloudsFromTex(mat3(gbufferModelViewInverse) * reflectedVector, colortex4).rgb / 30.0 ;
|
||||
if(isEyeInWater == 0 && !isReflectiveEntity) BackgroundReflection = skyCloudsFromTex(mat3(gbufferModelViewInverse) * reflectedVector, colortex4).rgb / 30.0 * Metals;
|
||||
#endif
|
||||
|
||||
if(isEyeInWater == 1 && isWater) BackgroundReflection.rgb = exp(-8.0 * vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B)) * clamp(WsunVec.y*lightCol.a,0,1);
|
||||
#else
|
||||
#ifdef WATER_BACKGROUND_SPECULAR
|
||||
if(isEyeInWater == 0) SkyReflection = skyCloudsFromTexLOD2(mat3(gbufferModelViewInverse) * reflectedVector, colortex4, 0).rgb / 30.0 ;
|
||||
if(isEyeInWater == 0) BackgroundReflection = skyCloudsFromTexLOD2(mat3(gbufferModelViewInverse) * reflectedVector, colortex4, 0).rgb / 30.0 * Metals;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef SCREENSPACE_REFLECTIONS
|
||||
if(iswater > 0.0){
|
||||
vec3 rtPos = rayTrace(reflectedVector, viewPos.xyz, interleaved_gradientNoise(), fresnel, isEyeInWater == 1);
|
||||
if (rtPos.z < 1.){
|
||||
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 = texture2D(colortex5,previousPosition.xy).rgb ;
|
||||
}
|
||||
vec3 rtPos = rayTrace(reflectedVector, viewPos.xyz, interleaved_gradientNoise_temporal(), fresnel, isEyeInWater == 1);
|
||||
if (rtPos.z < 1.){
|
||||
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 = texture2D(colortex5,previousPosition.xy).rgb * Metals;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
if(isEyeInWater == 1 && iswater > 0.9){
|
||||
SkyReflection.rgb = exp(-8.0 * vec3(Water_Absorb_R, Water_Absorb_G, Water_Absorb_B)) * clamp(WsunVec.y*lightCol.a,0,1);
|
||||
}
|
||||
|
||||
// if(iswater > 0.9) SkyReflection.rgb = mix(vec3(CaveFogColor_R, CaveFogColor_G, CaveFogColor_B)*0.1, SkyReflection.rgb*indoors, clamp(pow(eyeBrightnessSmooth.y/240. + lightmap.y,2.0),0.0,1.0));
|
||||
#endif
|
||||
|
||||
float visibilityFactor = clamp(exp2((pow(roughness,3.0) / f0) * -4),0,1);
|
||||
|
||||
#ifdef ENTITIES
|
||||
Reflections_Final = FinalColor;
|
||||
#else
|
||||
Reflections_Final = mix(SkyReflection*indoors, Reflections.rgb, Reflections.a);
|
||||
Reflections_Final = mix(FinalColor, Reflections_Final * Metals, fresnel);
|
||||
#endif
|
||||
|
||||
Reflections_Final += SunReflection * Metals;
|
||||
Reflections_Final = mix(mix(FinalColor, BackgroundReflection, indoors), Reflections.rgb, Reflections.a) * fresnel * visibilityFactor;
|
||||
Reflections_Final += SunReflection;
|
||||
|
||||
// Reflections_Final += vec3(CaveFogColor_R, CaveFogColor_G, CaveFogColor_B)*0.1 * darkSpecularHighlight(feetPlayerPos, viewToWorld(normal), 0.9, 0.1);
|
||||
|
||||
gl_FragData[0].rgb = Reflections_Final ;
|
||||
|
||||
#ifndef ENTITIES
|
||||
//correct alpha channel with fresnel
|
||||
gl_FragData[0].a = mix(gl_FragData[0].a, 1.0, fresnel);
|
||||
#endif
|
||||
//correct alpha channel with fresnel
|
||||
float alpha0 = gl_FragData[0].a;
|
||||
|
||||
gl_FragData[0].a = -gl_FragData[0].a * fresnel + gl_FragData[0].a + fresnel;
|
||||
|
||||
// prevent reflections from being darkened by buffer blending
|
||||
gl_FragData[0].rgb = clamp(FinalColor / gl_FragData[0].a*alpha0*(1.0-fresnel) * 0.1 + Reflections_Final / gl_FragData[0].a * 0.1,0.0,65100.0);
|
||||
|
||||
if (gl_FragData[0].r > 65000.) gl_FragData[0].rgba = vec4(0.0);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
gl_FragData[0].rgb = FinalColor;
|
||||
gl_FragData[0].rgb = FinalColor*0.1;
|
||||
}
|
||||
|
||||
#else
|
||||
gl_FragData[0].rgb = FinalColor;
|
||||
gl_FragData[0].rgb = FinalColor*0.1;
|
||||
#endif
|
||||
|
||||
// gl_FragData[0].rgb = vec3(1) * (texelFetch2D(depthtex0,ivec2(gl_FragCoord.xy),0).x - texelFetch2D(dhDepthTex1,ivec2(gl_FragCoord.xy),0).x);
|
||||
#if defined DISTANT_HORIZONS && defined DH_OVERDRAW_PREVENTION && !defined HAND
|
||||
bool WATER = texture2D(colortex7, gl_FragCoord.xy*texelSize).a > 0.0 && length(feetPlayerPos) > far-16*4 && texture2D(depthtex1, gl_FragCoord.xy*texelSize).x >= 1.0;
|
||||
|
||||
|
||||
#if defined DISTANT_HORIZONS && defined DH_OVERDRAW_PREVENTION
|
||||
gl_FragData[0].a = mix(gl_FragData[0].a, 0.0, 1.0-min(max(1.0 - length(feetPlayerPos.xz)/max(far,0.0),0.0)*2.0,1.0) );
|
||||
if(WATER) gl_FragData[0].a = 0.0;
|
||||
#endif
|
||||
|
||||
#ifndef HAND
|
||||
gl_FragData[1] = vec4(Albedo, iswater);
|
||||
gl_FragData[1] = vec4(Albedo, MATERIALS);
|
||||
#endif
|
||||
|
||||
#if DEBUG_VIEW == debug_DH_WATER_BLENDING
|
||||
if(gl_FragCoord.x*texelSize.x < 0.47) gl_FragData[0] = vec4(0.0);
|
||||
#endif
|
||||
#if DEBUG_VIEW == debug_NORMALS
|
||||
gl_FragData[0].rgb = normal.xyz * 0.1 * vec3(0,0,1);
|
||||
#endif
|
||||
#if DEBUG_VIEW == debug_INDIRECT
|
||||
gl_FragData[0].rgb = Indirect_lighting* 0.1;
|
||||
#endif
|
||||
#if DEBUG_VIEW == debug_DIRECT
|
||||
gl_FragData[0].rgb = Direct_lighting * 0.1;
|
||||
#endif
|
||||
|
||||
gl_FragData[3].a = lmtexcoord.w;
|
||||
gl_FragData[3].a = encodeVec2(lightmap);
|
||||
}
|
||||
}
|
@ -16,6 +16,9 @@ Read the terms of modification and sharing before changing something below pleas
|
||||
varying vec4 lmtexcoord;
|
||||
varying vec4 color;
|
||||
|
||||
uniform sampler2D colortex4;
|
||||
flat varying float exposure;
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
flat varying vec3 averageSkyCol_Clouds;
|
||||
flat varying vec4 lightCol;
|
||||
@ -35,7 +38,6 @@ flat varying int glass;
|
||||
attribute vec4 at_tangent;
|
||||
attribute vec4 mc_Entity;
|
||||
|
||||
uniform sampler2D colortex4;
|
||||
|
||||
uniform vec3 sunPosition;
|
||||
uniform float sunElevation;
|
||||
@ -73,7 +75,6 @@ vec4 toClipSpace3(vec3 viewSpacePosition) {
|
||||
return vec4(projMAD(gl_ProjectionMatrix, viewSpacePosition),-viewSpacePosition.z);
|
||||
}
|
||||
|
||||
varying vec4 pos;
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
//////////////////////////////VOID MAIN//////////////////////////////
|
||||
@ -82,14 +83,15 @@ varying vec4 pos;
|
||||
|
||||
void main() {
|
||||
|
||||
lmtexcoord.xy = (gl_MultiTexCoord0).xy;
|
||||
vec2 lmcoord = gl_MultiTexCoord1.xy / 240.0; // is this even correct? lol
|
||||
// lmtexcoord.xy = (gl_MultiTexCoord0).xy;
|
||||
lmtexcoord.xy = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
|
||||
vec2 lmcoord = gl_MultiTexCoord1.xy / 240.0;
|
||||
lmtexcoord.zw = lmcoord;
|
||||
|
||||
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
|
||||
|
||||
gl_Position = toClipSpace3(position);
|
||||
|
||||
pos = vec4(position,1);
|
||||
|
||||
HELD_ITEM_BRIGHTNESS = 0.0;
|
||||
|
||||
@ -97,21 +99,28 @@ void main() {
|
||||
if(heldItemId == ITEM_LIGHT_SOURCES || heldItemId2 == ITEM_LIGHT_SOURCES) HELD_ITEM_BRIGHTNESS = 0.9;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// 1.0 = water mask
|
||||
// 0.9 = entity mask
|
||||
// 0.8 = reflective entities
|
||||
// 0.7 = reflective blocks
|
||||
float mat = 0.0;
|
||||
|
||||
|
||||
// water mask
|
||||
if(mc_Entity.x == 8.0) {
|
||||
mat = 1.0;
|
||||
|
||||
gl_Position.z -= 1e-4;
|
||||
}
|
||||
|
||||
if (mc_Entity.x >= 200 && mc_Entity.x < 300) mat = 0.2;
|
||||
if (mc_Entity.x == 72) mat = 0.5;
|
||||
|
||||
// translucent entities
|
||||
#if defined ENTITIES || defined BLOCKENTITIES
|
||||
mat = 0.1;
|
||||
mat = 0.9;
|
||||
if (entityId == 1403) mat = 0.8;
|
||||
#endif
|
||||
|
||||
// translucent blocks
|
||||
if (mc_Entity.x >= 301 && mc_Entity.x <= 321) mat = 0.7;
|
||||
|
||||
tangent = vec4(normalize(gl_NormalMatrix *at_tangent.rgb),at_tangent.w);
|
||||
|
||||
@ -132,6 +141,7 @@ void main() {
|
||||
|
||||
|
||||
color = vec4(gl_Color.rgb, 1.0);
|
||||
exposure = texelFetch2D(colortex4,ivec2(10,37),0).r;
|
||||
|
||||
#ifdef OVERWORLD_SHADER
|
||||
lightCol.rgb = texelFetch2D(colortex4,ivec2(6,37),0).rgb;
|
||||
@ -143,8 +153,6 @@ void main() {
|
||||
// WsunVec = normalize(LightDir);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef TAA_UPSCALING
|
||||
gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w;
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user