mirror of
https://github.com/X0nk/Bliss-Shader.git
synced 2025-06-26 18:22:33 +08:00
re-add physics mod ocean support. tweak refraction strength falloff with distance
This commit is contained in:
@ -153,6 +153,11 @@ uniform float waterEnteredAltitude;
|
|||||||
#include "/lib/specular.glsl"
|
#include "/lib/specular.glsl"
|
||||||
#include "/lib/diffuse_lighting.glsl"
|
#include "/lib/diffuse_lighting.glsl"
|
||||||
|
|
||||||
|
#if defined PHYSICSMOD_OCEAN_SHADER
|
||||||
|
#include "/lib/oceans.glsl"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
float interleaved_gradientNoise_temporal(){
|
float interleaved_gradientNoise_temporal(){
|
||||||
#ifdef TAA
|
#ifdef TAA
|
||||||
return fract(52.9829189*fract(0.06711056*gl_FragCoord.x + 0.00583715*gl_FragCoord.y ) + 1.0/1.6180339887 * frameCounter);
|
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;
|
vec3 FragCoord = gl_FragCoord.xyz;
|
||||||
|
|
||||||
vec2 tempOffset = offsets[framemod8];
|
#ifdef TAA
|
||||||
|
vec2 tempOffset = offsets[framemod8];
|
||||||
vec3 viewPos = toScreenSpace(FragCoord*vec3(texelSize/RENDER_SCALE,1.0)-vec3(vec2(tempOffset)*texelSize*0.5, 0.0));
|
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;
|
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
|
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
|
#ifdef LARGE_WAVE_DISPLACEMENT
|
||||||
if (isWater){
|
if (isWater){
|
||||||
normal = viewToWorld(normal) ;
|
normal = viewToWorld(normal);
|
||||||
normal.xz = shitnormal.xy;
|
normal.xz = shitnormal.xy;
|
||||||
normal = worldToView(normal);
|
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.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);
|
||||||
|
|
||||||
#ifndef HAND
|
#if !defined HAND
|
||||||
if (isWater){
|
if (isWater){
|
||||||
vec3 playerPos = (mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz);
|
vec3 playerPos = (mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz);
|
||||||
vec3 waterPos = playerPos;
|
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
|
// tangent space normals for refraction
|
||||||
TangentNormal = NormalTex.xy;
|
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 = viewToWorld(normal);
|
||||||
worldSpaceNormal = normalize(viewToWorld(normal).xyz);
|
|
||||||
|
#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;
|
float nameTagMask = 0.0;
|
||||||
|
|
||||||
#if defined ENTITIES && defined IS_IRIS
|
#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
|
// if nothing is chosen, no smoothness and no reflectance
|
||||||
vec2 specularValues = vec2(1.0, 0.0);
|
vec2 specularValues = vec2(1.0, 0.0);
|
||||||
|
|
||||||
|
|
||||||
// hardcode specular values for select blocks like glass, water, and slime
|
// hardcode specular values for select blocks like glass, water, and slime
|
||||||
if(isReflective) specularValues = vec2(1.0, harcodedF0);
|
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;
|
float Shadows = 0.0;
|
||||||
#endif
|
#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);
|
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;
|
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);
|
if(gl_FragCoord.x*texelSize.x < 0.47) gl_FragData[0] = vec4(0.0);
|
||||||
#endif
|
#endif
|
||||||
#if DEBUG_VIEW == debug_NORMALS
|
#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;
|
gl_FragData[0].a = 1;
|
||||||
#endif
|
#endif
|
||||||
#if DEBUG_VIEW == debug_INDIRECT
|
#if DEBUG_VIEW == debug_INDIRECT
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
uniform float frameTimeCounter;
|
uniform float frameTimeCounter;
|
||||||
#include "/lib/Shadow_Params.glsl"
|
#include "/lib/Shadow_Params.glsl"
|
||||||
|
|
||||||
|
#if defined PHYSICSMOD_OCEAN_SHADER
|
||||||
|
#include "/lib/oceans.glsl"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
!! DO NOT REMOVE !!
|
!! DO NOT REMOVE !!
|
||||||
This code is from Chocapic13' shaders
|
This code is from Chocapic13' shaders
|
||||||
@ -111,12 +115,25 @@ vec3 getWaveNormal(vec3 posxz, float range){
|
|||||||
|
|
||||||
void main() {
|
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_MultiTexCoord0).xy;
|
||||||
lmtexcoord.xy = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
|
lmtexcoord.xy = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
|
||||||
vec2 lmcoord = gl_MultiTexCoord1.xy / 240.0;
|
vec2 lmcoord = gl_MultiTexCoord1.xy / 240.0;
|
||||||
lmtexcoord.zw = lmcoord;
|
lmtexcoord.zw = lmcoord;
|
||||||
|
|
||||||
vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
|
|
||||||
|
|
||||||
#ifdef LARGE_WAVE_DISPLACEMENT
|
#ifdef LARGE_WAVE_DISPLACEMENT
|
||||||
if(mc_Entity.x == 8.0) {
|
if(mc_Entity.x == 8.0) {
|
||||||
@ -184,8 +201,8 @@ void main() {
|
|||||||
binormal = normalize(cross(tangent2.rgb,normalMat.xyz)*at_tangent.w);
|
binormal = normalize(cross(tangent2.rgb,normalMat.xyz)*at_tangent.w);
|
||||||
|
|
||||||
mat3 tbnMatrix = mat3(tangent2.x, binormal.x, normalMat.x,
|
mat3 tbnMatrix = mat3(tangent2.x, binormal.x, normalMat.x,
|
||||||
tangent2.y, binormal.y, normalMat.y,
|
tangent2.y, binormal.y, normalMat.y,
|
||||||
tangent2.z, binormal.z, normalMat.z);
|
tangent2.z, binormal.z, normalMat.z);
|
||||||
|
|
||||||
flatnormal = normalMat.xyz;
|
flatnormal = normalMat.xyz;
|
||||||
|
|
||||||
|
@ -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.
|
// 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);
|
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 diffractionMult = 0.035;
|
||||||
float smudgeMult = 1.0;
|
float smudgeMult = 1.0;
|
||||||
|
|
||||||
|
232
shaders/lib/oceans.glsl
Normal file
232
shaders/lib/oceans.glsl
Normal file
@ -0,0 +1,232 @@
|
|||||||
|
// THIS FILE IS PUBLIC DOMAIN SO USE IT HOWEVER YOU WANT!
|
||||||
|
// to make it compatible with your shaderpack use:
|
||||||
|
#define PHYSICS_OCEAN_SUPPORT
|
||||||
|
// at the top of your file. When used my mod no longer injects code into
|
||||||
|
// your shaderpack. It replaces this define statement (before compilation) with
|
||||||
|
#define PHYSICS_OCEAN
|
||||||
|
// so you can use
|
||||||
|
#ifdef PHYSICS_OCEAN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// #ifdef PhysicsMod_support
|
||||||
|
// 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
|
||||||
|
// the overall shape must stay consistent because it is also computed on the CPU side
|
||||||
|
// to offset entities (though a custom CPU integration of your shader is possible by
|
||||||
|
// contacting me on my discord server https://discord.gg/VsNs9xP)
|
||||||
|
const int PHYSICS_ITERATIONS_OFFSET = 13;
|
||||||
|
const float PHYSICS_DRAG_MULT = 0.048;
|
||||||
|
const float PHYSICS_XZ_SCALE = 0.035;
|
||||||
|
const float PHYSICS_TIME_MULTIPLICATOR = 0.45;
|
||||||
|
const float PHYSICS_W_DETAIL = 0.75;
|
||||||
|
const float PHYSICS_FREQUENCY = 6.0;
|
||||||
|
const float PHYSICS_SPEED = 2.0;
|
||||||
|
const float PHYSICS_WEIGHT = 0.8;
|
||||||
|
const float PHYSICS_FREQUENCY_MULT = 1.18;
|
||||||
|
const float PHYSICS_SPEED_MULT = 1.07;
|
||||||
|
const float PHYSICS_ITER_INC = 12.0;
|
||||||
|
const float PHYSICS_NORMAL_STRENGTH = 0.6;
|
||||||
|
|
||||||
|
// this is the surface detail from the physics options, ranges from 13 to 48 (yeah I know weird)
|
||||||
|
uniform int physics_iterationsNormal;
|
||||||
|
// used to offset the 0 point of wave meshes to keep the wave function consistent even
|
||||||
|
// though the mesh totally changes
|
||||||
|
uniform vec2 physics_waveOffset;
|
||||||
|
// used for offsetting the local position to fetch the right pixel of the waviness texture
|
||||||
|
uniform ivec2 physics_textureOffset;
|
||||||
|
// time in seconds that can go faster dependent on weather conditions (affected by weather strength
|
||||||
|
// multiplier in ocean settings
|
||||||
|
uniform float physics_gameTime;
|
||||||
|
// base value is 13 and gets multiplied by wave height in ocean settings
|
||||||
|
uniform float physics_oceanHeight;
|
||||||
|
// basic texture to determine how shallow/far away from the shore the water is
|
||||||
|
uniform sampler2D physics_waviness;
|
||||||
|
// basic scale for the horizontal size of the waves
|
||||||
|
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;
|
||||||
|
|
||||||
|
#if defined PHYSICSMOD_VERTEX
|
||||||
|
// for the vertex shader stage
|
||||||
|
out vec3 physics_localPosition;
|
||||||
|
out float physics_localWaviness;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined PHYSICSMOD_FRAGMENT
|
||||||
|
// for the fragment shader stage
|
||||||
|
in vec3 physics_localPosition;
|
||||||
|
in float physics_localWaviness;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
float physics_waveHeight(vec2 position, int iterations, float factor, float time) {
|
||||||
|
position = (position - 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;
|
||||||
|
|
||||||
|
for (int i = 0; i < iterations; i++) {
|
||||||
|
vec2 direction = vec2(sin(iter), cos(iter));
|
||||||
|
float x = dot(direction, position) * frequency + modifiedTime * speed;
|
||||||
|
float wave = exp(sin(x) - 1.0);
|
||||||
|
float result = wave * cos(x);
|
||||||
|
vec2 force = result * weight * direction;
|
||||||
|
|
||||||
|
position -= force * PHYSICS_DRAG_MULT;
|
||||||
|
height += wave * weight;
|
||||||
|
iter += PHYSICS_ITER_INC;
|
||||||
|
waveSum += weight;
|
||||||
|
weight *= PHYSICS_WEIGHT;
|
||||||
|
frequency *= PHYSICS_FREQUENCY_MULT;
|
||||||
|
speed *= PHYSICS_SPEED_MULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return height / waveSum * physics_oceanHeight * factor - physics_oceanHeight * factor * 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 physics_waveDirection(vec2 position, int iterations, float time) {
|
||||||
|
position = (position - physics_waveOffset) * PHYSICS_XZ_SCALE * physics_oceanWaveHorizontalScale;
|
||||||
|
float iter = 0.0;
|
||||||
|
float frequency = PHYSICS_FREQUENCY;
|
||||||
|
float speed = PHYSICS_SPEED;
|
||||||
|
float weight = 1.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, position) * 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);
|
||||||
|
position -= force * PHYSICS_DRAG_MULT;
|
||||||
|
iter += PHYSICS_ITER_INC;
|
||||||
|
waveSum += weight;
|
||||||
|
weight *= PHYSICS_WEIGHT;
|
||||||
|
frequency *= PHYSICS_FREQUENCY_MULT;
|
||||||
|
speed *= PHYSICS_SPEED_MULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return vec2(dx / pow(waveSum, 1.0 - PHYSICS_W_DETAIL));
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 physics_waveNormal(const in vec2 position, const in vec2 direction, const in float factor, const in float time) {
|
||||||
|
float oceanHeightFactor = physics_oceanHeight / 13.0;
|
||||||
|
float totalFactor = oceanHeightFactor * factor;
|
||||||
|
vec3 waveNormal = normalize(vec3(direction.x * totalFactor, PHYSICS_NORMAL_STRENGTH, direction.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));
|
||||||
|
return normalize(mix(waveNormal, rippleNormal, pow(totalEffect, 0.5)));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct WavePixelData {
|
||||||
|
vec2 direction;
|
||||||
|
vec2 worldPos;
|
||||||
|
vec3 normal;
|
||||||
|
float foam;
|
||||||
|
float height;
|
||||||
|
};
|
||||||
|
|
||||||
|
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(position, data.direction, 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, time / 360.0), 0).rg;
|
||||||
|
vec2 s2 = textureLod(physics_foam, vec3(waterUV * 0.02, time / 360.0 + 0.5), 0).rg;
|
||||||
|
vec2 s3 = textureLod(physics_foam, vec3(waterUV * 0.1, 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;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
// VERTEX STAGE
|
||||||
|
void main() {
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
// now use finalPosition instead of gl_Vertex
|
||||||
|
}
|
||||||
|
|
||||||
|
// FRAGMENT STAGE
|
||||||
|
void main() {
|
||||||
|
WavePixelData wave = physics_wavePixel(physics_localPosition.xz, physics_localWaviness, physics_iterationsNormal, physics_gameTime);
|
||||||
|
|
||||||
|
// access the wave struct data however you want, wave.normal is in world space, wave.foam is the final foam amount
|
||||||
|
}
|
||||||
|
*/
|
@ -119,7 +119,7 @@ vec3 rayTraceSpeculars(vec3 dir, vec3 position, float dither, float quality, boo
|
|||||||
|
|
||||||
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) + stepv*(dither-0.5);
|
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) + stepv*(dither-0.5);
|
||||||
|
|
||||||
#ifdef DEFERRED_SPECULAR
|
#if defined DEFERRED_SPECULAR && defined TAA
|
||||||
spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE;
|
spos.xy += TAA_Offset*texelSize*0.5/RENDER_SCALE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -130,12 +130,9 @@ vec3 rayTraceSpeculars(vec3 dir, vec3 position, float dither, float quality, boo
|
|||||||
|
|
||||||
float sp = invLinZ(sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4.0),0).a/65000.0));
|
float sp = invLinZ(sqrt(texelFetch2D(colortex4,ivec2(spos.xy/texelSize/4.0),0).a/65000.0));
|
||||||
|
|
||||||
// if(hand) convertHandDepth(sp);
|
|
||||||
|
|
||||||
float currZ = linZ(spos.z);
|
float currZ = linZ(spos.z);
|
||||||
float nextZ = linZ(sp);
|
float nextZ = linZ(sp);
|
||||||
|
|
||||||
// if(abs(nextZ-currZ) < mix(0.005,0.5,currZ*currZ) && sp < max(minZ,maxZ) && sp > min(minZ,maxZ)) return vec3(spos.xy/RENDER_SCALE,sp);
|
|
||||||
if(sp < max(minZ,maxZ) && sp > min(minZ,maxZ)) return vec3(spos.xy/RENDER_SCALE,sp);
|
if(sp < max(minZ,maxZ) && sp > min(minZ,maxZ)) return vec3(spos.xy/RENDER_SCALE,sp);
|
||||||
|
|
||||||
minZ = maxZ-biasAmount / currZ;
|
minZ = maxZ-biasAmount / currZ;
|
||||||
@ -162,7 +159,7 @@ vec4 screenSpaceReflections(
|
|||||||
vec4 reflection = vec4(0.0);
|
vec4 reflection = vec4(0.0);
|
||||||
|
|
||||||
float reflectionLength = 0.0;
|
float reflectionLength = 0.0;
|
||||||
float quality = 30.0f;//mix(10.0f, 30.0f, fresnel);
|
float quality = 30.0f;
|
||||||
|
|
||||||
vec3 raytracePos = rayTraceSpeculars(reflectedVector, viewPos, noise, quality, isHand, reflectionLength, fresnel);
|
vec3 raytracePos = rayTraceSpeculars(reflectedVector, viewPos, noise, quality, isHand, reflectionLength, fresnel);
|
||||||
|
|
||||||
|
7
shaders/world0/physics_ocean.fsh
Normal file
7
shaders/world0/physics_ocean.fsh
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#version 120
|
||||||
|
|
||||||
|
#define PHYSICSMOD_FRAGMENT
|
||||||
|
#define PHYSICSMOD_OCEAN_SHADER
|
||||||
|
#define OVERWORLD_SHADER
|
||||||
|
|
||||||
|
#include "/dimensions/all_translucent.fsh"
|
7
shaders/world0/physics_ocean.vsh
Normal file
7
shaders/world0/physics_ocean.vsh
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#version 120
|
||||||
|
|
||||||
|
#define PHYSICSMOD_VERTEX
|
||||||
|
#define PHYSICSMOD_OCEAN_SHADER
|
||||||
|
#define OVERWORLD_SHADER
|
||||||
|
|
||||||
|
#include "/dimensions/all_translucent.vsh"
|
Reference in New Issue
Block a user