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
|
||||
}
|
Reference in New Issue
Block a user