/*
====================================================================================================

    Copyright (C) 2025 Pyvtron VX Shaders - Pyvton

    All Rights Reserved unless otherwise explicitly stated.

    Before You Do Something With Pyvtron VX Shaders, You MUST Read This:

    You Must Read The License: https://pyvton.pages.dev/minecraft-shaders/pyvtron-shaders-license
    And Read The Agreement: https://pyvton.pages.dev/minecraft-shaders/pyvtron-shaders-agreement

====================================================================================================
*/

// Not PyvtronGodrays, PyvtonGodrays.

#define VOLUMETRIC_LIGHT_STRENGTH 3.0
#define VOLUMETRIC_LIGHT_QUALITY 150

float PhaseMie(float a1b2c3,float d4e5f6,float g7h8i9){float j0k1l2=a1b2c3*a1b2c3;float m3n4o5=(1.-j0k1l2)*(1.+g7h8i9);float p6q7r8=1.+j0k1l2-2.*a1b2c3*d4e5f6;p6q7r8*=sqrt(p6q7r8);p6q7r8*=2.+j0k1l2;return 1.5*m3n4o5/p6q7r8;}float CalculateWaterCaustics(vec3 s9t0u1){vec3 v2w3x4=s9t0u1.xyz+cameraPosition.xyz;vec3 y5z6a7=v2w3x4+vec3(.0,1.,.0);vec3 b8c9d0=GetWavesNormalFromTex(y5z6a7).xzy;vec3 e1f2g3=refract(vec3(.0,1.,.0),b8c9d0.xyz,1.);vec3 h4i5j6=y5z6a7-e1f2g3/e1f2g3.y;float k7l8m9=distance(h4i5j6,v2w3x4);return k7l8m9+.2;}void PeGodrayUW(inout vec3 n0o1p2,vec3 q3r4s5,vec3 t6u7v8,float w9x0y1,float z2a3b4){vec3 c5d6e7=(gbufferModelViewInverse*vec4(.0,.0,.0,1.)).xyz;vec3 f8g9h0=vec3(.0);bool i1j2k3=(q3r4s5.y<1111.);float l4m5n6=i1j2k3?30.:100.;for(int o7p8q9=0;o7p8q9<VOLUMETRIC_LIGHT_QUALITY;o7p8q9++){float r0s1t2=(float(o7p8q9)+z2a3b4)/float(VOLUMETRIC_LIGHT_QUALITY);vec3 u3v4w5=t6u7v8*l4m5n6*r0s1t2+c5d6e7;vec3 x6y7z8=u3v4w5-c5d6e7;if(length(q3r4s5.xyz)<length(x6y7z8)){break;}float a9b0c1=.0;float d2e3f4=.0;vec3 g5h6i7=WorldPosToShadowProjPos(u3v4w5,a9b0c1,d2e3f4);float j8k9l0=step(g5h6i7.z+1e-6,textureLod(shadowtex1,g5h6i7.xy,3.).x);float m1n2o3=pow(CalculateWaterCaustics(u3v4w5),3.);float p4q5r6=pow(saturate(1.-r0s1t2),.2);float s7t8u9=i1j2k3?2.:.15;f8g9h0+=j8k9l0*m1n2o3*p4q5r6*s7t8u9;}vec3 v0w1x2=refract(worldLightVector,vec3(.0,-1.,.0),1./1.2);float y3z4a5=dot(v0w1x2,t6u7v8);y3z4a5=max(y3z4a5,.1);float b6c7d8=.5/(max(.0,pow(v0w1x2.y,2.)*2.)+.4);float e9f0g1=y3z4a5*y3z4a5;float h2i3j4=PhaseMie(.8,y3z4a5,e9f0g1);h2i3j4=pow(h2i3j4,1.)*VOLUMETRIC_LIGHT_STRENGTH;vec3 k5l6m7=f8g9h0*colorSunlight*.02*h2i3j4*b6c7d8*l4m5n6*vec3(.1,.5,1.);
#ifdef VOLUMETRIC_CLOUDS
#ifdef CLOUD_SHADOW
			float n8o9p0=mix(fma(w9x0y1,.9,.1),fma(w9x0y1,.7,.3),wetness);k5l6m7*=n8o9p0;
#endif
#endif
	n0o1p2+=k5l6m7;}