updated Physics mod support

for water waves, and snow and stuff.
This commit is contained in:
Xonk 2023-04-25 20:08:21 -04:00
parent b59cd5d5a9
commit b12c2491cf
9 changed files with 191 additions and 43 deletions

View File

@ -211,10 +211,11 @@ void main() {
vec2 refractedCoord = texcoord; vec2 refractedCoord = texcoord;
/// --- REFRACTION --- ///
#ifdef Refraction #ifdef Refraction
refractedCoord += (tangentNormals * clamp((ld(z2) - ld(z)) * 0.5,0.0,0.15)) * RENDER_SCALE; refractedCoord += (tangentNormals * clamp((ld(z2) - ld(z)) * 0.5,0.0,0.15)) * RENDER_SCALE;
if(decodeVec2(texture2D(colortex11,refractedCoord).b).g < 0.01 ) refractedCoord = texcoord; // remove refracted coords on solids if( texture2D(colortex7,refractedCoord).a < 0.95 && decodeVec2(texture2D(colortex11,refractedCoord).b).g < 0.01 ) refractedCoord = texcoord; // remove refracted coords on solids
#endif #endif
/// --- MAIN COLOR BUFFER --- /// /// --- MAIN COLOR BUFFER --- ///

View File

@ -102,7 +102,7 @@ void main() {
#endif #endif
#ifndef WEATHER #ifndef WEATHER
gl_FragData[1].a = pow(1.0-TEXTURE.a,2.0); // for bloomy rain gl_FragData[1].a = 0.0; // for bloomy rain
gl_FragData[0] = TEXTURE; gl_FragData[0] = TEXTURE;
vec3 Albedo = toLinear(gl_FragData[0].rgb); vec3 Albedo = toLinear(gl_FragData[0].rgb);

View File

@ -3,8 +3,6 @@
#include "/lib/settings.glsl" #include "/lib/settings.glsl"
flat varying int NameTags; flat varying int NameTags;
#ifndef USE_LUMINANCE_AS_HEIGHTMAP #ifndef USE_LUMINANCE_AS_HEIGHTMAP
@ -80,6 +78,12 @@ in vec3 velocity;
flat varying float blockID; flat varying float blockID;
flat varying int EMISSIVE; flat varying int EMISSIVE;
#ifdef ENTITIES
#define ENTITY_PHYSICSMOD_SNOW 829925
#endif
// float interleaved_gradientNoise(){ // float interleaved_gradientNoise(){
// return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521); // return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y)+frameTimeCounter*51.9521);
// } // }
@ -425,15 +429,20 @@ void main() {
NormalTex.xy = NormalTex.xy*2.0-1.0; NormalTex.xy = NormalTex.xy*2.0-1.0;
NormalTex.z = clamp(sqrt(1.0 - dot(NormalTex.xy, NormalTex.xy)),0.0,1.0) ; NormalTex.z = clamp(sqrt(1.0 - dot(NormalTex.xy, NormalTex.xy)),0.0,1.0) ;
normal = applyBump(tbnMatrix, NormalTex.xyz, mix(1.0,1.0-Puddle_shape,rainfall) ); normal = applyBump(tbnMatrix, NormalTex.xyz, 1 );
#ifdef ENTITIES #ifdef ENTITIES
if(NameTags == 1) normal = vec3(1); if(NameTags == 1) normal = vec3(1);
#endif #endif
#ifdef ENTITY_PHYSICSMOD_SNOW
normal = FlatNormals;
#endif
#endif #endif
#endif #endif
//////////////////////////////// ////////////////////////////////
//////////////////////////////// SPECULAR //////////////////////////////// SPECULAR
//////////////////////////////// ////////////////////////////////
@ -449,11 +458,20 @@ void main() {
if(NameTags == 1) SpecularTex = vec4(0.0); if(NameTags == 1) SpecularTex = vec4(0.0);
#endif #endif
#ifdef ENTITY_PHYSICSMOD_SNOW
SpecularTex.rg = vec2(0.0);
#endif
gl_FragData[2] = SpecularTex; gl_FragData[2] = SpecularTex;
#endif #endif
if(EMISSIVE > 0) gl_FragData[2].a = 0.9; if(EMISSIVE > 0) gl_FragData[2].a = 0.9;
//////////////////////////////// ////////////////////////////////
//////////////////////////////// ALBEDO //////////////////////////////// ALBEDO
//////////////////////////////// ////////////////////////////////

View File

@ -131,12 +131,14 @@ vec3 blackbody2(float Temp)
#define SEASONS_VSH #define SEASONS_VSH
#include "/lib/climate_settings.glsl" #include "/lib/climate_settings.glsl"
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////
//////////////////////////////VOID MAIN////////////////////////////// //////////////////////////////VOID MAIN//////////////////////////////
void main() { void main() {
gl_Position = ftransform(); gl_Position = ftransform();
@ -148,9 +150,9 @@ void main() {
// emission and shit... // emission and shit...
EMISSIVE = 0; EMISSIVE = 0;
#ifndef LabPBR_Emissives // #ifndef LabPBR_Emissives
if(mc_Entity.x == 10005) EMISSIVE = 1; // if(mc_Entity.x == 10005) EMISSIVE = 1;
#endif // #endif
lmtexcoord.xy = (gl_MultiTexCoord0).xy; lmtexcoord.xy = (gl_MultiTexCoord0).xy;
@ -194,7 +196,7 @@ void main() {
// normalMat.a = 0.45; // normalMat.a = 0.45;
// try and single out nametag text and then discard nametag background // try and single out nametag text and then discard nametag background
@ -240,9 +242,14 @@ void main() {
normalMat.a = 0.9; normalMat.a = 0.9;
} }
gl_Position = toClipSpace3(position); gl_Position = toClipSpace3(position);
#endif #endif
NoSeasonCol.rgb = gl_Color.rgb; NoSeasonCol.rgb = gl_Color.rgb;
#ifdef Seasons #ifdef Seasons

View File

@ -71,7 +71,6 @@ flat varying vec3 avgAmbient;
#include "lib/diffuse_lighting.glsl" #include "lib/diffuse_lighting.glsl"
float blueNoise(){ float blueNoise(){
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter); return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
} }
@ -151,6 +150,7 @@ vec3 viewToWorld(vec3 viewPosition) {
pos = gbufferModelViewInverse * pos; pos = gbufferModelViewInverse * pos;
return pos.xyz; return pos.xyz;
} }
vec3 worldToView(vec3 worldPos) { vec3 worldToView(vec3 worldPos) {
vec4 pos = vec4(worldPos, 0.0); vec4 pos = vec4(worldPos, 0.0);
pos = gbufferModelView * pos; pos = gbufferModelView * pos;
@ -290,6 +290,7 @@ if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize
} }
#endif #endif
vec4 COLORTEST = vec4(Albedo,gl_FragData[0].a); vec4 COLORTEST = vec4(Albedo,gl_FragData[0].a);
@ -304,7 +305,18 @@ if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize
tangent.z, tangent2.z, normal.z); tangent.z, tangent2.z, normal.z);
if (iswater > 0.4){
/// ------ NORMALS ------ ///
vec4 NormalTex = texture2D(normals, lmtexcoord.xy, Texture_MipMap_Bias).rgba;
NormalTex.xy = NormalTex.xy*2.0-1.0;
NormalTex.z = clamp(sqrt(1.0 - dot(NormalTex.xy, NormalTex.xy)),0.0,1.0) ;
TangentNormal = NormalTex.xy*0.5+0.5;
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
if (iswater > 0.95){
if(physics_iterationsNormal < 1.0){ if(physics_iterationsNormal < 1.0){
float bumpmult = 1.; float bumpmult = 1.;
@ -321,29 +333,26 @@ if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize
bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult); bump = bump * vec3(bumpmult, bumpmult, bumpmult) + vec3(0.0f, 0.0f, 1.0f - bumpmult);
normal = normalize(bump * tbnMatrix); normal = normalize(bump * tbnMatrix);
}else{ }else{
vec3 PhysicsMod_normal = physics_waveNormal(physics_localPosition.xz, physics_localWaviness, physics_gameTime); /// ------ PHYSICS MOD OCEAN SHIT ------ ///
normal = normalize(worldToView(PhysicsMod_normal) + mix(normal, vec3(0.0), clamp(physics_localWaviness,0.0,1.0))); WavePixelData wave = physics_wavePixel(physics_localPosition.xz, physics_localWaviness, physics_iterationsNormal, physics_gameTime);
// float Foam = wave.foam;
vec3 worldSpaceNormal = normal.xyz; // Albedo = mix(Albedo,vec3(1),Foam);
// gl_FragData[0].a = Foam;
normal = normalize(worldToView(wave.normal) + mix(normal, vec3(0.0), clamp(physics_localWaviness,0.0,1.0)));
vec3 worldSpaceNormal = normal;
vec3 bitangent = normalize(cross(tangent.xyz, worldSpaceNormal)); vec3 bitangent = normalize(cross(tangent.xyz, worldSpaceNormal));
mat3 tbn_new = mat3(tangent.xyz, binormal, worldSpaceNormal); mat3 tbn_new = mat3(tangent.xyz, binormal, worldSpaceNormal);
vec3 tangentSpaceNormal = worldSpaceNormal * tbn_new; vec3 tangentSpaceNormal = worldSpaceNormal * tbn_new;
TangentNormal = tangentSpaceNormal.xy ; TangentNormal = tangentSpaceNormal.xy * 0.5 + 0.5;
} }
}else{
vec4 NormalTex = texture2D(normals, lmtexcoord.xy, Texture_MipMap_Bias).rgba;
NormalTex.xy = NormalTex.xy*2.0-1.0;
NormalTex.z = clamp(sqrt(1.0 - dot(NormalTex.xy, NormalTex.xy)),0.0,1.0) ;
TangentNormal = NormalTex.xy*0.5+0.5;
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
} }
// cannot encode alpha or it will shit its pants // cannot encode alpha or it will shit its pants
@ -405,12 +414,19 @@ if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize
vec2 SpecularTex = texture2D(specular, lmtexcoord.xy, Texture_MipMap_Bias).rg; 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);
// SpecularTex = (iswater > 0.0 && iswater < 0.9) && SpecularTex.r > 0.0 && SpecularTex.g < 0.9 ? SpecularTex : vec2(1.0,0.1);
if (iswater > 0.0 && (SpecularTex.g > 0.0 || SpecularTex.r > 0.0)){
float roughness = max(pow(1.0-SpecularTex.r,2.0),0.05);
float f0 = SpecularTex.g;
roughness = iswater > 0.95 ? 0.05 : roughness;
f0 = iswater > 0.95 ? 0.1 : f0;
if (iswater > 0.0 ){
vec3 Reflections_Final = vec3(0.0); vec3 Reflections_Final = vec3(0.0);
float roughness = max(pow(1.0-SpecularTex.r,2.0),0.05);
float f0 = SpecularTex.g;
float F0 = f0; float F0 = f0;
@ -458,7 +474,7 @@ if (gl_FragCoord.x * texelSize.x < RENDER_SCALE.x && gl_FragCoord.y * texelSize
//correct alpha channel with fresnel //correct alpha channel with fresnel
float alpha0 = gl_FragData[0].a; float alpha0 = gl_FragData[0].a;
gl_FragData[0].a = -gl_FragData[0].a*fresnel+gl_FragData[0].a+fresnel; gl_FragData[0].a = mix(alpha0, 1.0, fresnel);
if (gl_FragData[0].r > 65000.) gl_FragData[0].rgba = vec4(0.); if (gl_FragData[0].r > 65000.) gl_FragData[0].rgba = vec4(0.);

View File

@ -97,11 +97,11 @@ void main() {
float mat = 0.0; float mat = 0.0;
if(mc_Entity.x == 8.0 || mc_Entity.x == 9.0) { if(mc_Entity.x == 8.0) {
mat = 1.0; mat = 1.0;
gl_Position.z -= 1e-4; gl_Position.z -= 1e-4;
} }
if (mc_Entity.x == 10002) mat = 0.2; if (mc_Entity.x == 10002) mat = 0.2;
if (mc_Entity.x == 72) mat = 0.5; if (mc_Entity.x == 72) mat = 0.5;

View File

@ -20,7 +20,7 @@ vec3 toLinear(vec3 sRGB){
void main() { void main() {
vec3 albedo = (texture2D(texture, texcoord).rgb * color.rgb); vec3 albedo = texture2D(texture, texcoord).rgb * color.rgb;
gl_FragData[0].rgb = albedo; gl_FragData[0].rgb = albedo;

View File

@ -5,8 +5,8 @@
// your shaderpack. It replaces this define statement (before compilation) with // your shaderpack. It replaces this define statement (before compilation) with
#define PHYSICS_OCEAN #define PHYSICS_OCEAN
// so you can use // so you can use
// #ifdef PHYSICS_OCEAN #ifdef PHYSICS_OCEAN
// #endif #endif
// to customize the water for the physics ocean // to customize the water for the physics ocean
// just some basic consts for the wave function based on afl_ext's shader https://www.shadertoy.com/view/Xdlczl // just some basic consts for the wave function based on afl_ext's shader https://www.shadertoy.com/view/Xdlczl
@ -42,7 +42,20 @@ uniform float physics_oceanHeight;
uniform sampler2D physics_waviness; uniform sampler2D physics_waviness;
// basic scale for the horizontal size of the waves // basic scale for the horizontal size of the waves
uniform float physics_oceanWaveHorizontalScale; uniform float physics_oceanWaveHorizontalScale;
// used to offset the model to know the ripple position
uniform vec3 physics_modelOffset;
// used for offsetting the ripple texture
uniform float physics_rippleRange;
// controlling how much foam generates on the ocean
uniform float physics_foamAmount;
// controlling the opacity of the foam
uniform float physics_foamOpacity;
// texture containing the ripples (basic bump map)
uniform sampler2D physics_ripples;
// foam noise
uniform sampler3D physics_foam;
// just the generic minecraft lightmap, you can remove this and use the one supplied by Optifine/Iris
uniform sampler2D physics_lightmap;
#ifdef PHYSICSMOD_VERTEX #ifdef PHYSICSMOD_VERTEX
// for the vertex shader stage // for the vertex shader stage
out vec3 physics_localPosition; out vec3 physics_localPosition;
@ -54,6 +67,7 @@ uniform float physics_oceanWaveHorizontalScale;
in vec3 physics_localPosition; in vec3 physics_localPosition;
in float physics_localWaviness; in float physics_localWaviness;
#endif #endif
float physics_waveHeight(vec2 position, int iterations, float factor, float time) { float physics_waveHeight(vec2 position, int iterations, float factor, float time) {
position = (position - physics_waveOffset) * PHYSICS_XZ_SCALE * physics_oceanWaveHorizontalScale; position = (position - physics_waveOffset) * PHYSICS_XZ_SCALE * physics_oceanWaveHorizontalScale;
float iter = 0.0; float iter = 0.0;
@ -112,9 +126,98 @@ vec2 physics_waveDirection(vec2 position, int iterations, float time) {
return vec2(dx / pow(waveSum, 1.0 - PHYSICS_W_DETAIL)); return vec2(dx / pow(waveSum, 1.0 - PHYSICS_W_DETAIL));
} }
vec3 physics_waveNormal(vec2 position, float factor, float time) { // vec3 physics_waveNormal(vec2 position, float factor, float time) {
// vec2 wave = -physics_waveDirection(position.xy, physics_iterationsNormal, time);
// float oceanHeightFactor = physics_oceanHeight / 13.0;
// float totalFactor = oceanHeightFactor * factor;
// return normalize(vec3(wave.x * totalFactor, PHYSICS_NORMAL_STRENGTH, wave.y * totalFactor));
// }
// thank you Null. not sure if this is legal though lmfao
vec3 physics_waveNormal_ripples(vec2 position, float factor, float time) {
vec2 wave = -physics_waveDirection(position.xy, physics_iterationsNormal, time); vec2 wave = -physics_waveDirection(position.xy, physics_iterationsNormal, time);
float oceanHeightFactor = physics_oceanHeight / 13.0; float oceanHeightFactor = physics_oceanHeight / 13.0;
float totalFactor = oceanHeightFactor * factor; float totalFactor = oceanHeightFactor * factor;
return normalize(vec3(wave.x * totalFactor, PHYSICS_NORMAL_STRENGTH, wave.y * totalFactor)); vec3 waveNormal = normalize(vec3(wave.x * totalFactor, PHYSICS_NORMAL_STRENGTH, wave.y * totalFactor));
vec2 eyePosition = position + physics_modelOffset.xz;
vec2 rippleFetch = (eyePosition + vec2(physics_rippleRange)) / (physics_rippleRange * 2.0);
vec2 rippleTexelSize = vec2(2.0 / textureSize(physics_ripples, 0).x, 0.0);
float left = texture(physics_ripples, rippleFetch - rippleTexelSize.xy).r;
float right = texture(physics_ripples, rippleFetch + rippleTexelSize.xy).r;
float top = texture(physics_ripples, rippleFetch - rippleTexelSize.yx).r;
float bottom = texture(physics_ripples, rippleFetch + rippleTexelSize.yx).r;
float totalEffect = left + right + top + bottom;
float normalx = left - right;
float normalz = top - bottom;
vec3 rippleNormal = normalize(vec3(normalx, 1.0, normalz));
waveNormal = normalize(mix(waveNormal, rippleNormal, pow(totalEffect, 0.5)));
return waveNormal;
}
struct WavePixelData {
vec2 direction;
vec2 worldPos;
vec3 normal;
float foam;
float height;
} wave;
WavePixelData physics_wavePixel(const in vec2 position, const in float factor, const in float iterations, const in float time) {
vec2 wavePos = (position.xy - physics_waveOffset) * PHYSICS_XZ_SCALE * physics_oceanWaveHorizontalScale;
float iter = 0.0;
float frequency = PHYSICS_FREQUENCY;
float speed = PHYSICS_SPEED;
float weight = 1.0;
float height = 0.0;
float waveSum = 0.0;
float modifiedTime = time * PHYSICS_TIME_MULTIPLICATOR;
vec2 dx = vec2(0.0);
for (int i = 0; i < iterations; i++) {
vec2 direction = vec2(sin(iter), cos(iter));
float x = dot(direction, wavePos) * frequency + modifiedTime * speed;
float wave = exp(sin(x) - 1.0);
float result = wave * cos(x);
vec2 force = result * weight * direction;
dx += force / pow(weight, PHYSICS_W_DETAIL);
wavePos -= force * PHYSICS_DRAG_MULT;
height += wave * weight;
iter += PHYSICS_ITER_INC;
waveSum += weight;
weight *= PHYSICS_WEIGHT;
frequency *= PHYSICS_FREQUENCY_MULT;
speed *= PHYSICS_SPEED_MULT;
}
WavePixelData data;
data.direction = -vec2(dx / pow(waveSum, 1.0 - PHYSICS_W_DETAIL));
data.worldPos = wavePos / physics_oceanWaveHorizontalScale / PHYSICS_XZ_SCALE;
data.height = height / waveSum * physics_oceanHeight * factor - physics_oceanHeight * factor * 0.5;
data.normal = physics_waveNormal_ripples(position, factor, time);
float waveAmplitude = data.height * pow(max(data.normal.y, 0.0), 4.0);
vec2 waterUV = mix(position - physics_waveOffset, data.worldPos, clamp(factor * 2.0, 0.2, 1.0));
vec2 s1 = textureLod(physics_foam, vec3(waterUV * 0.26, vec3(time) / 360.0), 0).rg;
vec2 s2 = textureLod(physics_foam, vec3(waterUV * 0.02, vec3(time) / 360.0 + 0.5), 0).rg;
vec2 s3 = textureLod(physics_foam, vec3(waterUV * 0.1, vec3(time) / 360.0 + 1.0), 0).rg;
float waterSurfaceNoise = s1.r * s2.r * s3.r * 2.8 * physics_foamAmount;
waveAmplitude = clamp(waveAmplitude * 1.2, 0.0, 1.0);
waterSurfaceNoise = (1.0 - waveAmplitude) * waterSurfaceNoise + waveAmplitude * physics_foamAmount;
float worleyNoise = 0.2 + 0.8 * s1.g * (1.0 - s2.g);
float waterFoamMinSmooth = 0.45;
float waterFoamMaxSmooth = 2.0;
waterSurfaceNoise = smoothstep(waterFoamMinSmooth, 1.0, waterSurfaceNoise) * worleyNoise;
data.foam = clamp(waterFoamMaxSmooth * waterSurfaceNoise * physics_foamOpacity, 0.0, 1.0);
return data;
} }

View File

@ -323,7 +323,8 @@ float GetCloudShadow(vec3 eyePlayerPos){
shadow += GetAltostratusDensity(highShadowStart) * Alto_density; shadow += GetAltostratusDensity(highShadowStart) * Alto_density;
#endif #endif
shadow = clamp(exp(-shadow*10.0),0.0,1.0); shadow = shadow/2.0; // perhaps i should average the 2 shadows being added....
shadow = clamp(exp(-shadow*15.0),0.0,1.0);
return shadow; return shadow;
} }
@ -342,6 +343,8 @@ float GetCloudShadow_VLFOG(vec3 WorldPos){
shadow += GetAltostratusDensity(highShadowStart) * Alto_density; shadow += GetAltostratusDensity(highShadowStart) * Alto_density;
#endif #endif
// shadow = shadow/2.0; // perhaps i should average the 2 shadows being added....
shadow = clamp(exp(-shadow*15.0),0.0,1.0); shadow = clamp(exp(-shadow*15.0),0.0,1.0);
// do not allow it to exist above the lowest cloud plane // do not allow it to exist above the lowest cloud plane