/usr/src/castle-game-engine-5.2.0/x3d/x3d_environmentaleffects.inc is in castle-game-engine-src 5.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 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 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 | {
Copyright 2002-2014 Michalis Kamburelis.
This file is part of "Castle Game Engine".
"Castle Game Engine" is free software; see the file COPYING.txt,
included in this distribution, for details about the copyright.
"Castle Game Engine" 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.
----------------------------------------------------------------------------
}
{$ifdef read_interface}
{ }
TBackgroundSide = (bsBack, bsBottom, bsFront, bsLeft, bsRight, bsTop);
TAbstractBackgroundNode = class(TAbstractBindableNode)
private
procedure EventSet_BindReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
protected
procedure DirectEnumerateActive(Func: TEnumerateChildrenFunction); override;
public
procedure CreateNode; override;
function TransformationChange: TNodeTransformationChange; override;
{ Texture node for given background side.
May return @nil if none.
It is the caller's responsibility to take care of freeing the result,
but only if it's not otherwise used. In other words, use TX3DNode.FreeIfUnused
(or some routine based on it), unless you're sure that you always
make the returned node a child of another node (in this case
the returned node is always used, and remains managed by parent node). }
function Texture(const Side: TBackgroundSide): TAbstractTextureNode; virtual; abstract;
private FFdGroundAngle: TMFFloat;
public property FdGroundAngle: TMFFloat read FFdGroundAngle;
private FFdGroundColor: TMFColor;
public property FdGroundColor: TMFColor read FFdGroundColor;
private FFdSkyAngle: TMFFloat;
public property FdSkyAngle: TMFFloat read FFdSkyAngle;
private FFdSkyColor: TMFColor;
public property FdSkyColor: TMFColor read FFdSkyColor;
private FFdTransparency: TSFFloat;
public property FdTransparency: TSFFloat read FFdTransparency;
private FFdShaders: TMFNodeShaders;
public property FdShaders: TMFNodeShaders read FFdShaders;
private FFdEffects: TMFNode;
public property FdEffects: TMFNode read FFdEffects;
function TransformRotation: TMatrix4Single;
end;
TFogTypeOrNone = (ftLinear, ftExp, ftNone);
TFogType = ftLinear..ftExp;
IAbstractFogObject = interface(IX3DNode)
['{F5C4E0A9-2214-4E3F-8E90-1E0305B2EBC6}']
function GetFdcolor: TSFColor;
function GetFdfogType: TSFString;
function GetFdvisibilityRange: TSFFloat;
function GetFdvolumetric: TSFBool;
function GetFdvolumetricDirection: TSFVec3f;
function GetFdvolumetricVisibilityStart: TSFFloat;
property FdColor: TSFColor read GetFdcolor;
property FdFogType: TSFString read GetFdfogType;
property FdVisibilityRange: TSFFloat read GetFdvisibilityRange;
property FdVolumetric: TSFBool read GetFdvolumetric;
property FdVolumetricDirection: TSFVec3f read GetFdvolumetricDirection;
property FdVolumetricVisibilityStart: TSFFloat read GetFdvolumetricVisibilityStart;
function GetTransformScale: Single;
property TransformScale: Single read GetTransformScale;
function FogType: TFogType;
end;
TBackgroundNode = class(TAbstractBackgroundNode)
public
procedure CreateNode; override;
class function ClassNodeTypeName: string; override;
class function URNMatching(const URN: string): boolean; override;
function Texture(const Side: TBackgroundSide): TAbstractTextureNode; override;
private FFdBackUrl: TMFString;
public property FdBackUrl: TMFString read FFdBackUrl;
private FFdBottomUrl: TMFString;
public property FdBottomUrl: TMFString read FFdBottomUrl;
private FFdFrontUrl: TMFString;
public property FdFrontUrl: TMFString read FFdFrontUrl;
private FFdLeftUrl: TMFString;
public property FdLeftUrl: TMFString read FFdLeftUrl;
private FFdRightUrl: TMFString;
public property FdRightUrl: TMFString read FFdRightUrl;
private FFdTopUrl: TMFString;
public property FdTopUrl: TMFString read FFdTopUrl;
end;
TFogNode = class(TAbstractBindableNode, IAbstractFogObject)
private
function GetFdcolor: TSFColor;
function GetFdfogType: TSFString;
function GetFdvisibilityRange: TSFFloat;
function GetFdvolumetric: TSFBool;
function GetFdvolumetricDirection: TSFVec3f;
function GetFdvolumetricVisibilityStart: TSFFloat;
function GetTransformScale: Single;
procedure EventSet_BindReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
public
procedure CreateNode; override;
class function ClassNodeTypeName: string; override;
class function URNMatching(const URN: string): boolean; override;
function TransformationChange: TNodeTransformationChange; override;
private FFdColor: TSFColor;
public property FdColor: TSFColor read FFdColor;
private FFdFogType: TSFString;
public property FdFogType: TSFString read FFdFogType;
private FFdVisibilityRange: TSFFloat;
public property FdVisibilityRange: TSFFloat read FFdVisibilityRange;
{ Fields below are Kambi's fog extensions, see
http://castle-engine.sourceforge.net/x3d_extensions.php#ext_fog_volumetric
@groupBegin }
private FFdVolumetric: TSFBool;
public property FdVolumetric: TSFBool read FFdVolumetric;
private FFdVolumetricDirection: TSFVec3f;
public property FdVolumetricDirection: TSFVec3f read FFdVolumetricDirection;
private FFdVolumetricVisibilityStart: TSFFloat;
public property FdVolumetricVisibilityStart: TSFFloat read FFdVolumetricVisibilityStart;
private FFdAlternative: TSFNode;
public property FdAlternative: TSFNode read FFdAlternative;
{ @groupEnd }
{ Fog type. }
function FogType: TFogType;
{ Fog type, but may also return ftNone if we are @nil (checks Self <> nil)
or visibilityRange = 0. }
function FogTypeOrNone: TFogTypeOrNone;
{ Apply fog to the color of the vertex.
This can be used by software renderers (ray-tracers etc.)
to calculate pixel color following VRML/X3D specifications.
After all the lighting is summed up (see TX3DGraphTraverseState.Emission and
TLightInstance.Contribution), process color by this method to apply fog.
Does nothing if AFogType = ftNone. In this special case, it's also
allowed to call this on @nil instance. }
procedure ApplyFog(var Color: TVector3Single;
const Position, VertexPos: TVector3Single; const AFogType: TFogTypeOrNone);
end;
TFogCoordinateNode = class(TAbstractGeometricPropertyNode)
public
procedure CreateNode; override;
class function ClassNodeTypeName: string; override;
class function URNMatching(const URN: string): boolean; override;
private FFdDepth: TMFFloat;
public property FdDepth: TMFFloat read FFdDepth;
end;
TLocalFogNode = class(TAbstractChildNode, IAbstractFogObject)
private
FTransformScale: Single;
function GetFdcolor: TSFColor;
function GetFdfogType: TSFString;
function GetFdvisibilityRange: TSFFloat;
function GetFdvolumetric: TSFBool;
function GetFdvolumetricDirection: TSFVec3f;
function GetFdvolumetricVisibilityStart: TSFFloat;
function GetTransformScale: Single;
protected
procedure BeforeTraverse(StateStack: TX3DGraphTraverseStateStack); override;
public
procedure CreateNode; override;
class function ClassNodeTypeName: string; override;
class function URNMatching(const URN: string): boolean; override;
private FFdColor: TSFColor;
public property FdColor: TSFColor read FFdColor;
private FFdEnabled: TSFBool;
public property FdEnabled: TSFBool read FFdEnabled;
private FFdFogType: TSFString;
public property FdFogType: TSFString read FFdFogType;
private FFdVisibilityRange: TSFFloat;
public property FdVisibilityRange: TSFFloat read FFdVisibilityRange;
{ Fields below are Kambi's fog extensions, see
http://castle-engine.sourceforge.net/x3d_extensions.php#ext_fog_volumetric
@groupBegin }
private FFdVolumetric: TSFBool;
public property FdVolumetric: TSFBool read FFdVolumetric;
private FFdVolumetricDirection: TSFVec3f;
public property FdVolumetricDirection: TSFVec3f read FFdVolumetricDirection;
private FFdVolumetricVisibilityStart: TSFFloat;
public property FdVolumetricVisibilityStart: TSFFloat read FFdVolumetricVisibilityStart;
{ @groupEnd }
function FogType: TFogType;
end;
TTextureBackgroundNode = class(TAbstractBackgroundNode)
public
procedure CreateNode; override;
class function ClassNodeTypeName: string; override;
class function URNMatching(const URN: string): boolean; override;
function Texture(const Side: TBackgroundSide): TAbstractTextureNode; override;
private FFdBackTexture: TSFNode;
public property FdBackTexture: TSFNode read FFdBackTexture;
private FFdBottomTexture: TSFNode;
public property FdBottomTexture: TSFNode read FFdBottomTexture;
private FFdFrontTexture: TSFNode;
public property FdFrontTexture: TSFNode read FFdFrontTexture;
private FFdLeftTexture: TSFNode;
public property FdLeftTexture: TSFNode read FFdLeftTexture;
private FFdRightTexture: TSFNode;
public property FdRightTexture: TSFNode read FFdRightTexture;
private FFdTopTexture: TSFNode;
public property FdTopTexture: TSFNode read FFdTopTexture;
end;
{$endif read_interface}
{$ifdef read_implementation}
procedure TAbstractBackgroundNode.CreateNode;
begin
inherited;
FFdGroundAngle := TMFFloat.Create(Self, 'groundAngle', []);
FdGroundAngle.Angle := true;
FdGroundAngle.ChangesAlways := [chBackground];
Fields.Add(FFdGroundAngle);
{ X3D specification comment: [0,Pi/2] }
FFdGroundColor := TMFColor.Create(Self, 'groundColor', []);
FdGroundColor.ChangesAlways := [chBackground];
Fields.Add(FFdGroundColor);
{ X3D specification comment: [0,1] }
FFdSkyAngle := TMFFloat.Create(Self, 'skyAngle', []);
FdSkyAngle.Angle := true;
FdSkyAngle.ChangesAlways := [chBackground];
Fields.Add(FFdSkyAngle);
{ X3D specification comment: [0,Pi] }
FFdSkyColor := TMFColor.Create(Self, 'skyColor', Vector3Single(0, 0, 0));
FdSkyColor.ChangesAlways := [chBackground];
Fields.Add(FFdSkyColor);
{ X3D specification comment: [0,1] }
FFdTransparency := TSFFloat.Create(Self, 'transparency', 0);
FdTransparency.ChangesAlways := [chBackground];
Fields.Add(FFdTransparency);
{ X3D specification comment: [0,1] }
FFdShaders := TMFNodeShaders.Create(Self, 'shaders', [TAbstractShaderNode]);
FdShaders.ChangesAlways := [chEverything];
Fields.Add(FFdShaders);
FFdEffects := TMFNode.Create(Self, 'effects', [TEffectNode]);
FdEffects.Exposed := false;
FdEffects.ChangesAlways := [chEverything];
Fields.Add(FFdEffects);
DefaultContainerField := 'children';
Eventset_bind.OnReceive.Add(@EventSet_BindReceive);
end;
procedure TAbstractBackgroundNode.DirectEnumerateActive(
Func: TEnumerateChildrenFunction);
begin
inherited;
FFdShaders.EnumerateValid(Func);
end;
procedure TAbstractBackgroundNode.EventSet_BindReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
begin
if Scene <> nil then
begin
Scene.GetBackgroundStack.Set_Bind(Self, (Value as TSFBool).Value);
{ Background is something visible, so we must actually redisplay
for user to see the new scene. This is not done by Set_Bind method
automatically, as this is specific to Background node. }
Scene.VisibleChangeHere([vcVisibleNonGeometry]);
end;
end;
function TAbstractBackgroundNode.TransformationChange: TNodeTransformationChange;
begin
Result := ntcBackground;
end;
function TAbstractBackgroundNode.TransformRotation: TMatrix4Single;
begin
Result := Transform;
{ TODO: We should extract here only rotation from BgTransform matrix.
Below is a very hacky way of at least cancelling the translation.
This will work OK for any rigid body matrix, i.e. composed only from
rotation and translation. }
Result[3][0] := 0;
Result[3][1] := 0;
Result[3][2] := 0;
end;
procedure TBackgroundNode.CreateNode;
begin
inherited;
{ TODO: changing XxxUrl should only cause reloading of the Textures
(even better: only of the appropriate background side),
and then chBackground (to create need display list for rendering background).
Current chEverything is very unoptimal. }
FFdBackUrl := TMFString.Create(Self, 'backUrl', []);
FdBackUrl.ChangesAlways := [chEverything];
Fields.Add(FFdBackUrl);
{ X3D specification comment: [URI] }
FFdBottomUrl := TMFString.Create(Self, 'bottomUrl', []);
FdBottomUrl.ChangesAlways := [chEverything];
Fields.Add(FFdBottomUrl);
{ X3D specification comment: [URI] }
FFdFrontUrl := TMFString.Create(Self, 'frontUrl', []);
FdFrontUrl.ChangesAlways := [chEverything];
Fields.Add(FFdFrontUrl);
{ X3D specification comment: [URI] }
FFdLeftUrl := TMFString.Create(Self, 'leftUrl', []);
FdLeftUrl.ChangesAlways := [chEverything];
Fields.Add(FFdLeftUrl);
{ X3D specification comment: [URI] }
FFdRightUrl := TMFString.Create(Self, 'rightUrl', []);
FdRightUrl.ChangesAlways := [chEverything];
Fields.Add(FFdRightUrl);
{ X3D specification comment: [URI] }
FFdTopUrl := TMFString.Create(Self, 'topUrl', []);
FdTopUrl.ChangesAlways := [chEverything];
Fields.Add(FFdTopUrl);
{ X3D specification comment: [URI] }
DefaultContainerField := 'children';
end;
class function TBackgroundNode.ClassNodeTypeName: string;
begin
Result := 'Background';
end;
class function TBackgroundNode.URNMatching(const URN: string): boolean;
begin
Result := (inherited URNMatching(URN)) or
(URN = URNVRML97Nodes + ClassNodeTypeName) or
(URN = URNX3DNodes + ClassNodeTypeName);
end;
function TBackgroundNode.Texture(const Side: TBackgroundSide): TAbstractTextureNode;
var
TextureField: TMFString;
ResultImgTex: TImageTextureNode;
begin
case Side of
bsBack : TextureField := FdBackUrl;
bsBottom: TextureField := FdBottomUrl;
bsFront : TextureField := FdFrontUrl;
bsLeft : TextureField := FdLeftUrl;
bsRight : TextureField := FdRightUrl;
bsTop : TextureField := FdTopUrl;
else raise EInternalError.Create('TTextureBackgroundNode.Texture:Side?');
end;
if TextureField.Items.Count <> 0 then
begin
ResultImgTex := TImageTextureNode.Create('', BaseUrl);
ResultImgTex.FdUrl.Assign(TextureField);
Result := ResultImgTex;
end else
Result := nil;
end;
procedure TFogNode.CreateNode;
begin
inherited;
{ TODO: this is very unoptimal.
With new renderer, we possible don't have to do *anything*
when fog property changes, they will be automatically used? }
FFdColor := TSFColor.Create(Self, 'color', Vector3Single(1, 1, 1));
FdColor.ChangesAlways := [chEverything];
Fields.Add(FFdColor);
{ X3D specification comment: [0,1] }
FFdFogType := TSFString.Create(Self, 'fogType', 'LINEAR');
FdFogType.ChangesAlways := [chEverything];
Fields.Add(FFdFogType);
{ X3D specification comment: ["LINEAR"|"EXPONENTIAL"] }
FFdVisibilityRange := TSFFloat.Create(Self, 'visibilityRange', 0);
FdVisibilityRange.ChangesAlways := [chEverything];
Fields.Add(FFdVisibilityRange);
{ X3D specification comment: [0,Inf) }
FFdVolumetric := TSFBool.Create(Self, 'volumetric', false);
FdVolumetric.ChangesAlways := [chEverything];
Fields.Add(FFdVolumetric);
FFdVolumetricDirection := TSFVec3f.Create(Self, 'volumetricDirection', Vector3Single(0, -1, 0));
FdVolumetricDirection.ChangesAlways := [chEverything];
Fields.Add(FFdVolumetricDirection);
FFdVolumetricVisibilityStart := TSFFloat.Create(Self, 'volumetricVisibilityStart', 0);
FdVolumetricVisibilityStart.ChangesAlways := [chEverything];
Fields.Add(FFdVolumetricVisibilityStart);
{ Only for backward compatibility. Not used anymore. }
FFdAlternative := TSFNode.Create(Self, 'alternative', [TFogNode]);
FdAlternative.ChangesAlways := [chEverything];
Fields.Add(FFdAlternative);
DefaultContainerField := 'children';
Eventset_bind.OnReceive.Add(@EventSet_BindReceive);
end;
class function TFogNode.ClassNodeTypeName: string;
begin
Result := 'Fog';
end;
class function TFogNode.URNMatching(const URN: string): boolean;
begin
Result := (inherited URNMatching(URN)) or
(URN = URNVRML97Nodes + ClassNodeTypeName) or
(URN = URNX3DNodes + ClassNodeTypeName);
end;
procedure TFogNode.EventSet_BindReceive(
Event: TX3DEvent; Value: TX3DField; const Time: TX3DTime);
begin
if Scene <> nil then
begin
Scene.GetFogStack.Set_Bind(Self, (Value as TSFBool).Value);
{ Fog is something visible, so we must actually redisplay
for user to see the new scene. This is not done by Set_Bind method
automatically, as this is specific to Fog node. }
Scene.VisibleChangeHere([vcVisibleNonGeometry]);
end;
end;
function TFogNode.TransformationChange: TNodeTransformationChange;
begin
Result := ntcFog;
end;
function TFogNode.GetFdcolor: TSFColor;
begin
Result := FFdColor;
end;
function TFogNode.GetFdfogType: TSFString;
begin
Result := FdFogType;
end;
function TFogNode.GetFdvisibilityRange: TSFFloat;
begin
Result := FdVisibilityRange;
end;
function TFogNode.GetFdvolumetric: TSFBool;
begin
Result := FFdVolumetric;
end;
function TFogNode.GetFdvolumetricDirection: TSFVec3f;
begin
Result := FFdVolumetricDirection;
end;
function TFogNode.GetFdvolumetricVisibilityStart: TSFFloat;
begin
Result := FFdVolumetricVisibilityStart;
end;
function TFogNode.GetTransformScale: Single;
begin
Result := TransformScale;
end;
function TFogNode.FogType: TFogType;
begin
if FdFogType.Value = 'LINEAR' then
Result := ftLinear else
if FdFogType.Value = 'EXPONENTIAL' then
Result := ftExp else
begin
OnWarning(wtMajor, 'VRML/X3D', 'Unknown fog type "' + FdFogType.Value + '"');
Result := ftLinear;
end;
end;
function TFogNode.FogTypeOrNone: TFogTypeOrNone;
begin
if (Self = nil) or
(FdVisibilityRange.Value = 0.0) then
Exit(ftNone);
Result := FogType;
end;
procedure TFogNode.ApplyFog(var Color: TVector3Single;
const Position, VertexPos: TVector3Single; const AFogType: TFogTypeOrNone);
var
FogVisibilityRangeScaled: Single;
procedure ApplyDistance(const Distance: Single);
var
F: Single;
begin
case AFogType of
ftLinear: F := (FogVisibilityRangeScaled - Distance) / FogVisibilityRangeScaled;
ftExp : F := Exp(-Distance / (FogVisibilityRangeScaled - Distance));
end;
Color := Vector_Init_Lerp(F, FdColor.Value, Color);
end;
var
FogVolumetricVisibilityStart: Single;
Distance, DistanceSqr: Single;
VertProjected: TVector3Single;
begin
if AFogType <> ftNone then
begin
FogVisibilityRangeScaled := FdVisibilityRange.Value * TransformScale;
if FdVolumetric.Value then
begin
FogVolumetricVisibilityStart := FdVolumetricVisibilityStart.Value * TransformScale;
{ Calculation of Distance for volumetric fog below is analogous to
GetFogVolumetric inside ArraysGenerator. }
VertProjected := PointOnLineClosestToPoint(
ZeroVector3Single, FdVolumetricDirection.Value, VertexPos);
Distance := VectorLen(VertProjected);
if not AreParallelVectorsSameDirection(
VertProjected, FdVolumetricDirection.Value) then
Distance := -Distance;
{ Now I want
- Distance = FogVolumetricVisibilityStart -> 0
- Distance = FogVolumetricVisibilityStart + X -> X
(so that Distance = FogVolumetricVisibilityStart +
FogVisibilityRangeScaled -> FogVisibilityRangeScaled) }
Distance -= FogVolumetricVisibilityStart;
{ When Distance < 0 our intention is to have no fog.
So Distance < 0 should be equivalent to Distance = 0. }
MaxTo1st(Distance, 0);
if Distance >= FogVisibilityRangeScaled - SingleEqualityEpsilon then
Color := FdColor.Value else
ApplyDistance(Distance);
end else
begin
DistanceSqr := PointsDistanceSqr(Position, VertexPos);
if DistanceSqr >= Sqr(FogVisibilityRangeScaled - SingleEqualityEpsilon) then
Color := FdColor.Value else
ApplyDistance(Sqrt(DistanceSqr));
end;
end;
end;
procedure TFogCoordinateNode.CreateNode;
begin
inherited;
FFdDepth := TMFFloat.Create(Self, 'depth', []);
Fields.Add(FFdDepth);
{ X3D specification comment: [0,1] }
DefaultContainerField := 'fogCoord';
end;
class function TFogCoordinateNode.ClassNodeTypeName: string;
begin
Result := 'FogCoordinate';
end;
class function TFogCoordinateNode.URNMatching(const URN: string): boolean;
begin
Result := (inherited URNMatching(URN)) or
(URN = URNX3DNodes + ClassNodeTypeName);
end;
procedure TLocalFogNode.CreateNode;
begin
inherited;
FFdColor := TSFColor.Create(Self, 'color', Vector3Single(1, 1, 1));
Fields.Add(FFdColor);
{ X3D specification comment: [0,1] }
FFdEnabled := TSFBool.Create(Self, 'enabled', true);
Fields.Add(FFdEnabled);
FFdFogType := TSFString.Create(Self, 'fogType', 'LINEAR');
Fields.Add(FFdFogType);
{ X3D specification comment: ["LINEAR"|"EXPONENTIAL"] }
FFdVisibilityRange := TSFFloat.Create(Self, 'visibilityRange', 0);
Fields.Add(FFdVisibilityRange);
{ X3D specification comment: [0,-Inf) }
FFdVolumetric := TSFBool.Create(Self, 'volumetric', false);
FdVolumetric.ChangesAlways := [chEverything];
Fields.Add(FFdVolumetric);
FFdVolumetricDirection := TSFVec3f.Create(Self, 'volumetricDirection', Vector3Single(0, -1, 0));
FdVolumetricDirection.ChangesAlways := [chEverything];
Fields.Add(FFdVolumetricDirection);
FFdVolumetricVisibilityStart := TSFFloat.Create(Self, 'volumetricVisibilityStart', 0);
FdVolumetricVisibilityStart.ChangesAlways := [chEverything];
Fields.Add(FFdVolumetricVisibilityStart);
DefaultContainerField := 'children';
FTransformScale := 1;
end;
procedure TLocalFogNode.BeforeTraverse(StateStack: TX3DGraphTraverseStateStack);
begin
inherited;
FTransformScale := StateStack.Top.TransformScale;
end;
class function TLocalFogNode.ClassNodeTypeName: string;
begin
Result := 'LocalFog';
end;
class function TLocalFogNode.URNMatching(const URN: string): boolean;
begin
Result := (inherited URNMatching(URN)) or
(URN = URNX3DNodes + ClassNodeTypeName);
end;
function TLocalFogNode.GetFdcolor: TSFColor;
begin
Result := FFdColor;
end;
function TLocalFogNode.GetFdfogType: TSFString;
begin
Result := FdFogType;
end;
function TLocalFogNode.GetFdvisibilityRange: TSFFloat;
begin
Result := FdVisibilityRange;
end;
function TLocalFogNode.GetFdvolumetric: TSFBool;
begin
Result := FFdVolumetric;
end;
function TLocalFogNode.GetFdvolumetricDirection: TSFVec3f;
begin
Result := FFdVolumetricDirection;
end;
function TLocalFogNode.GetFdvolumetricVisibilityStart: TSFFloat;
begin
Result := FFdVolumetricVisibilityStart;
end;
function TLocalFogNode.GetTransformScale: Single;
begin
{ TODO: this is actually bad, each LocalFog occurrence may have
different scale, depending on parent transform node.
We should keep LocalFogScale in State, and pass it along
to RenderShape. This method should not exist. }
Result := FTransformScale;
end;
function TLocalFogNode.FogType: TFogType;
begin
if FdFogType.Value = 'LINEAR' then
Result := ftLinear else
if FdFogType.Value = 'EXPONENTIAL' then
Result := ftExp else
begin
OnWarning(wtMajor, 'VRML/X3D', 'Unknown fog type "' + FdFogType.Value + '"');
Result := ftLinear;
end;
end;
procedure TTextureBackgroundNode.CreateNode;
begin
inherited;
FFdBackTexture := TSFNode.Create(Self, 'backTexture', [TAbstractTextureNode]);
Fields.Add(FFdBackTexture);
FFdBottomTexture := TSFNode.Create(Self, 'bottomTexture', [TAbstractTextureNode]);
Fields.Add(FFdBottomTexture);
FFdFrontTexture := TSFNode.Create(Self, 'frontTexture', [TAbstractTextureNode]);
Fields.Add(FFdFrontTexture);
FFdLeftTexture := TSFNode.Create(Self, 'leftTexture', [TAbstractTextureNode]);
Fields.Add(FFdLeftTexture);
FFdRightTexture := TSFNode.Create(Self, 'rightTexture', [TAbstractTextureNode]);
Fields.Add(FFdRightTexture);
FFdTopTexture := TSFNode.Create(Self, 'topTexture', [TAbstractTextureNode]);
Fields.Add(FFdTopTexture);
DefaultContainerField := 'children';
end;
function TTextureBackgroundNode.Texture(const Side: TBackgroundSide): TAbstractTextureNode;
var
TextureField: TSFNode;
begin
case Side of
bsBack : TextureField := FdBackTexture;
bsBottom: TextureField := FdBottomTexture;
bsFront : TextureField := FdFrontTexture;
bsLeft : TextureField := FdLeftTexture;
bsRight : TextureField := FdRightTexture;
bsTop : TextureField := FdTopTexture;
else raise EInternalError.Create('TTextureBackgroundNode.Texture:Side?');
end;
if TextureField.Value is TAbstractTextureNode then
Result := TAbstractTextureNode(TextureField.Value) else
Result := nil;
end;
class function TTextureBackgroundNode.ClassNodeTypeName: string;
begin
Result := 'TextureBackground';
end;
class function TTextureBackgroundNode.URNMatching(const URN: string): boolean;
begin
Result := (inherited URNMatching(URN)) or
(URN = URNX3DNodes + ClassNodeTypeName);
end;
procedure RegisterEnvironmentalEffectsNodes;
begin
NodesManager.RegisterNodeClasses([
TBackgroundNode,
TFogNode,
TFogCoordinateNode,
TLocalFogNode,
TTextureBackgroundNode
]);
end;
{$endif read_implementation}
|