re-add physics mod ocean support. tweak refraction strength falloff with distance

This commit is contained in:
Xonk
2025-04-01 20:36:18 -04:00
parent 450ec181e4
commit 9ce449690a
7 changed files with 317 additions and 19 deletions

View File

@ -153,6 +153,11 @@ uniform float waterEnteredAltitude;
#include "/lib/specular.glsl"
#include "/lib/diffuse_lighting.glsl"
#if defined PHYSICSMOD_OCEAN_SHADER
#include "/lib/oceans.glsl"
#endif
float interleaved_gradientNoise_temporal(){
#ifdef TAA
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887 * frameCounter);
@ -395,9 +400,12 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
vec3 FragCoord = gl_FragCoord.xyz;
vec2 tempOffset = offsets[framemod8];
vec3 viewPos = toScreenSpace(FragCoord*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5, 0.0));
#ifdef TAA
vec2 tempOffset = offsets[framemod8];
vec3 viewPos = toScreenSpace(FragCoord*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5, 0.0));
#else
vec3 viewPos = toScreenSpace(FragCoord*vec3(texelSize/RENDER_SCALE,1.0));
#endif
vec3 feetPlayerPos = mat3(gbufferModelViewInverse) * viewPos;
////////////////////////////////////////////////////////////////////////////////
@ -465,9 +473,31 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
vec3 normal = normalMat.xyz; // in viewSpace
#if defined PHYSICSMOD_OCEAN_SHADER && defined PHYSICS_OCEAN
WavePixelData wave = physics_wavePixel(physics_localPosition.xz, physics_localWaviness, physics_iterationsNormal, physics_gameTime);
#if defined DISTANT_HORIZONS
float PHYSICS_OCEAN_TRANSITION = 1.0-pow(1.0-pow(1.0-clamp(1.0-length(feetPlayerPos.xz)/max(far,0.0),0,1),5),5);
#else
float PHYSICS_OCEAN_TRANSITION = 0.0;
#endif
if (isWater){
if (!gl_FrontFacing) {
wave.normal = -wave.normal;
}
normal = mix(normalize(gl_NormalMatrix * wave.normal), normal, PHYSICS_OCEAN_TRANSITION);
Albedo = mix(Albedo, vec3(1.0), wave.foam);
gl_FragData[0].a = mix(1.0/255.0, 1.0, wave.foam);
}
#endif
#ifdef LARGE_WAVE_DISPLACEMENT
if (isWater){
normal = viewToWorld(normal) ;
normal = viewToWorld(normal);
normal.xz = shitnormal.xy;
normal = worldToView(normal);
}
@ -485,7 +515,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 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);
#ifndef HAND
#if !defined HAND
if (isWater){
vec3 playerPos = (mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz);
vec3 waterPos = playerPos;
@ -510,11 +540,19 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
// tangent space normals for refraction
TangentNormal = NormalTex.xy;
#if defined PHYSICSMOD_OCEAN_SHADER && defined PHYSICS_OCEAN
normal = applyBump(tbnMatrix, NormalTex.xyz, PHYSICS_OCEAN_TRANSITION);
#else
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
#endif
normal = applyBump(tbnMatrix, NormalTex.xyz, 1.0);
worldSpaceNormal = normalize(viewToWorld(normal).xyz);
worldSpaceNormal = viewToWorld(normal);
#if defined PHYSICSMOD_OCEAN_SHADER && defined PHYSICS_OCEAN
if (isWater) TangentNormal = normalize(wave.normal).xz;
#endif
// TangentNormal = clamp(TangentNormal + (blueNoise()*2.0-1.0)*0.005,-1.0,1.0);
float nameTagMask = 0.0;
#if defined ENTITIES && defined IS_IRIS
@ -678,6 +716,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
// if nothing is chosen, no smoothness and no reflectance
vec2 specularValues = vec2(1.0, 0.0);
// hardcode specular values for select blocks like glass, water, and slime
if(isReflective) specularValues = vec2(1.0, harcodedF0);
@ -708,7 +747,6 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
float Shadows = 0.0;
#endif
vec3 specularReflections = specularReflections(viewPos, normalize(feetPlayerPos), WsunVec, vec3(blueNoise(), vec2(interleaved_gradientNoise_temporal())), worldSpaceNormal, roughness, f0, Albedo, FinalColor*gl_FragData[0].a, DirectLightColor * Shadows, lightmap.y, isHand, isWater, reflectance, flashLightSpecularData);
gl_FragData[0].a = gl_FragData[0].a + (1.0-gl_FragData[0].a) * reflectance;
@ -749,7 +787,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
if(gl_FragCoord.x*texelSize.x < 0.47) gl_FragData[0] = vec4(0.0);
#endif
#if DEBUG_VIEW == debug_NORMALS
gl_FragData[0].rgb = worldSpaceNormal * 0.1;
gl_FragData[0].rgb = vec3(worldSpaceNormal.x,worldSpaceNormal.y*0,worldSpaceNormal.z*0) * 0.1;
gl_FragData[0].a = 1;
#endif
#if DEBUG_VIEW == debug_INDIRECT

View File

@ -6,6 +6,10 @@
uniform float frameTimeCounter;
#include "/lib/Shadow_Params.glsl"
#if defined PHYSICSMOD_OCEAN_SHADER
#include "/lib/oceans.glsl"
#endif
/*
!! DO NOT REMOVE !!
This code is from Chocapic13' shaders
@ -111,12 +115,25 @@ vec3 getWaveNormal(vec3 posxz, float range){
void main() {
#if defined PHYSICSMOD_OCEAN_SHADER && defined PHYSICS_OCEAN
// basic texture to determine how shallow/far away from the shore the water is
physics_localWaviness = texelFetch(physics_waviness, ivec2(gl_Vertex.xz) - physics_textureOffset, 0).r;
// transform gl_Vertex (since it is the raw mesh, i.e. not transformed yet)
vec4 finalPosition = vec4(gl_Vertex.x, gl_Vertex.y + physics_waveHeight(gl_Vertex.xz, PHYSICS_ITERATIONS_OFFSET, physics_localWaviness, physics_gameTime), gl_Vertex.z, gl_Vertex.w);
// pass this to the fragment shader to fetch the texture there for per fragment normals
physics_localPosition = finalPosition.xyz;
vec3 position = mat3(gl_ModelViewMatrix) * vec3(finalPosition) + gl_ModelViewMatrix[3].xyz;
#else
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
#endif
// 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;
#ifdef LARGE_WAVE_DISPLACEMENT
if(mc_Entity.x == 8.0) {
@ -184,8 +201,8 @@ void main() {
binormal = normalize(cross(tangent2.rgb,normalMat.xyz)*at_tangent.w);
mat3 tbnMatrix = mat3(tangent2.x, binormal.x, normalMat.x,
tangent2.y, binormal.y, normalMat.y,
tangent2.z, binormal.z, normalMat.z);
tangent2.y, binormal.y, normalMat.y,
tangent2.z, binormal.z, normalMat.z);
flatnormal = normalMat.xyz;

View File

@ -190,7 +190,7 @@ vec3 doRefractionEffect( inout vec2 texcoord, vec2 normal, float linearDistance,
// make the tangent space normals match the directions of the texcoord UV, this greatly improves the refraction effect.
vec2 UVNormal = vec2(normal.x,-normal.y);
float refractionMult = 0.3 / (1.0 + linearDistance);
float refractionMult = 0.3 / (1.0 + linearDistance*0.5);
float diffractionMult = 0.035;
float smudgeMult = 1.0;