update main shader

This commit is contained in:
MihailRis 2025-02-10 22:41:30 +03:00
parent 35cf07b0f0
commit 8dfc948fe3
4 changed files with 14 additions and 5 deletions

View File

@ -1,20 +1,18 @@
in vec4 a_color;
in vec2 a_texCoord;
in float a_distance;
in float a_fog;
in vec3 a_dir;
out vec4 f_color;
uniform sampler2D u_texture0;
uniform samplerCube u_cubemap;
uniform vec3 u_fogColor;
uniform float u_fogFactor;
uniform float u_fogCurve;
uniform bool u_alphaClip;
void main() {
vec3 fogColor = texture(u_cubemap, a_dir).rgb;
vec4 tex_color = texture(u_texture0, a_texCoord);
float depth = (a_distance/256.0);
float alpha = a_color.a * tex_color.a;
if (u_alphaClip) {
if (alpha < 0.2f)
@ -24,7 +22,6 @@ void main() {
if (alpha < 0.002f)
discard;
}
f_color = mix(a_color * tex_color, vec4(fogColor,1.0),
min(1.0, pow(depth*u_fogFactor, u_fogCurve)));
f_color = mix(a_color * tex_color, vec4(fogColor,1.0), a_fog);
f_color.a = alpha;
}

View File

@ -7,6 +7,7 @@ layout (location = 2) in float v_light;
out vec4 a_color;
out vec2 a_texCoord;
out float a_distance;
out float a_fog;
out vec3 a_dir;
uniform mat4 u_model;
@ -14,6 +15,10 @@ 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 samplerCube u_cubemap;
uniform vec3 u_torchlightColor;
@ -35,6 +40,10 @@ void main() {
a_dir = modelpos.xyz - u_cameraPos;
vec3 skyLightColor = pick_sky_color(u_cubemap);
a_color.rgb = max(a_color.rgb, skyLightColor.rgb*decomp_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(depth * u_weatherFogDencity, u_weatherFogOpacity)));
gl_Position = u_proj * u_view * modelpos;
}

View File

@ -97,6 +97,7 @@ void PrecipitationRenderer::render(const Camera& camera, float delta) {
WeatherPreset weather {};
auto& fall = weather.fall;
fall.vspeed = 2.0f;
fall.texture = "misc/rain";
const int radius = 6;

View File

@ -119,6 +119,8 @@ void WorldRenderer::setupWorldShader(
shader.uniform1f("u_gamma", settings.graphics.gamma.get());
shader.uniform1f("u_fogFactor", fogFactor);
shader.uniform1f("u_fogCurve", settings.graphics.fogCurve.get());
shader.uniform1f("u_weatherFogOpacity", 0.8f);
shader.uniform1f("u_weatherFogDencity", 2.0f);
shader.uniform1f("u_dayTime", level.getWorld()->getInfo().daytime);
shader.uniform2f("u_lightDir", skybox->getLightDir());
shader.uniform3f("u_cameraPos", camera.position);