Bliss-Shader/shaders/dimensions/all_particles.fsh

263 lines
6.9 KiB
Plaintext
Raw Normal View History

2023-10-07 22:18:20 -04:00
#include "/lib/settings.glsl"
2024-05-02 12:43:30 -04:00
#ifdef IS_LPV_ENABLED
#extension GL_EXT_shader_image_load_store: enable
#endif
2023-10-07 22:18:20 -04:00
#include "/lib/res_params.glsl"
varying vec4 lmtexcoord;
varying vec4 color;
#ifdef LINES
flat varying int SELECTION_BOX;
#endif
2023-10-07 22:18:20 -04:00
#ifdef OVERWORLD_SHADER
const bool shadowHardwareFiltering = true;
uniform sampler2DShadow shadow;
2024-03-20 21:44:25 -04:00
#ifdef TRANSLUCENT_COLORED_SHADOWS
uniform sampler2D shadowcolor0;
uniform sampler2DShadow shadowtex0;
uniform sampler2DShadow shadowtex1;
#endif
2023-10-07 22:18:20 -04:00
flat varying vec3 WsunVec;
flat varying vec3 averageSkyCol_Clouds;
flat varying vec4 lightCol;
#endif
uniform int isEyeInWater;
2023-10-07 22:18:20 -04:00
uniform sampler2D texture;
uniform sampler2D noisetex;
uniform sampler2D colortex4;
#ifdef IS_LPV_ENABLED
uniform sampler3D texLpv1;
uniform sampler3D texLpv2;
#endif
uniform mat4 gbufferProjectionInverse;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelView;
uniform mat4 shadowModelView;
uniform mat4 shadowProjection;
uniform vec3 cameraPosition;
uniform float frameTimeCounter;
#include "/lib/Shadow_Params.glsl"
uniform vec2 texelSize;
uniform ivec2 eyeBrightnessSmooth;
uniform float rainStrength;
flat varying float HELD_ITEM_BRIGHTNESS;
2023-10-07 22:18:20 -04:00
#ifndef OVERWORLD_SHADER
uniform float nightVision;
#endif
#ifdef OVERWORLD_SHADER
#define CLOUDSHADOWSONLY
#include "/lib/volumetricClouds.glsl"
#endif
2024-05-02 12:43:30 -04:00
#ifdef IS_LPV_ENABLED
uniform int frameCounter;
#include "/lib/hsv.glsl"
#include "/lib/lpv_common.glsl"
#include "/lib/lpv_render.glsl"
#endif
#include "/lib/diffuse_lighting.glsl"
#include "/lib/sky_gradient.glsl"
vec3 toLinear(vec3 sRGB){
return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
vec3 toScreenSpace(vec3 p) {
vec4 iProjDiag = vec4(gbufferProjectionInverse[0].x, gbufferProjectionInverse[1].y, gbufferProjectionInverse[2].zw);
vec3 p3 = p * 2. - 1.;
vec4 fragposition = iProjDiag * p3.xyzz + gbufferProjectionInverse[3];
return fragposition.xyz / fragposition.w;
}
uniform int framemod8;
const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.),
vec2(-1.,3.)/8.,
vec2(5.0,1.)/8.,
vec2(-3,-5.)/8.,
vec2(-5.,5.)/8.,
vec2(-7.,-1.)/8.,
vec2(3,7.)/8.,
vec2(7.,-7.)/8.);
2023-10-07 22:18:20 -04:00
//Mie phase function
float phaseg(float x, float g){
float gg = g * g;
return (gg * -0.25 + 0.25) * pow(-2.0 * (g * x) + (gg + 1.0), -1.5) / 3.14;
}
//encoding by jodie
float encodeVec2(vec2 a){
const vec2 constant1 = vec2( 1., 256.) / 65535.;
vec2 temp = floor( a * 255. );
return temp.x*constant1.x+temp.y*constant1.y;
}
float encodeVec2(float x,float y){
return encodeVec2(vec2(x,y));
}
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN//////////////////////////////
2023-10-07 22:18:20 -04:00
#ifdef DAMAGE_BLOCK_EFFECT
/* RENDERTARGETS:11 */
#else
/* DRAWBUFFERS:29 */
#endif
2023-10-07 22:18:20 -04:00
void main() {
#ifdef LINES
#ifndef SELECT_BOX
if(SELECTION_BOX > 0) discard;
#endif
#endif
2023-10-07 22:18:20 -04:00
vec2 tempOffset = offsets[framemod8];
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;
vec3 feetPlayerPos_normalized = normalize(feetPlayerPos);
2023-10-07 22:18:20 -04:00
vec4 TEXTURE = texture2D(texture, lmtexcoord.xy)*color;
2023-10-07 22:18:20 -04:00
vec3 Albedo = toLinear(TEXTURE.rgb);
vec2 lightmap = lmtexcoord.zw;
#ifndef OVERWORLD_SHADER
lightmap.y = 1.0;
#endif
#ifdef Hand_Held_lights
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
2023-10-07 22:18:20 -04:00
#ifdef WEATHER
gl_FragData[1].a = TEXTURE.a; // for bloomy rain and stuff
#endif
2023-10-07 22:18:20 -04:00
#ifndef WEATHER
#ifndef LINES
gl_FragData[0].a = TEXTURE.a;
#else
gl_FragData[0].a = 1.0;
#endif
2023-12-21 15:21:15 -05:00
#ifndef BLOOMY_PARTICLES
gl_FragData[1].a = 0.0; // for bloomy rain and stuff
#endif
2023-10-07 22:18:20 -04:00
vec3 Direct_lighting = vec3(0.0);
vec3 Indirect_lighting = vec3(0.0);
vec3 MinimumLightColor = vec3(1.0);
if(isEyeInWater == 1) MinimumLightColor = vec3(10.0);
2023-10-07 22:18:20 -04:00
vec3 Torch_Color = vec3(TORCH_R,TORCH_G,TORCH_B);
if(lightmap.x >= 0.9) Torch_Color *= LIT_PARTICLE_BRIGHTNESS;
2023-10-07 22:18:20 -04:00
#ifdef OVERWORLD_SHADER
2024-03-20 21:44:25 -04:00
vec3 Shadows = vec3(1.0);
2023-10-07 22:18:20 -04:00
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
2023-10-07 22:18:20 -04:00
//do shadows only if on shadow map
if (abs(projectedShadowPosition.x) < 1.0-1.5/shadowMapResolution && abs(projectedShadowPosition.y) < 1.0-1.5/shadowMapResolution){
2024-03-20 21:44:25 -04:00
Shadows = vec3(0.0);
2023-10-07 22:18:20 -04:00
projectedShadowPosition = projectedShadowPosition * vec3(0.5,0.5,0.5/6.0) + vec3(0.5);
2024-03-20 21:44:25 -04:00
#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
2023-10-07 22:18:20 -04:00
}
2023-10-07 22:18:20 -04:00
float cloudShadow = GetCloudShadow(feetPlayerPos);
Direct_lighting = (lightCol.rgb/80.0) * Shadows * cloudShadow;
2023-10-07 22:18:20 -04:00
#ifndef LINES
Direct_lighting *= phaseg(clamp(dot(feetPlayerPos_normalized, WsunVec),0.0,1.0), 0.65)*2 + 0.5;
#endif
vec3 AmbientLightColor = (averageSkyCol_Clouds / 30.0) * 3.0;
#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
2023-10-07 22:18:20 -04:00
2024-05-02 12:43:30 -04:00
Indirect_lighting = DoAmbientLightColor(feetPlayerPos, AmbientLightColor,MinimumLightColor, Torch_Color, clamp(lightmap.xy,0,1));
2023-10-20 21:33:13 -04:00
#ifdef LINES
2023-10-07 22:18:20 -04:00
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * toLinear(color.rgb);
2023-10-20 21:33:13 -04:00
#else
gl_FragData[0].rgb = (Indirect_lighting + Direct_lighting) * Albedo;
2023-10-07 22:18:20 -04:00
#endif
#ifdef DAMAGE_BLOCK_EFFECT
gl_FragData[0] = vec4(0.0, encodeVec2(TEXTURE.rg), encodeVec2(vec2(TEXTURE.b,0.0)), TEXTURE.a);
#endif
2023-10-07 22:18:20 -04:00
// 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
}