This commit is contained in:
2026-04-12 16:40:54 +07:00
parent d163609854
commit 2fe83bfb1f
31 changed files with 1153 additions and 2 deletions
+161
View File
@@ -0,0 +1,161 @@
/*
HOW TO USE:
edit functions "cust1 cust2 cust3" for custom functions 7 8 and 9.
The distortion function is in "geomfunc".
cam is player eye position, to make F5 model viewing easy,
you don't have to use this in the functions.
NOTES:
P is gl_Vertex.
p is P.xyz-eye.
dpos is velocity (jittery at the moment, not sure why).
*/
#include "uniforms.glsl"
#include "functionlibs.glsl"
const float E = 2.718281828459045;
const float PI= 3.14159265359;
vec3 dir=playerLookVector;
//CUSTOM WARP FUNCTIONS
// pos | velocity|campos |headpos |dist | variable| pos xyz |time | world pos |
vec3 cust1(vec3 p,vec3 vel,vec3 cam,vec3 eye,float d, float J, float x,float y,float z,float t,float X,float Y,float Z){
p=mat3(gbufferModelView)*p;
p.z-=d/1.1;
p=mat3(gbufferModelViewInverse)*p;
return p;
}
vec4 rot4(vec4 p,vec4 q){
return(qmul(qmul(q,p),-q));
}
vec3 torusify(vec3 p,vec3 cam,float J){
float K=J/2;
p.y=tanh((p.y-cam.y)/K)*K;
p.y-=K;
p.xy=vec2(-sin(p.x*PI/J)*p.y,cos(p.x*PI/J)*p.y)+vec2(0,K);
p.y+=K;
p.zy=vec2(sin(p.z*PI/J)*p.y,cos(p.z*PI/J)*p.y)-vec2(0,K);
return p;
}
vec3 camtor(vec3 cam,vec3 vx,float J){
return vx;
}
vec3 cust2(vec3 p,vec3 vel,vec3 cam,vec3 eye,float d, float J, float x,float y,float z,float t,float X,float Y,float Z){
p=torusify(p+cam,cam,J)-torusify(cam,cam,J);
vec3 vx=normalize(torusify(cam+vec3(0.01,0,0),cam,J)-torusify(cam,cam,J));
vec3 vy=normalize(torusify(cam+vec3(0,0.01,0),cam,J)-torusify(cam,cam,J));
vec3 vz=normalize(torusify(cam+vec3(0,0,0.01),cam,J)-torusify(cam,cam,J));
mat3 dirc=mat3(vx,vy,vz);
p=inverse(dirc)*p;
return p;
}
vec3 cust3(vec3 p,vec3 vel,vec3 cam,vec3 eye,float d, float J, float x,float y,float z,float t,float X,float Y,float Z){
float a=(sin(t/6)*d)/J;
mat3 NIL = mat3(
cos(a),0,-sin(a),
0,1,0,
sin(a),0,cos(a));
return p*NIL;
}
#define MODE 0 // [0 1 2 3 4 5 6 7 8 9]
#define J 16 // [1 2 4 8 16 32 64 128 256 512]
#define f5_distance 1 // [1 2 3 4 5 6 7 8 9 10]
//this is the function that warps space
vec4 geomfunc(vec4 P){
//basic variables
vec3 cam=eyePosition;
vec3 eye=relativeEyePosition;
vec3 p=P.xyz+eye;
vec3 dpos=(cameraPosition-previousCameraPosition)/frameTime;
float x=p.x,y=p.y,z=p.z,w=gl_Vertex.w,t=(frameTimeCounter);
float X=x+cameraPosition.x,Y=y+cameraPosition.y,Z=z+cameraPosition.z;
float d=length(p.xyz)/J;
//Solv geodesic approximation matrix that I found myself.
vec2 o =rot(vec2(J,0),frameTimeCounter);
mat3 SOLV=mat3(
pow(2,-y/J), 0, 0,
x/J, 1, -z/J,
0, 0, pow(2,y/J));
switch (MODE){
case 0:
p=inv(p,vec3(o.y,0,o.x));;
break;
case 1:
p=inv(p,vec3(o.x,o.y,0));;
break;
case 2:
p=inv(p,vec3(0,o.x,o.y));;
break;
case 3:
p+=dpos*d/J;
break;
case 4:
p=inv(p,vec3(0,J,0));;
break;
case 5:
p=inv(p,vec3(0,-J,0));;
break;
case 6:
p=p*SOLV;;
break;
//custom 1
case 7:
p=cust1(p,dpos,cam,eye,length(p.xyz),J,x,y,z,t,X,Y,Z);
break;
//custom 2
case 8:
p=cust2(p,dpos,cam,eye,length(p.xyz),J,x,y,z,t,X,Y,Z);
break;
//custom 3
case 9:
p=cust3(p,dpos,cam,eye,length(p.xyz),J,x,y,z,t,X,Y,Z);
break;
default:
p=p;
break;
}
return vec4(p-(eye*f5_distance),gl_Vertex.w);
}
/*
vec3 cust1(vec3 p,vec3 velocity,vec3 cam,vec3 eye,float d, float J, float x,float y,float z,float t,float X,float Y,float Z){
p=mat3(gbufferModelView)*p;
p.z-=d/1.1;
p=mat3(gbufferModelViewInverse)*p;
return p;
}
*/
+100
View File
@@ -0,0 +1,100 @@
//Basic functions that should exist in glsl already, why arent they built in
float pow2(float a){return pow(2,a);}
vec2 pow2(vec2 a){return vec2(pow(2,a.x),pow(2,a.y));}
vec3 pow2(vec3 a){return vec3(pow(2,a.x),pow(2,a.y),pow(2,a.z));}
vec4 pow2(vec4 a){return vec4(pow(2,a.x),pow(2,a.y),pow(2,a.z),pow(2,a.w));}
float dot2(float a){return a*a;}
float dot2(vec2 a){return dot(a,a);}
float dot2(vec3 a){return dot(a,a);}
float dot2(vec4 a){return dot(a,a);}
float mix3(float a,float b,float c,float fac){return mix(mix(a,b,fac),mix(b,c,fac),fac);}
vec2 mix3(vec2 a,vec2 b,vec2 c,float fac){return mix(mix(a,b,fac),mix(b,c,fac),fac);}
vec3 mix3(vec3 a,vec3 b,vec3 c,float fac){return mix(mix(a,b,fac),mix(b,c,fac),fac);}
vec4 mix3(vec4 a,vec4 b,vec4 c,float fac){return mix(mix(a,b,fac),mix(b,c,fac),fac);}
float mix4(float a,float b,float c,float d,float fac){return mix(mix(mix(a,b,fac),mix(b,c,fac),fac),mix(mix(b,c,fac),mix(c,d,fac),fac),fac);}
vec2 mix4(vec2 a,vec2 b,vec2 c,vec2 d,float fac){return mix(mix(mix(a,b,fac),mix(b,c,fac),fac),mix(mix(b,c,fac),mix(c,d,fac),fac),fac);}
vec3 mix4(vec3 a,vec3 b,vec3 c,vec3 d,float fac){return mix(mix(mix(a,b,fac),mix(b,c,fac),fac),mix(mix(b,c,fac),mix(c,d,fac),fac),fac);}
vec4 mix4(vec4 a,vec4 b,vec4 c,vec4 d,float fac){return mix(mix(mix(a,b,fac),mix(b,c,fac),fac),mix(mix(b,c,fac),mix(c,d,fac),fac),fac);}
mat3 rotation3d(vec3 axis, float angle) {
axis = normalize(axis);
float s = sin(angle);
float c = cos(angle);
float oc = 1.0 - c;
return mat3(
oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s,
oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s,
oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c
);
}
//Super basic 2D rotation function.
vec2 rot(vec2 p,float a){vec2 A = p.xy*mat2(cos(a),sin(a),-sin(a),cos(a));return A;}
//Inversion function.
vec3 inv(vec3 p,vec3 ofset){
p+=ofset;
p=normalize(p)*(dot2(ofset)/length(p));
p=reflect(p,normalize(ofset));
return p+ofset;
}
//Inversion function with inverted inversion position.
vec3 inv2(vec3 p,vec3 dpos){
return length(dpos)>0.0001?inv(p,normalize(dpos)*(1/length(dpos))):p;
}
//quaternion stuff
vec4 qmul(vec4 a, vec4 b) {
return vec4(
a.w * b.xyz + b.w * a.xyz + cross(a.xyz, b.xyz),
a.w * b.w - dot(a.xyz, b.xyz)
);
}
vec4 qinv(vec4 a){
return normalize(a)*(1./length(a));
}
vec3 qrot(vec3 pos, vec3 axis, float angle) {
vec4 q = vec4(sin(angle / 2.0) * axis, cos(angle / 2.0));
vec4 partial = qmul(q, vec4(pos, 0));
// Skip calculating the real part, since it's always 0
return -partial.w * q.xyz + q.w * partial.xyz + cross(q.xyz, partial.xyz);
}
vec3 getm(mat3 matr){
return vec3(matr[0][0],matr[1][1],matr[2][2]);
}
/*
y=y-(J/2);
vec4 P=vec4(sin(x*PI/J)*(J/2),cos(z*PI/J)*y,-sin(z*PI/J)*y,cos(x*PI/J));
p=P.xyz/(1+P.w);
return (P.xyz/(1+P.w))+vec3(0,J/4,0);
mat3 NIL = mat3(
cos(a)*cosh(a),0,-sin(a)*cosh(a),
0,1,0,
sin(a)*cosh(a),0,cos(a)*cosh(a));
mat3 NIL2 = mat3(
cos(a)*cosh(a),-sin(a)*cosh(a),0,
sin(a)*cosh(a),cos(a)*cosh(a),0,
0,0,1);
mat3 SOLV=mat3(
exp(-y/J), 0, 0,
x/J, 1, -z/J,
0, 0, exp(y/J));
mat3 SOLV2=mat3(
exp(z/J), 0, 0,
0, exp(-z/J),0,
-x/J, y/J, 1);
*/
+10
View File
@@ -0,0 +1,10 @@
#version 120
varying vec4 color;
void main()
{
gl_FragData[0] = color;
}
+30
View File
@@ -0,0 +1,30 @@
#version 120
#include "common.glsl"
varying vec4 color;
void main()
{
vec4 position = gl_ModelViewMatrix * gl_Vertex;
position = gbufferModelViewInverse * position;
position = geomfunc(position);
position = gbufferModelView * position;
gl_Position = gl_ProjectionMatrix * position;
gl_FogFragCoord = sqrt(position.x * position.x + position.y * position.y + position.z * position.z);
color = gl_Color;
}
+17
View File
@@ -0,0 +1,17 @@
#version 120
uniform sampler2D texture;
uniform sampler2D lightmap;
varying vec4 color;
varying vec4 texcoord;
varying vec4 lmcoord;
void main()
{
gl_FragData[0] = texture2D(texture, texcoord.st) * texture2D(lightmap, lmcoord.st) * color;
gl_FragData[0].rgb = gl_FragData[0].rgb;
}
+34
View File
@@ -0,0 +1,34 @@
#version 120
#include "common.glsl"
varying vec4 color;
varying vec4 texcoord;
varying vec4 lmcoord;
void main()
{
vec4 position = gl_ModelViewMatrix * gl_Vertex;
position = gbufferModelViewInverse * position;
position=geomfunc(position);
position = gbufferModelView * position;
gl_Position = gl_ProjectionMatrix * position;
gl_FogFragCoord = sqrt(position.x * position.x + position.y * position.y + position.z * position.z);
texcoord = gl_TextureMatrix[0] * gl_MultiTexCoord0;
color = gl_Color;
lmcoord = gl_TextureMatrix[1] * gl_MultiTexCoord1;
}
+15
View File
@@ -0,0 +1,15 @@
#version 120
uniform sampler2D texture;
uniform sampler2D lightmap;
varying vec4 color;
varying vec4 texcoord;
varying vec4 lmcoord;
void main()
{
gl_FragData[0] = texture2D(texture, texcoord.st) * texture2D(lightmap, lmcoord.st) * color;
}
+19
View File
@@ -0,0 +1,19 @@
#version 120
varying vec4 color;
varying vec4 texcoord;
varying vec4 lmcoord;
void main()
{
gl_Position = ftransform();
texcoord = gl_TextureMatrix[0] * gl_MultiTexCoord0;
color = gl_Color;
lmcoord = gl_TextureMatrix[1] * gl_MultiTexCoord1;
}
+13
View File
@@ -0,0 +1,13 @@
#version 120
//Upper & lower parts of the sky
varying vec4 color;
void main()
{
gl_FragData[0] = color;
gl_FragData[0].rgb = mix(gl_FragData[0].rgb, gl_Fog.color.rgb, clamp((gl_FogFragCoord - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0));
}
+18
View File
@@ -0,0 +1,18 @@
#version 120
//Upper & lower parts of the sky
varying vec4 color;
void main()
{
vec4 position = gl_ModelViewMatrix * gl_Vertex;
gl_Position = gl_ProjectionMatrix * position;
gl_FogFragCoord = sqrt(position.x * position.x + position.y * position.y + position.z * position.z);
color = gl_Color;
}
+14
View File
@@ -0,0 +1,14 @@
#version 120
//Sun & moon
uniform sampler2D texture;
varying vec4 color;
varying vec4 texcoord;
void main()
{
gl_FragData[0] = texture2D(texture, texcoord.st) * color;
}
+17
View File
@@ -0,0 +1,17 @@
#version 120
//Sun & moon
varying vec4 color;
varying vec4 texcoord;
void main()
{
gl_Position = ftransform();
texcoord = gl_TextureMatrix[0] * gl_MultiTexCoord0;
color = gl_Color;
}
+17
View File
@@ -0,0 +1,17 @@
#version 120
uniform sampler2D texture;
uniform sampler2D lightmap;
varying vec4 color;
varying vec4 texcoord;
varying vec4 lmcoord;
void main()
{
gl_FragData[0] = texture2D(texture, texcoord.st) * texture2D(lightmap, lmcoord.st) * color;
gl_FragData[0].rgb = mix(gl_FragData[0].rgb, gl_Fog.color.rgb, clamp((gl_FogFragCoord - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0));
}
+40
View File
@@ -0,0 +1,40 @@
#version 120
#include "common.glsl"
varying vec4 color;
varying vec4 texcoord;
varying vec4 lmcoord;
vec2 rot(float a, float A, float B){
return vec2((cos(a)*A)+(sin(a)*B),(-sin(a)*A)+(cos(a)*B));
}
void main()
{
vec4 p = gl_ModelViewMatrix * gl_Vertex;
p = gbufferModelViewInverse * p;
p = geomfunc(p);
p = gbufferModelView * p;
gl_Position = gl_ProjectionMatrix * p;
gl_FogFragCoord = 1;
texcoord = gl_TextureMatrix[0] * gl_MultiTexCoord0;
color = gl_Color;
lmcoord = gl_TextureMatrix[1] * gl_MultiTexCoord1;
}
+17
View File
@@ -0,0 +1,17 @@
#version 120
uniform sampler2D texture;
uniform sampler2D lightmap;
varying vec4 color;
varying vec4 texcoord;
varying vec4 lmcoord;
void main()
{
gl_FragData[0] = texture2D(texture, texcoord.st) * texture2D(lightmap, lmcoord.st) * color;
gl_FragData[0].rgb = mix(gl_FragData[0].rgb, gl_Fog.color.rgb, clamp((gl_FogFragCoord - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0));
}
+40
View File
@@ -0,0 +1,40 @@
#version 120
#include "common.glsl"
//#define WORLD_SPACE //Implements the deformation in World Space. Uses Screen Space if not enabled.
varying vec4 color;
varying vec4 texcoord;
varying vec4 lmcoord;
void main()
{
vec4 position = gl_ModelViewMatrix * gl_Vertex;
position = gbufferModelViewInverse * position;
position = geomfunc(position);
position = gbufferModelView * position;
gl_Position = gl_ProjectionMatrix * position;
gl_FogFragCoord = sqrt(position.x * position.x + position.y * position.y + position.z * position.z);
texcoord = gl_TextureMatrix[0] * gl_MultiTexCoord0;
color = gl_Color;
lmcoord = gl_TextureMatrix[1] * gl_MultiTexCoord1;
}
+17
View File
@@ -0,0 +1,17 @@
#version 120
uniform sampler2D texture;
uniform sampler2D lightmap;
varying vec4 color;
varying vec4 texcoord;
varying vec4 lmcoord;
void main()
{
gl_FragData[0] = texture2D(texture, texcoord.st) * texture2D(lightmap, lmcoord.st) * color;
gl_FragData[0].rgb = mix(gl_FragData[0].rgb, gl_Fog.color.rgb, clamp((gl_FogFragCoord - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0));
}
+38
View File
@@ -0,0 +1,38 @@
#version 120
#include "common.glsl"
//#define WORLD_SPACE //Implements the deformation in World Space. Uses Screen Space if not enabled.
varying vec4 color;
varying vec4 texcoord;
varying vec4 lmcoord;
void main()
{
vec4 position = gl_ModelViewMatrix * gl_Vertex;
position = gbufferModelViewInverse * position;
position = geomfunc(position);
position = gbufferModelView * position;
gl_Position = gl_ProjectionMatrix * position;
gl_FogFragCoord = sqrt(position.x * position.x + position.y * position.y + position.z * position.z);
texcoord = gl_TextureMatrix[0] * gl_MultiTexCoord0;
color = gl_Color;
lmcoord = gl_TextureMatrix[1] * gl_MultiTexCoord1;
}
+15
View File
@@ -0,0 +1,15 @@
#version 120
uniform sampler2D texture;
varying vec4 color;
varying vec4 texcoord;
void main()
{
gl_FragData[0] = texture2D(texture, texcoord.st) * color;
gl_FragData[0].rgb = mix(gl_FragData[0].rgb, gl_Fog.color.rgb, clamp((gl_FogFragCoord - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0));
}
+35
View File
@@ -0,0 +1,35 @@
#version 120
#include "common.glsl"
//#define WORLD_SPACE //Implements the deformation in World Space. Uses Screen Space if not enabled.
varying vec4 color;
varying vec4 texcoord;
varying vec4 lmcoord;
void main()
{
vec4 position = gl_ModelViewMatrix * gl_Vertex;
position = gbufferModelViewInverse * position;
position = geomfunc(position);
position = gbufferModelView * position;
gl_Position = gl_ProjectionMatrix * position;
gl_FogFragCoord = sqrt(position.x * position.x + position.y * position.y + position.z * position.z);
texcoord = gl_TextureMatrix[0] * gl_MultiTexCoord0;
color = gl_Color;
}
+6
View File
@@ -0,0 +1,6 @@
option.J=Scale
option.J.comment=Scale of the world.
option.MODE=Distortion Mode
option.MODE.comment 0: Rotation zx\n1: Rotation xy\n2: Rotation yz\n3: Relativity (Jittery)\n4: Uptown\n5: Downtown\n6: Solv Geodesics\n7: Custom 1\n8: Custom 2\n9: Custom 3
option.f5_distance F5 Distance
option.f5_distance.comment Camera distance when you press F5
+12
View File
@@ -0,0 +1,12 @@
#Properties:
frustum.culling=false
sliders J
#Custom Uniforms
variable.float.cameraSmoothX = smooth(((cameraPositionInt.x+cameraPositionFract.x)-(previousCameraPositionInt.x+previousCameraPositionFract.x))/frameTime, 1, 1)
variable.float.cameraSmoothY = smooth(((cameraPositionInt.y+cameraPositionFract.y)-(previousCameraPositionInt.y+previousCameraPositionFract.y))/frameTime, 1, 1)
variable.float.cameraSmoothZ = smooth(((cameraPositionInt.z+cameraPositionFract.z)-(previousCameraPositionInt.z+previousCameraPositionFract.z))/frameTime, 1, 1)
uniform.vec3.cameraSmooth = vec3(cameraSmoothX, cameraSmoothY,cameraSmoothZ)
+39
View File
@@ -0,0 +1,39 @@
uniform mat4 gbufferModelView;
uniform mat4 gbufferModelViewInverse;
uniform mat4 gbufferPreviousModelView;
uniform mat4 gbufferPreviousProjection;
uniform mat4 gbufferProjection;
uniform mat4 gbufferProjectionInverse;
uniform vec3 cameraPosition;
uniform vec3 cameraPositionFract;
uniform vec3 cameraPositionInt;
uniform vec3 cameraOffset;
uniform vec3 playerLookVector;
uniform vec3 upPosition;
uniform vec3 previousCameraPosition;
uniform vec3 previousCameraPositionFract;
uniform vec3 previousCameraPositionInt;
uniform vec3 relativeEyePosition;
uniform float eyeAltitude;
uniform vec3 chunkOffset;
uniform float frameTime;
uniform float frameTimeCounter;
uniform int frameCounter;
uniform float viewHeight;
uniform float viewWidth;
uniform vec3 eyePosition;
uniform vec3 cameraSmooth;