initial commit

This commit is contained in:
MihailRis
2025-05-07 20:42:50 +03:00
parent 27b194816b
commit fc46b7c434
36 changed files with 754 additions and 70 deletions
+5 -1
View File
@@ -1,9 +1,13 @@
in vec3 v_coord;
out vec4 f_color;
layout (location = 0) out vec4 f_color;
layout (location = 1) out vec4 f_position;
layout (location = 2) out vec4 f_normal;
uniform samplerCube u_cubemap;
void main(){
vec3 dir = normalize(v_coord);
f_position = vec4(100000.0);
f_normal = vec4(0.0);
f_color = texture(u_cubemap, dir);
}
+7
View File
@@ -2,8 +2,15 @@ in vec2 v_uv;
out vec4 f_color;
uniform sampler2D u_screen;
uniform sampler2D u_position;
uniform sampler2D u_normal;
uniform sampler2D u_noise;
uniform sampler2D u_shadows;
uniform ivec2 u_screenSize;
uniform float u_intensity;
uniform float u_timer;
uniform mat4 u_projection;
#include <__effect__>
+48 -1
View File
@@ -1,3 +1,50 @@
uniform vec3 samples[64];
int kernelSize = 32;
float radius = 0.25;
float bias = 0.025;
float near_plane = 0.5f;
float far_plane = 200.0f;
// required when using a perspective projection matrix
float linearize_depth(float depth) {
float z = depth * 2.0 - 1.0; // Back to NDC
return (2.0 * near_plane * far_plane) / (far_plane + near_plane - z * (far_plane - near_plane));
}
float fmod(float x, float y) {
return x - y * floor(x/y);
}
vec4 effect() {
return texture(u_screen, v_uv);
vec2 noiseScale = u_screenSize / 4.0;
vec3 position = texture(u_position, v_uv).xyz;
vec3 color = texture(u_screen, v_uv).rgb;
vec3 normal = texture(u_normal, v_uv).xyz;
vec3 randomVec = normalize(texture(u_noise, v_uv * noiseScale).xyz);
vec3 tangent = normalize(randomVec - normal * dot(randomVec, normal));
vec3 bitangent = cross(normal, tangent);
mat3 TBN = mat3(tangent, bitangent, normal);
float occlusion = 0.0;
for(int i = 0; i < kernelSize; ++i)
{
vec3 samplePos = TBN * samples[i];
samplePos = position + samplePos * radius;
vec4 offset = vec4(samplePos, 1.0);
offset = u_projection * offset;
offset.xyz /= offset.w;
offset.xyz = offset.xyz * 0.5 + 0.5;
float sampleDepth = texture(u_position, offset.xy).z;
float rangeCheck = smoothstep(0.0, 1.0, radius / abs(position.z - sampleDepth));
occlusion += (sampleDepth >= samplePos.z + bias ? 1.0 : 0.0) * rangeCheck;
}
occlusion = 1.1 - (occlusion / kernelSize);
float d = texture(u_shadows, v_uv).r;
return vec4(color * occlusion, 1.0);
}
+11
View File
@@ -0,0 +1,11 @@
uniform vec3 samples[64];
vec4 effect() {
vec2 noiseScale = u_screenSize / 4.0;
vec3 position = texture(u_position, v_uv).xyz;
vec3 color = texture(u_screen, v_uv).rgb;
vec3 normal = texture(u_normal, v_uv).xyz;
vec3 randomVec = texture(u_noise, v_uv * noiseScale).xyz;
return vec4(randomVec, 1.0);
}
+8 -1
View File
@@ -1,8 +1,13 @@
in vec4 a_color;
in vec2 a_texCoord;
in vec3 a_position;
in vec3 a_dir;
in vec3 a_normal;
in float a_fog;
out vec4 f_color;
layout (location = 0) out vec4 f_color;
layout (location = 1) out vec4 f_position;
layout (location = 2) out vec4 f_normal;
uniform sampler2D u_texture0;
uniform samplerCube u_cubemap;
@@ -20,4 +25,6 @@ void main() {
discard;
f_color = mix(a_color * tex_color, vec4(fogColor,1.0), a_fog);
f_color.a = alpha;
f_position = vec4(a_position, 1.0);
f_normal = vec4(a_normal, 1.0);
}
+6
View File
@@ -7,7 +7,9 @@ layout (location = 3) in vec4 v_light;
out vec4 a_color;
out vec2 a_texCoord;
out vec3 a_normal;
out float a_fog;
out vec3 a_position;
out vec3 a_dir;
uniform mat4 u_model;
@@ -31,6 +33,8 @@ void main() {
vec3 pos3d = modelpos.xyz - u_cameraPos;
modelpos.xyz = apply_planet_curvature(modelpos.xyz, pos3d);
a_normal = vec3(0.0, 1.0, 0.0);//v_normal.xyz * 2.0 - 1.0;
vec3 light = v_light.rgb;
float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz) /
u_torchlightDistance);
@@ -48,4 +52,6 @@ void main() {
a_fog = min(1.0, max(pow(depth * u_fogFactor, u_fogCurve),
min(pow(depth * u_weatherFogDencity, u_weatherFogCurve), u_weatherFogOpacity)));
gl_Position = u_proj * u_view * modelpos;
a_position = (u_view * modelpos).xyz;
}
+45 -3
View File
@@ -1,19 +1,53 @@
layout (location = 0) out vec4 f_color;
layout (location = 1) out vec4 f_position;
layout (location = 2) out vec4 f_normal;
in vec4 a_color;
in vec2 a_texCoord;
in float a_fog;
in vec3 a_position;
in vec3 a_dir;
out vec4 f_color;
in vec3 a_normal;
in vec3 a_realnormal;
in vec4 a_modelpos;
uniform sampler2D u_texture0;
uniform samplerCube u_cubemap;
uniform sampler2DShadow u_shadows;
// flags
uniform bool u_alphaClip;
uniform bool u_debugLights;
uniform bool u_debugNormals;
uniform bool u_enableShadows;
uniform mat4 u_shadowsMatrix;
const int BLUR_SAMPLES = 6;
void main() {
float shadow = 1.0;
if (u_enableShadows) {
vec4 mpos = u_shadowsMatrix * vec4(a_modelpos.xyz, 1.0);
vec3 projCoords = mpos.xyz / mpos.w;
projCoords = projCoords * 0.5 + 0.5;
projCoords.z -= 0.0001;
shadow = 0.0;
for (int i = 0; i < BLUR_SAMPLES; i++) {
shadow += texture(u_shadows, projCoords.xyz + vec3(
-0.002*(i%2==0?1:0)*i/BLUR_SAMPLES,
-0.002*(i%2==0?0:1)*i/BLUR_SAMPLES,
-0.0005 * i/BLUR_SAMPLES));
}
shadow /= BLUR_SAMPLES;
shadow += 0.5;
shadow = shadow * 0.7 + 0.3;
}
vec3 fogColor = texture(u_cubemap, a_dir).rgb;
vec4 tex_color = texture(u_texture0, a_texCoord);
if (u_debugLights)
tex_color.rgb = vec3(1.0);
float alpha = a_color.a * tex_color.a;
if (u_alphaClip) {
if (alpha < 0.2f)
@@ -23,6 +57,14 @@ void main() {
if (alpha < 0.002f)
discard;
}
if (u_debugLights)
tex_color.rgb = u_debugNormals ? (a_normal * 0.5 + 0.5) : vec3(1.0);
else if (u_debugNormals) {
tex_color.rgb *= a_normal * 0.5 + 0.5;
}
f_color = mix(a_color * tex_color, vec4(fogColor,1.0), a_fog);
f_color.rgb *= shadow;
f_color.a = alpha;
f_position = vec4(a_position, 1.0);
f_normal = vec4(a_normal, 1.0);
}
+15
View File
@@ -3,12 +3,17 @@
layout (location = 0) in vec3 v_position;
layout (location = 1) in vec2 v_texCoord;
layout (location = 2) in vec4 v_light;
layout (location = 3) in vec4 v_normal;
out vec4 a_color;
out vec2 a_texCoord;
out vec3 a_normal;
out float a_distance;
out float a_fog;
out vec3 a_position;
out vec4 a_modelpos;
out vec3 a_dir;
out vec3 a_realnormal;
uniform mat4 u_model;
uniform mat4 u_proj;
@@ -25,12 +30,19 @@ uniform samplerCube u_cubemap;
uniform vec3 u_torchlightColor;
uniform float u_torchlightDistance;
uniform bool u_enableShadows;
void main() {
vec4 modelpos = u_model * vec4(v_position, 1.0f);
vec3 pos3d = modelpos.xyz-u_cameraPos;
modelpos.xyz = apply_planet_curvature(modelpos.xyz, pos3d);
a_realnormal = v_normal.xyz;
mat3 normalMatrix = transpose(inverse(mat3(u_view * u_model)));
a_normal = v_normal.xyz * 2.0 - 1.0;
a_normal = normalMatrix * (false ? -a_normal : a_normal);
//a_normal = v_normal.xyz * 2.0 - 1.0;
vec3 light = v_light.rgb;
float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz) /
u_torchlightDistance);
@@ -47,4 +59,7 @@ void main() {
a_fog = min(1.0, max(pow(depth * u_fogFactor, u_fogCurve),
min(pow(depth * u_weatherFogDencity, u_weatherFogCurve), u_weatherFogOpacity)));
gl_Position = u_proj * u_view * modelpos;
a_position = (u_view * modelpos).xyz;
a_modelpos = modelpos;
}
+11
View File
@@ -0,0 +1,11 @@
in vec2 a_texCoord;
uniform sampler2D u_texture0;
void main() {
vec4 tex_color = texture(u_texture0, a_texCoord);
if (tex_color.a < 0.5) {
discard;
}
// depth will be written anyway
}
+17
View File
@@ -0,0 +1,17 @@
#include <commons>
layout (location = 0) in vec3 v_position;
layout (location = 1) in vec2 v_texCoord;
layout (location = 2) in vec4 v_light;
layout (location = 3) in vec4 v_normal;
out vec2 a_texCoord;
uniform mat4 u_model;
uniform mat4 u_proj;
uniform mat4 u_view;
void main() {
a_texCoord = v_texCoord;
gl_Position = u_proj * u_view * u_model * vec4(v_position, 1.0f);
}