From 31578303a4eab6b6b083e57b6bf8d12ff3b3d991 Mon Sep 17 00:00:00 2001 From: x2048 Date: Thu, 31 Mar 2022 22:40:06 +0200 Subject: Tune shadow perspective distortion (#12146) * Pass perspective distortion parameters as uniforms * Set all perspective bias parameters via ShadowRenderer * Recalibrate perspective distortion and shadow range to render less shadow geometry with the same quality and observed shadow distance --- client/shaders/nodes_shader/opengl_fragment.glsl | 18 +++++++++--------- client/shaders/nodes_shader/opengl_vertex.glsl | 8 ++++---- client/shaders/object_shader/opengl_fragment.glsl | 18 +++++++++--------- client/shaders/object_shader/opengl_vertex.glsl | 8 ++++---- client/shaders/shadow_shaders/pass1_trans_vertex.glsl | 10 +++++----- client/shaders/shadow_shaders/pass1_vertex.glsl | 10 +++++----- 6 files changed, 36 insertions(+), 36 deletions(-) (limited to 'client/shaders') diff --git a/client/shaders/nodes_shader/opengl_fragment.glsl b/client/shaders/nodes_shader/opengl_fragment.glsl index adc8adccb..3dc66bdb3 100644 --- a/client/shaders/nodes_shader/opengl_fragment.glsl +++ b/client/shaders/nodes_shader/opengl_fragment.glsl @@ -47,17 +47,17 @@ const float fogShadingParameter = 1.0 / ( 1.0 - fogStart); #ifdef ENABLE_DYNAMIC_SHADOWS -const float bias0 = 0.9; -const float zPersFactor = 0.5; -const float bias1 = 1.0 - bias0 + 1e-6; +uniform float xyPerspectiveBias0; +uniform float xyPerspectiveBias1; +uniform float zPerspectiveBias; vec4 getPerspectiveFactor(in vec4 shadowPosition) { float pDistance = length(shadowPosition.xy); - float pFactor = pDistance * bias0 + bias1; + float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1; - shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPersFactor); + shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias); return shadowPosition; } @@ -172,12 +172,12 @@ float getHardShadowDepth(sampler2D shadowsampler, vec2 smTexCoord, float realDis float getBaseLength(vec2 smTexCoord) { float l = length(2.0 * smTexCoord.xy - 1.0); // length in texture coords - return bias1 / (1.0 / l - bias0); // return to undistorted coords + return xyPerspectiveBias1 / (1.0 / l - xyPerspectiveBias0); // return to undistorted coords } float getDeltaPerspectiveFactor(float l) { - return 0.1 / (bias0 * l + bias1); // original distortion factor, divided by 10 + return 0.1 / (xyPerspectiveBias0 * l + xyPerspectiveBias1); // original distortion factor, divided by 10 } float getPenumbraRadius(sampler2D shadowsampler, vec2 smTexCoord, float realDistance, float multiplier) @@ -489,8 +489,8 @@ void main(void) vec3 shadow_color = vec3(0.0, 0.0, 0.0); vec3 posLightSpace = getLightSpacePosition(); - float distance_rate = (1 - pow(clamp(2.0 * length(posLightSpace.xy - 0.5),0.0,1.0), 20.0)); - float f_adj_shadow_strength = max(adj_shadow_strength-mtsmoothstep(0.9,1.1, posLightSpace.z ),0.0); + float distance_rate = (1 - pow(clamp(2.0 * length(posLightSpace.xy - 0.5),0.0,1.0), 50.0)); + float f_adj_shadow_strength = max(adj_shadow_strength-mtsmoothstep(0.9,1.1, posLightSpace.z),0.0); if (distance_rate > 1e-7) { diff --git a/client/shaders/nodes_shader/opengl_vertex.glsl b/client/shaders/nodes_shader/opengl_vertex.glsl index 5e77ac719..935fbf043 100644 --- a/client/shaders/nodes_shader/opengl_vertex.glsl +++ b/client/shaders/nodes_shader/opengl_vertex.glsl @@ -45,8 +45,8 @@ varying float nightRatio; const vec3 artificialLight = vec3(1.04, 1.04, 1.04); const float e = 2.718281828459; const float BS = 10.0; -const float bias0 = 0.9; -const float bias1 = 1.0 - bias0; +uniform float xyPerspectiveBias0; +uniform float xyPerspectiveBias1; #ifdef ENABLE_DYNAMIC_SHADOWS // custom smoothstep implementation because it's not defined in glsl1.2 @@ -206,9 +206,9 @@ void main(void) // Distance from the vertex to the player float distanceToPlayer = length(eyeToVertex - v_LightDirection * dot(eyeToVertex, v_LightDirection)) / f_shadowfar; // perspective factor estimation according to the - float perspectiveFactor = distanceToPlayer * bias0 + bias1; + float perspectiveFactor = distanceToPlayer * xyPerspectiveBias0 + xyPerspectiveBias1; float texelSize = f_shadowfar * perspectiveFactor * perspectiveFactor / - (f_textureresolution * bias1 - perspectiveFactor * bias0); + (f_textureresolution * xyPerspectiveBias1 - perspectiveFactor * xyPerspectiveBias0); float slopeScale = clamp(pow(1.0 - cosLight*cosLight, 0.5), 0.0, 1.0); normalOffsetScale = texelSize * slopeScale; diff --git a/client/shaders/object_shader/opengl_fragment.glsl b/client/shaders/object_shader/opengl_fragment.glsl index edb9d2bb1..2b9a59cd7 100644 --- a/client/shaders/object_shader/opengl_fragment.glsl +++ b/client/shaders/object_shader/opengl_fragment.glsl @@ -43,17 +43,17 @@ const float fogShadingParameter = 1.0 / (1.0 - fogStart); #endif #ifdef ENABLE_DYNAMIC_SHADOWS -const float bias0 = 0.9; -const float zPersFactor = 0.5; -const float bias1 = 1.0 - bias0 + 1e-6; +uniform float xyPerspectiveBias0; +uniform float xyPerspectiveBias1; +uniform float zPerspectiveBias; vec4 getPerspectiveFactor(in vec4 shadowPosition) { float pDistance = length(shadowPosition.xy); - float pFactor = pDistance * bias0 + bias1; + float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1; - shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPersFactor); + shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias); return shadowPosition; } @@ -162,12 +162,12 @@ float getHardShadowDepth(sampler2D shadowsampler, vec2 smTexCoord, float realDis float getBaseLength(vec2 smTexCoord) { float l = length(2.0 * smTexCoord.xy - 1.0); // length in texture coords - return bias1 / (1.0 / l - bias0); // return to undistorted coords + return xyPerspectiveBias1 / (1.0 / l - xyPerspectiveBias0); // return to undistorted coords } float getDeltaPerspectiveFactor(float l) { - return 0.1 / (bias0 * l + bias1); // original distortion factor, divided by 10 + return 0.1 / (xyPerspectiveBias0 * l + xyPerspectiveBias1); // original distortion factor, divided by 10 } float getPenumbraRadius(sampler2D shadowsampler, vec2 smTexCoord, float realDistance, float multiplier) @@ -477,8 +477,8 @@ void main(void) vec3 shadow_color = vec3(0.0, 0.0, 0.0); vec3 posLightSpace = getLightSpacePosition(); - float distance_rate = (1 - pow(clamp(2.0 * length(posLightSpace.xy - 0.5),0.0,1.0), 20.0)); - float f_adj_shadow_strength = max(adj_shadow_strength-mtsmoothstep(0.9,1.1, posLightSpace.z ),0.0); + float distance_rate = (1 - pow(clamp(2.0 * length(posLightSpace.xy - 0.5),0.0,1.0), 50.0)); + float f_adj_shadow_strength = max(adj_shadow_strength-mtsmoothstep(0.9,1.1, posLightSpace.z),0.0); if (distance_rate > 1e-7) { diff --git a/client/shaders/object_shader/opengl_vertex.glsl b/client/shaders/object_shader/opengl_vertex.glsl index ff0067302..55861b0e9 100644 --- a/client/shaders/object_shader/opengl_vertex.glsl +++ b/client/shaders/object_shader/opengl_vertex.glsl @@ -37,8 +37,8 @@ const vec3 artificialLight = vec3(1.04, 1.04, 1.04); varying float vIDiff; const float e = 2.718281828459; const float BS = 10.0; -const float bias0 = 0.9; -const float bias1 = 1.0 - bias0; +uniform float xyPerspectiveBias0; +uniform float xyPerspectiveBias1; #ifdef ENABLE_DYNAMIC_SHADOWS // custom smoothstep implementation because it's not defined in glsl1.2 @@ -116,9 +116,9 @@ void main(void) // Distance from the vertex to the player float distanceToPlayer = length(eyeToVertex - v_LightDirection * dot(eyeToVertex, v_LightDirection)) / f_shadowfar; // perspective factor estimation according to the - float perspectiveFactor = distanceToPlayer * bias0 + bias1; + float perspectiveFactor = distanceToPlayer * xyPerspectiveBias0 + xyPerspectiveBias1; float texelSize = f_shadowfar * perspectiveFactor * perspectiveFactor / - (f_textureresolution * bias1 - perspectiveFactor * bias0); + (f_textureresolution * xyPerspectiveBias1 - perspectiveFactor * xyPerspectiveBias0); float slopeScale = clamp(pow(1.0 - cosLight*cosLight, 0.5), 0.0, 1.0); normalOffsetScale = texelSize * slopeScale; diff --git a/client/shaders/shadow_shaders/pass1_trans_vertex.glsl b/client/shaders/shadow_shaders/pass1_trans_vertex.glsl index 0a9efe450..6d2877d18 100644 --- a/client/shaders/shadow_shaders/pass1_trans_vertex.glsl +++ b/client/shaders/shadow_shaders/pass1_trans_vertex.glsl @@ -4,15 +4,15 @@ varying vec4 tPos; varying vec3 varColor; #endif -const float bias0 = 0.9; -const float zPersFactor = 0.5; -const float bias1 = 1.0 - bias0 + 1e-6; +uniform float xyPerspectiveBias0; +uniform float xyPerspectiveBias1; +uniform float zPerspectiveBias; vec4 getPerspectiveFactor(in vec4 shadowPosition) { float pDistance = length(shadowPosition.xy); - float pFactor = pDistance * bias0 + bias1; - shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPersFactor); + float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1; + shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias); return shadowPosition; } diff --git a/client/shaders/shadow_shaders/pass1_vertex.glsl b/client/shaders/shadow_shaders/pass1_vertex.glsl index feee9467f..3873ac6e6 100644 --- a/client/shaders/shadow_shaders/pass1_vertex.glsl +++ b/client/shaders/shadow_shaders/pass1_vertex.glsl @@ -1,15 +1,15 @@ uniform mat4 LightMVP; // world matrix varying vec4 tPos; -const float bias0 = 0.9; -const float zPersFactor = 0.5; -const float bias1 = 1.0 - bias0 + 1e-6; +uniform float xyPerspectiveBias0; +uniform float xyPerspectiveBias1; +uniform float zPerspectiveBias; vec4 getPerspectiveFactor(in vec4 shadowPosition) { float pDistance = length(shadowPosition.xy); - float pFactor = pDistance * bias0 + bias1; - shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPersFactor); + float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1; + shadowPosition.xyz *= vec3(vec2(1.0 / pFactor), zPerspectiveBias); return shadowPosition; } -- cgit v1.2.3 ' href='#n228'>228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
/*
Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#pragma once

#include "irr_v3d.h"
#include "map.h"
#include "hud.h"
#include "gamedef.h"
#include "serialization.h" // For SER_FMT_VER_INVALID
#include "content/mods.h"
#include "inventorymanager.h"
#include "content/subgames.h"
#include "tileanimation.h" // TileAnimationParams
#include "particles.h" // ParticleParams
#include "network/peerhandler.h"
#include "network/address.h"
#include "util/numeric.h"
#include "util/thread.h"
#include "util/basic_macros.h"
#include "util/metricsbackend.h"
#include "serverenvironment.h"
#include "clientiface.h"
#include "chatmessage.h"
#include "translation.h"
#include <string>
#include <list>
#include <map>
#include <vector>
#include <unordered_set>

class ChatEvent;
struct ChatEventChat;
struct ChatInterface;
class IWritableItemDefManager;
class NodeDefManager;
class IWritableCraftDefManager;
class BanManager;
class EventManager;
class Inventory;
class ModChannelMgr;
class RemotePlayer;
class PlayerSAO;
struct PlayerHPChangeReason;
class IRollbackManager;
struct RollbackAction;
class EmergeManager;
class ServerScripting;
class ServerEnvironment;
struct SimpleSoundSpec;
struct CloudParams;
struct SkyboxParams;
struct SunParams;
struct MoonParams;
struct StarParams;
class ServerThread;
class ServerModManager;
class ServerInventoryManager;

enum ClientDeletionReason {
	CDR_LEAVE,
	CDR_TIMEOUT,
	CDR_DENY
};

struct MediaInfo
{
	std::string path;
	std::string sha1_digest; // base64-encoded
	bool no_announce; // true: not announced in TOCLIENT_ANNOUNCE_MEDIA (at player join)

	MediaInfo(const std::string &path_="",
	          const std::string &sha1_digest_=""):
		path(path_),
		sha1_digest(sha1_digest_),
		no_announce(false)
	{
	}
};

struct ServerSoundParams
{
	enum Type {
		SSP_LOCAL,
		SSP_POSITIONAL,