refactor shaders

This commit is contained in:
MihailRis
2025-05-09 23:51:34 +03:00
parent 36e5ff2472
commit 30a0b81680
9 changed files with 128 additions and 88 deletions
+19 -29
View File
@@ -5,61 +5,51 @@ 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 vec2 a_texCoord;
out vec3 a_dir;
out vec3 a_normal;
out vec3 a_position;
out vec3 a_realnormal;
out vec4 a_color;
out vec4 a_modelpos;
uniform mat4 u_model;
uniform mat4 u_proj;
uniform mat4 u_view;
uniform vec3 u_cameraPos;
uniform float u_gamma;
uniform float u_fogFactor;
uniform float u_fogCurve;
uniform float u_weatherFogOpacity;
uniform float u_weatherFogDencity;
uniform float u_weatherFogCurve;
uniform float u_timer;
uniform samplerCube u_cubemap;
uniform samplerCube u_skybox;
uniform vec3 u_torchlightColor;
uniform float u_torchlightDistance;
uniform bool u_enableShadows;
#include <lighting>
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_modelpos = u_model * vec4(v_position, 1.0f);
vec3 pos3d = a_modelpos.xyz - u_cameraPos;
a_modelpos.xyz = apply_planet_curvature(a_modelpos.xyz, pos3d);
a_realnormal = v_normal.xyz * 2.0 - 1.0;
mat3 normalMatrix = transpose(inverse(mat3(u_view * u_model)));
a_normal = a_realnormal;
a_normal = normalMatrix * (false ? -a_normal : a_normal);
//a_normal = a_realnormal;
a_normal = calc_screen_normal(a_realnormal);
vec3 light = v_light.rgb;
float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz) /
u_torchlightDistance);
float torchlight = calc_torch_light(a_modelpos.xyz);
light += torchlight * u_torchlightColor;
a_color = vec4(pow(light, vec3(u_gamma)),1.0f);
a_texCoord = v_texCoord;
a_dir = modelpos.xyz - u_cameraPos;
vec3 skyLightColor = pick_sky_color(u_cubemap);
a_dir = a_modelpos.xyz - u_cameraPos;
vec3 skyLightColor = pick_sky_color(u_skybox);
a_color.rgb = max(a_color.rgb, skyLightColor.rgb*v_light.a);
a_distance = length(u_view * u_model * vec4(pos3d * FOG_POS_SCALE, 0.0));
float depth = (a_distance / 256.0);
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_fog = calc_fog(a_distance / 256.0);
a_position = (u_view * modelpos).xyz;
a_modelpos = modelpos;
vec4 viewmodelpos = u_view * a_modelpos;
a_position = viewmodelpos.xyz;
gl_Position = u_proj * viewmodelpos;
}