| 1 | type
|
|---|
| 2 | { TBGRADirectionalLight3D }
|
|---|
| 3 |
|
|---|
| 4 | TBGRADirectionalLight3D = class(TBGRALight3D,IBGRADirectionalLight3D)
|
|---|
| 5 | protected
|
|---|
| 6 | FDirection, FBetweenDirectionAndObserver: TPoint3D_128;
|
|---|
| 7 | public
|
|---|
| 8 | constructor Create(ADirection: TPoint3D);
|
|---|
| 9 | function GetDirection: TPoint3D; override;
|
|---|
| 10 | procedure SetDirection(const AValue: TPoint3D);
|
|---|
| 11 |
|
|---|
| 12 | procedure ComputeDiffuseAndSpecularColor(Context: PSceneLightingContext); override;
|
|---|
| 13 | procedure ComputeDiffuseColor(Context: PSceneLightingContext); override;
|
|---|
| 14 | procedure ComputeDiffuseLightness(Context: PSceneLightingContext); override;
|
|---|
| 15 | function IsDirectional: boolean; override;
|
|---|
| 16 | end;
|
|---|
| 17 |
|
|---|
| 18 | { TBGRAPointLight3D }
|
|---|
| 19 |
|
|---|
| 20 | TBGRAPointLight3D = class(TBGRALight3D,IBGRAPointLight3D)
|
|---|
| 21 | protected
|
|---|
| 22 | FVertex: IBGRAVertex3D;
|
|---|
| 23 | FIntensity: single;
|
|---|
| 24 | public
|
|---|
| 25 | constructor Create(AVertex: IBGRAVertex3D; AIntensity: single);
|
|---|
| 26 | function GetIntensity: single; override;
|
|---|
| 27 | procedure SetIntensity(const AValue: single);
|
|---|
| 28 |
|
|---|
| 29 | function GetVertex: IBGRAVertex3D;
|
|---|
| 30 | procedure SetVertex(const AValue: IBGRAVertex3D);
|
|---|
| 31 | function GetPosition: TPoint3D; override;
|
|---|
| 32 |
|
|---|
| 33 | procedure ComputeDiffuseAndSpecularColor(Context: PSceneLightingContext); override;
|
|---|
| 34 | procedure ComputeDiffuseLightness(Context: PSceneLightingContext); override;
|
|---|
| 35 | procedure ComputeDiffuseColor(Context: PSceneLightingContext); override;
|
|---|
| 36 | function IsDirectional: boolean; override;
|
|---|
| 37 | end;
|
|---|
| 38 |
|
|---|
| 39 | { TBGRAPointLight3D }
|
|---|
| 40 |
|
|---|
| 41 | constructor TBGRAPointLight3D.Create(AVertex: IBGRAVertex3D; AIntensity: single);
|
|---|
| 42 | begin
|
|---|
| 43 | inherited Create;
|
|---|
| 44 | FVertex:= AVertex;
|
|---|
| 45 | FIntensity := AIntensity;
|
|---|
| 46 | end;
|
|---|
| 47 |
|
|---|
| 48 | function TBGRAPointLight3D.GetIntensity: single;
|
|---|
| 49 | begin
|
|---|
| 50 | result := FIntensity;
|
|---|
| 51 | end;
|
|---|
| 52 |
|
|---|
| 53 | procedure TBGRAPointLight3D.SetIntensity(const AValue: single);
|
|---|
| 54 | begin
|
|---|
| 55 | FIntensity:= AValue;
|
|---|
| 56 | end;
|
|---|
| 57 |
|
|---|
| 58 | function TBGRAPointLight3D.GetVertex: IBGRAVertex3D;
|
|---|
| 59 | begin
|
|---|
| 60 | result := FVertex;
|
|---|
| 61 | end;
|
|---|
| 62 |
|
|---|
| 63 | procedure TBGRAPointLight3D.SetVertex(const AValue: IBGRAVertex3D);
|
|---|
| 64 | begin
|
|---|
| 65 | FVertex := AValue;
|
|---|
| 66 | end;
|
|---|
| 67 |
|
|---|
| 68 | function TBGRAPointLight3D.GetPosition: TPoint3D;
|
|---|
| 69 | begin
|
|---|
| 70 | Result:= FVertex.GetViewCoord;
|
|---|
| 71 | end;
|
|---|
| 72 |
|
|---|
| 73 | procedure TBGRAPointLight3D.ComputeDiffuseAndSpecularColor(Context: PSceneLightingContext);
|
|---|
| 74 | {$DEFINE PARAM_POINTLIGHT}
|
|---|
| 75 | {$i phonglight.inc}
|
|---|
| 76 |
|
|---|
| 77 | procedure TBGRAPointLight3D.ComputeDiffuseLightness(Context: PSceneLightingContext);
|
|---|
| 78 | const maxValue = 100*32768;
|
|---|
| 79 | var
|
|---|
| 80 | vect: TPoint3D_128;
|
|---|
| 81 | dist2,intensity: single;
|
|---|
| 82 | begin
|
|---|
| 83 | vect := FVertex.ViewCoord_128 - Context^.basic.Position;
|
|---|
| 84 | dist2 := DotProduct3D_128(vect,vect);
|
|---|
| 85 | if dist2 = 0 then
|
|---|
| 86 | TBGRAMaterial3D(Context^.material).ComputeDiffuseLightness(Context,maxValue,FLightness)
|
|---|
| 87 | else
|
|---|
| 88 | begin
|
|---|
| 89 | intensity := DotProduct3D_128(vect, Context^.basic.Normal)/(dist2*sqrt(dist2))*FIntensity;
|
|---|
| 90 | if Context^.LightThrough and (intensity < 0) then intensity := -intensity*Context^.LightThroughFactor;
|
|---|
| 91 | if intensity > 100 then intensity := 100;
|
|---|
| 92 | if intensity < FMinIntensity then intensity := FMinIntensity;
|
|---|
| 93 | TBGRAMaterial3D(Context^.material).ComputeDiffuseLightness(Context,round(intensity*32768),FLightness);
|
|---|
| 94 | end;
|
|---|
| 95 | end;
|
|---|
| 96 |
|
|---|
| 97 | procedure TBGRAPointLight3D.ComputeDiffuseColor(Context: PSceneLightingContext);
|
|---|
| 98 | var
|
|---|
| 99 | vect: TPoint3D_128;
|
|---|
| 100 | intensity,dist2: single;
|
|---|
| 101 | begin
|
|---|
| 102 | vect := FVertex.ViewCoord_128 - Context^.basic.Position;
|
|---|
| 103 | dist2 := DotProduct3D_128(vect,vect);
|
|---|
| 104 | if dist2 = 0 then
|
|---|
| 105 | intensity := 100
|
|---|
| 106 | else
|
|---|
| 107 | begin
|
|---|
| 108 | intensity := DotProduct3D_128(vect, Context^.basic.Normal)/(dist2*sqrt(dist2))*FIntensity;
|
|---|
| 109 | if Context^.LightThrough and (intensity < 0) then intensity := -intensity*Context^.LightThroughFactor;
|
|---|
| 110 | if intensity > 100 then intensity := 100;
|
|---|
| 111 | if intensity < FMinIntensity then intensity := FMinIntensity;
|
|---|
| 112 | end;
|
|---|
| 113 |
|
|---|
| 114 | TBGRAMaterial3D(Context^.material).ComputeDiffuseColor(Context,intensity, FColorInt);
|
|---|
| 115 | end;
|
|---|
| 116 |
|
|---|
| 117 | function TBGRAPointLight3D.IsDirectional: boolean;
|
|---|
| 118 | begin
|
|---|
| 119 | result := false;
|
|---|
| 120 | end;
|
|---|
| 121 |
|
|---|
| 122 | { TBGRADirectionalLight3D }
|
|---|
| 123 |
|
|---|
| 124 | constructor TBGRADirectionalLight3D.Create(ADirection: TPoint3D);
|
|---|
| 125 | begin
|
|---|
| 126 | inherited Create;
|
|---|
| 127 | SetDirection(ADirection);
|
|---|
| 128 | end;
|
|---|
| 129 |
|
|---|
| 130 | function TBGRADirectionalLight3D.GetDirection: TPoint3D;
|
|---|
| 131 | begin
|
|---|
| 132 | result := Point3D(-FDirection.x,-FDirection.y,-FDirection.z);
|
|---|
| 133 | end;
|
|---|
| 134 |
|
|---|
| 135 | procedure TBGRADirectionalLight3D.SetDirection(const AValue: TPoint3D);
|
|---|
| 136 | begin
|
|---|
| 137 | FDirection := -Point3D_128(AValue.x,AValue.y,AValue.z);
|
|---|
| 138 | Normalize3D_128(FDirection);
|
|---|
| 139 | FBetweenDirectionAndObserver := FDirection + FViewVector;
|
|---|
| 140 | Normalize3D_128(FBetweenDirectionAndObserver);
|
|---|
| 141 | end;
|
|---|
| 142 |
|
|---|
| 143 | procedure TBGRADirectionalLight3D.ComputeDiffuseAndSpecularColor(Context: PSceneLightingContext);
|
|---|
| 144 | {$i phonglight.inc}
|
|---|
| 145 |
|
|---|
| 146 | procedure TBGRADirectionalLight3D.ComputeDiffuseColor(Context: PSceneLightingContext);
|
|---|
| 147 | var
|
|---|
| 148 | intensity: single;
|
|---|
| 149 | begin
|
|---|
| 150 | intensity:= DotProduct3D_128(Context^.basic.Normal, FDirection);
|
|---|
| 151 | if Context^.LightThrough and (intensity < 0) then intensity := -intensity*Context^.LightThroughFactor;
|
|---|
| 152 | if intensity < FMinIntensity then intensity := FMinIntensity;
|
|---|
| 153 |
|
|---|
| 154 | TBGRAMaterial3D(Context^.material).ComputeDiffuseColor(Context,intensity,FColorInt);
|
|---|
| 155 | end;
|
|---|
| 156 |
|
|---|
| 157 | procedure TBGRADirectionalLight3D.ComputeDiffuseLightness(
|
|---|
| 158 | Context: PSceneLightingContext);
|
|---|
| 159 | var
|
|---|
| 160 | intensity: single;
|
|---|
| 161 | begin
|
|---|
| 162 | intensity:= DotProduct3D_128(Context^.basic.Normal, FDirection);
|
|---|
| 163 | if Context^.LightThrough and (intensity < 0) then intensity := -intensity*Context^.LightThroughFactor;
|
|---|
| 164 | if intensity < FMinIntensity then intensity := FMinIntensity;
|
|---|
| 165 |
|
|---|
| 166 | TBGRAMaterial3D(Context^.material).ComputeDiffuseLightness(Context,round(intensity*32768),FLightness);
|
|---|
| 167 | end;
|
|---|
| 168 |
|
|---|
| 169 | function TBGRADirectionalLight3D.IsDirectional: boolean;
|
|---|
| 170 | begin
|
|---|
| 171 | result := true;
|
|---|
| 172 | end;
|
|---|
| 173 |
|
|---|