centralize vertex displacement code. fix SSS on mobs/random blocks. add voxy support disclaimer to world curvature.

This commit is contained in:
Xonk
2026-02-13 18:33:34 -05:00
parent 5ef39ede12
commit 42f210516c
12 changed files with 104 additions and 101 deletions
+29 -2
View File
@@ -1,5 +1,6 @@
#define ANTIALIASING_RELATED_SETTINGS
#define DEPTH_OF_FIELD_RELATED_SETTINGS
#define GEOMETRY_ANIMATION_RELATED_SETTINGS
#include "/lib/settings.glsl"
#include "/lib/res_params.glsl"
@@ -8,7 +9,6 @@ varying vec4 gcolor;
uniform vec2 texelSize;
#if DOF_QUALITY == 5
uniform int hideGUI;
uniform int frameCounter;
@@ -17,12 +17,39 @@ uniform vec2 texelSize;
uniform float far;
#include "/lib/bokeh.glsl"
#endif
uniform vec3 cameraPosition;
uniform int frameTimeCounter;
uniform mat4 dhProjection;
uniform mat4 gbufferModelView;
uniform mat4 gbufferModelViewInverse;
#include "/lib/TAA_jitter.glsl"
#include "/lib/vertex_displacement.glsl"
void main() {
gl_Position = ftransform();
// gl_Position = ftransform();
vec4 vPos = gl_Vertex;
vec3 cameraOffset = fract(cameraPosition);
vPos.xyz = floor(vPos.xyz + cameraOffset + 0.5) - cameraOffset;
vec4 viewPos = gl_ModelViewMatrix * vPos;
vec4 localPos = gbufferModelViewInverse * viewPos;
#if CURVATURE_AMOUNT != 0
vec4 worldPos = localPos;
applyWorldCurvature(worldPos.xyz);
worldPos = gbufferModelView * worldPos;
gl_Position = dhProjection * worldPos;
#else
gl_Position = dhProjection * viewPos;
#endif
#if TAA_MODE == 3
gl_Position.xy = gl_Position.xy * RENDER_SCALE + RENDER_SCALE * gl_Position.w - gl_Position.w;
+4 -13
View File
@@ -1,6 +1,7 @@
#define ANTIALIASING_RELATED_SETTINGS
#define SEASONS_RELATED_SETTINGS
#define DEPTH_OF_FIELD_RELATED_SETTINGS
#define GEOMETRY_ANIMATION_RELATED_SETTINGS
#include "/lib/settings.glsl"
#include "/lib/res_params.glsl"
@@ -28,8 +29,10 @@ uniform float screenBrightness;
#endif
uniform int frameTimeCounter;
#include "/lib/TAA_jitter.glsl"
#include "/lib/vertex_displacement.glsl"
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferModelView;
@@ -49,16 +52,6 @@ vec4 toClipSpace3(vec3 viewSpacePosition) {
void main() {
// vec3 position = mat3(gl_ModelViewMatrix) * vec3(gl_Vertex) + gl_ModelViewMatrix[3].xyz;
// vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz;
// #ifdef PLANET_CURVATURE
// float curvature = length(worldpos) / (16*8);
// worldpos.y -= curvature*curvature * CURVATURE_AMOUNT;
// #endif
// position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
// gl_Position = toClipSpace3(position);
vec4 vPos = gl_Vertex;
vec3 cameraOffset = fract(cameraPosition);
@@ -70,11 +63,9 @@ void main() {
#if CURVATURE_AMOUNT != 0
vec4 worldPos = localPos;
float curvature = length(worldPos) / (16*8);
worldPos.y -= curvature*curvature * (float(CURVATURE_AMOUNT)/10.0f);
applyWorldCurvature(worldPos.xyz);
worldPos = gbufferModelView * worldPos;
gl_Position = dhProjection * worldPos;
#else
gl_Position = dhProjection * viewPos;
+5 -4
View File
@@ -1,5 +1,6 @@
#define ANTIALIASING_RELATED_SETTINGS
#define DEPTH_OF_FIELD_RELATED_SETTINGS
#define GEOMETRY_ANIMATION_RELATED_SETTINGS
#include "/lib/settings.glsl"
#include "/lib/res_params.glsl"
@@ -43,9 +44,11 @@ uniform float far;
#endif
uniform int frameTimeCounter;
#include "/lib/TAA_jitter.glsl"
#include "/lib/vertex_displacement.glsl"
uniform vec3 cameraPosition;
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
@@ -61,12 +64,10 @@ void main() {
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz;
// worldpos.y -= length(worldpos)/(16*2);
#if CURVATURE_AMOUNT != 0
float curvature = length(worldpos) / (16*8);
worldpos.y -= curvature*curvature * (float(CURVATURE_AMOUNT)/10.0f);
applyWorldCurvature(worldpos);
#endif
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
gl_Position = toClipSpace3(position);
+4 -6
View File
@@ -1,5 +1,6 @@
#define HANDHELD_LIGHTSOURCE_RELATED_SETTINGS
#define ANTIALIASING_RELATED_SETTINGS
#define GEOMETRY_ANIMATION_RELATED_SETTINGS
#include "/lib/settings.glsl"
#include "/lib/res_params.glsl"
#include "/lib/items.glsl"
@@ -44,6 +45,7 @@ uniform int heldItemId;
uniform int heldItemId2;
#include "/lib/TAA_jitter.glsl"
#include "/lib/vertex_displacement.glsl"
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
@@ -51,9 +53,6 @@ vec4 toClipSpace3(vec3 viewSpacePosition) {
return vec4(projMAD(gl_ProjectionMatrix, viewSpacePosition),-viewSpacePosition.z);
}
#ifdef DAMAGE_BLOCK_EFFECT
varying vec4 vtexcoordam; // .st for add, .pq for mul
varying vec4 vtexcoord;
@@ -103,9 +102,8 @@ void main() {
}
#endif
#if defined LINES && CURVATURE_AMOUNT != 0
float curvature = length(worldpos) / (16*8);
worldpos.y -= curvature*curvature * (float(CURVATURE_AMOUNT)/10.0f);
#if defined LINES && CURVATURE_AMOUNT != 0
applyWorldCurvature(worldpos);
#endif
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
+10 -35
View File
@@ -3,6 +3,7 @@
#define DEPTH_OF_FIELD_RELATED_SETTINGS
#define GEOMETRY_ANIMATION_RELATED_SETTINGS
#define SEASONS_RELATED_SETTINGS
#define SUB_SURFACE_SCATTERING_RELATED_SETTINGS
#include "/lib/settings.glsl"
#include "/lib/res_params.glsl"
#include "/lib/bokeh.glsl"
@@ -38,6 +39,7 @@ flat varying float EMISSIVE;
flat varying int LIGHTNING;
flat varying int PORTAL;
flat varying int SIGN;
flat varying int SHADOWBIAS_OFFSET_MASK;
flat varying float blockID;
flat varying int NameTags;
@@ -59,8 +61,8 @@ uniform float frameTimeCounter;
uniform sampler2D noisetex;//depth
const float PI48 = 150.796447372*WAVY_SPEED;
float pi2wt = PI48*frameTimeCounter;
#include "/lib/vertex_displacement.glsl"
#if defined HAND
uniform mat4 gbufferPreviousModelView;
@@ -84,33 +86,6 @@ vec4 toClipSpace3(vec3 viewSpacePosition) {
return vec4(projMAD(gl_ProjectionMatrix, viewSpacePosition),-viewSpacePosition.z);
}
vec2 calcWave(in vec3 pos) {
float magnitude = abs(sin(dot(vec4(frameTimeCounter, pos),vec4(1.0,0.005,0.005,0.005)))*0.5+0.72)*0.013;
vec2 ret = (sin(pi2wt*vec2(0.0063,0.0015)*4. - pos.xz + pos.y*0.05)+0.1)*magnitude;
return ret;
}
vec3 calcMovePlants(in vec3 pos) {
vec2 move1 = calcWave(pos );
float move1y = -length(move1);
return vec3(move1.x,move1y,move1.y)*5.*WAVY_STRENGTH;
}
vec3 calcWaveLeaves(in vec3 pos, in float fm, in float mm, in float ma, in float f0, in float f1, in float f2, in float f3, in float f4, in float f5) {
float magnitude = abs(sin(dot(vec4(frameTimeCounter, pos),vec4(1.0,0.005,0.005,0.005)))*0.5+0.72)*0.013;
vec3 ret = (sin(pi2wt*vec3(0.0063,0.0224,0.0015)*1.5 - pos))*magnitude;
return ret;
}
vec3 calcMoveLeaves(in vec3 pos, in float f0, in float f1, in float f2, in float f3, in float f4, in float f5, in vec3 amp1, in vec3 amp2) {
vec3 move1 = calcWaveLeaves(pos , 0.0054, 0.0400, 0.0400, 0.0127, 0.0089, 0.0114, 0.0063, 0.0224, 0.0015) * amp1;
return move1*5.*WAVY_STRENGTH;
}
float densityAtPos(in vec3 pos){
pos /= 18.;
pos.xz *= 0.5;
@@ -195,6 +170,7 @@ void main() {
PORTAL = 0;
SIGN = 0;
SHADOWBIAS_OFFSET_MASK = 0;
#if defined WORLD && !defined HAND
if(blockEntityId == BLOCK_SIGN) SIGN = 1;
@@ -236,7 +212,7 @@ void main() {
/////// ----- SSS STUFF ----- ///////
SSSAMOUNT = 0.0;
#ifdef WORLD
#if defined WORLD || defined ENTITIES
/////// ----- SSS ON BLOCKS ----- ///////
// strong
if (
@@ -291,7 +267,6 @@ void main() {
if(blockEntityId == BLOCK_SSS_WEAK_3) SSSAMOUNT = 0.4;
// low
#endif
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz;
@@ -326,14 +301,14 @@ void main() {
#endif
#if CURVATURE_AMOUNT != 0
float curvature = length(worldpos) / (16*8);
worldpos.y -= curvature*curvature * (float(CURVATURE_AMOUNT)/10.0f);
applyWorldCurvature(worldpos);
#endif
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
// ensure hand/entities have the same transformations as the spidereyes and enchant glint programs.
#if !defined ENTITIES && !defined HAND
// will do world curvature here soon, needs the same transformations as enchant glint to avoid zfighting
#if !defined HAND && !defined ENTITIES
gl_Position = toClipSpace3(position);
#endif
#endif
+3 -2
View File
@@ -3,6 +3,7 @@
#define DEPTH_OF_FIELD_RELATED_SETTINGS
#define SHADOWMAP_CONSTANT_RELATED_SETTINGS
#define WATER_RELATED_SETTINGS
#define GEOMETRY_ANIMATION_RELATED_SETTINGS
#include "/lib/settings.glsl"
#include "/lib/res_params.glsl"
#include "/lib/bokeh.glsl"
@@ -83,6 +84,7 @@ uniform vec2 texelSize;
#include "/lib/TAA_jitter.glsl"
#include "/lib/vertex_displacement.glsl"
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
@@ -171,8 +173,7 @@ void main() {
vec3 worldpos = mat3(gbufferModelViewInverse) * position + gbufferModelViewInverse[3].xyz;
#if CURVATURE_AMOUNT != 0
float curvature = length(worldpos) / (16*8);
worldpos.y -= curvature*curvature * (float(CURVATURE_AMOUNT)/10.0f);
applyWorldCurvature(worldpos);
#endif
position = mat3(gbufferModelView) * worldpos + gbufferModelView[3].xyz;
@@ -2,6 +2,9 @@
#include "/lib/settings.glsl"
#include "/lib/res_params.glsl"
// will do soon, needs the same transformations as entities so that enchant glint does not zfight
// #include "/lib/vertex_displacement.glsl"
/*
!! DO NOT REMOVE !!
This code is from Chocapic13' shaders
+1 -1
View File
@@ -999,7 +999,7 @@ screen.World = World
value.FOLIAGE_ANIMATION_AMOUNT.0 = §cOFF
suffix.FOLIAGE_ANIMATION_AMOUNT = %
option.CURVATURE_AMOUNT = Planet Curvature Amount
option.CURVATURE_AMOUNT = Planet Curvature Amount §bⓘ Voxy Not Supported§r
value.CURVATURE_AMOUNT.0 = §cOFF
suffix.CURVATURE_AMOUNT = %
+35
View File
@@ -0,0 +1,35 @@
const float PI48 = 150.796447372*WAVY_SPEED;
float pi2wt = PI48*frameTimeCounter;
vec2 calcWave(in vec3 pos) {
float magnitude = abs(sin(dot(vec4(frameTimeCounter, pos),vec4(1.0,0.005,0.005,0.005)))*0.5+0.72)*0.013;
vec2 ret = (sin(pi2wt*vec2(0.0063,0.0015)*4. - pos.xz + pos.y*0.05)+0.1)*magnitude;
return ret;
}
vec3 calcMovePlants(in vec3 pos) {
vec2 move1 = calcWave(pos );
float move1y = -length(move1);
return vec3(move1.x,move1y,move1.y)*5.*WAVY_STRENGTH;
}
vec3 calcWaveLeaves(in vec3 pos, in float fm, in float mm, in float ma, in float f0, in float f1, in float f2, in float f3, in float f4, in float f5) {
float magnitude = abs(sin(dot(vec4(frameTimeCounter, pos),vec4(1.0,0.005,0.005,0.005)))*0.5+0.72)*0.013;
vec3 ret = (sin(pi2wt*vec3(0.0063,0.0224,0.0015)*1.5 - pos))*magnitude;
return ret;
}
vec3 calcMoveLeaves(in vec3 pos, in float f0, in float f1, in float f2, in float f3, in float f4, in float f5, in vec3 amp1, in vec3 amp2) {
vec3 move1 = calcWaveLeaves(pos , 0.0054, 0.0400, 0.0400, 0.0127, 0.0089, 0.0114, 0.0063, 0.0224, 0.0015) * amp1;
return move1*5.*WAVY_STRENGTH;
}
void applyWorldCurvature(inout vec3 worldPos){
float curvature = length(worldPos) / (16.0*8.0);
worldPos.y -= curvature*curvature * (float(CURVATURE_AMOUNT)/10.0f);
}
+6 -34
View File
@@ -12,7 +12,6 @@
#define RENDER_SHADOW
/*
!! DO NOT REMOVE !!
This code is from Chocapic13' shaders
@@ -71,35 +70,6 @@ uniform int entityId;
#include "/lib/voxel_write.glsl"
#endif
const float PI48 = 150.796447372*WAVY_SPEED;
float pi2wt = PI48*frameTimeCounter;
vec2 calcWave(in vec3 pos) {
float magnitude = abs(sin(dot(vec4(frameTimeCounter, pos),vec4(1.0,0.005,0.005,0.005)))*0.5+0.72)*0.013;
vec2 ret = (sin(pi2wt*vec2(0.0063,0.0015)*4. - pos.xz + pos.y*0.05)+0.1)*magnitude;
return ret;
}
vec3 calcMovePlants(in vec3 pos) {
vec2 move1 = calcWave(pos );
float move1y = -length(move1);
return vec3(move1.x,move1y,move1.y)*5.*WAVY_STRENGTH/255.0;
}
vec3 calcWaveLeaves(in vec3 pos, in float fm, in float mm, in float ma, in float f0, in float f1, in float f2, in float f3, in float f4, in float f5) {
float magnitude = abs(sin(dot(vec4(frameTimeCounter, pos),vec4(1.0,0.005,0.005,0.005)))*0.5+0.72)*0.013;
vec3 ret = (sin(pi2wt*vec3(0.0063,0.0224,0.0015)*1.5 - pos))*magnitude;
return ret;
}
vec3 calcMoveLeaves(in vec3 pos, in float f0, in float f1, in float f2, in float f3, in float f4, in float f5, in vec3 amp1, in vec3 amp2) {
vec3 move1 = calcWaveLeaves(pos , 0.0054, 0.0400, 0.0400, 0.0127, 0.0089, 0.0114, 0.0063, 0.0224, 0.0015) * amp1;
return move1*5.*WAVY_STRENGTH/255.;
}
bool intersectCone(float coneHalfAngle, vec3 coneTip , vec3 coneAxis, vec3 rayOrig, vec3 rayDir, float maxZ)
{
vec3 co = rayOrig - coneTip;
@@ -119,6 +89,9 @@ bool intersectCone(float coneHalfAngle, vec3 coneTip , vec3 coneAxis, vec3 rayOr
return true;
}
#include "/lib/vertex_displacement.glsl"
#define diagonal3(m) vec3((m)[0].x, (m)[1].y, m[2].z)
#define projMAD(m, v) (diagonal3(m) * (v) + (m)[3].xyz)
@@ -252,17 +225,16 @@ void main() {
){
// apply displacement for waving plant blocks
worldpos += calcMovePlants(playerpos + cameraPosition) * max(gl_MultiTexCoord1.y,0.5);
worldpos += calcMovePlants(playerpos + cameraPosition) / 255.0 * max(gl_MultiTexCoord1.y,0.5);
// apply displacement for waving leaf blocks specifically, overwriting the other waving mode. these wave off of the air. they wave uniformly
if(blockId == BLOCK_AIR_WAVING) worldpos = playerpos + calcMoveLeaves(playerpos + cameraPosition, 0.0040, 0.0064, 0.0043, 0.0035, 0.0037, 0.0041, vec3(1.0,0.2,1.0), vec3(0.5,0.1,0.5))*gl_MultiTexCoord1.y;
if(blockId == BLOCK_AIR_WAVING) worldpos = playerpos + calcMoveLeaves(playerpos + cameraPosition, 0.0040, 0.0064, 0.0043, 0.0035, 0.0037, 0.0041, vec3(1.0,0.2,1.0), vec3(0.5,0.1,0.5))/255.0*gl_MultiTexCoord1.y;
}
#endif
#if CURVATURE_AMOUNT != 0
float curvature = length(worldpos) / (16*8);
worldpos.y -= curvature*curvature * (float(CURVATURE_AMOUNT)/10.0f);
applyWorldCurvature(worldpos);
#endif
position = mat3(shadowModelView) * worldpos + shadowModelView[3].xyz;
+2 -2
View File
@@ -261,9 +261,9 @@ void main() {
#endif
#if CURVATURE_AMOUNT != 0
float curvature = length(worldpos) / (16*8);
worldpos.y -= curvature*curvature * (float(CURVATURE_AMOUNT)/10.0f);
applyWorldCurvature(worldpos);
#endif
position = mat3(shadowModelView) * worldpos + shadowModelView[3].xyz;
@@ -261,9 +261,9 @@ void main() {
#endif
#if CURVATURE_AMOUNT != 0
float curvature = length(worldpos) / (16*8);
worldpos.y -= curvature*curvature * (float(CURVATURE_AMOUNT)/10.0f);
applyWorldCurvature(worldpos);
#endif
position = mat3(shadowModelView) * worldpos + shadowModelView[3].xyz;