Changeset 472 for GraphicTest/Packages/bgrabitmap/lightingclasses3d.inc
- Timestamp:
- Apr 9, 2015, 9:58:36 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/Packages/bgrabitmap/lightingclasses3d.inc
r452 r472 5 5 TBGRAMaterial3D = class(TInterfacedObject, IBGRAMaterial3D) 6 6 private 7 FDiffuseColorInt: TColorInt65536; 7 FName: string; 8 FTexture: IBGRAScanner; 9 FAutoSimpleColor,FAutoAmbiantColor,FAutoDiffuseColor,FAutoSpecularColor: boolean; 10 FSimpleColorInt, FAmbiantColorInt, FDiffuseColorInt: TColorInt65536; 8 11 FDiffuseLightness: integer; 12 FTextureZoom: TPointF; 13 9 14 FSpecularColorInt: TColorInt65536; 10 FAutoDiffuseColor,FAutoSpecularColor: boolean;11 15 FSpecularIndex: integer; 12 16 FSpecularOn: boolean; 17 13 18 FSaturationLowF: single; 14 19 FSaturationHighF: single; … … 21 26 22 27 procedure UpdateSpecular; 28 procedure UpdateSimpleColor; 23 29 procedure ComputePowerTable; 24 30 public … … 26 32 destructor Destroy; override; 27 33 34 function GetAutoAmbiantColor: boolean; 28 35 function GetAutoDiffuseColor: boolean; 29 36 function GetAutoSpecularColor: boolean; 37 function GetAutoSimpleColor: boolean; 38 function GetAmbiantAlpha: byte; 39 function GetAmbiantColor: TBGRAPixel; 40 function GetAmbiantColorF: TColorF; 41 function GetAmbiantColorInt: TColorInt65536; 42 function GetDiffuseAlpha: byte; 30 43 function GetDiffuseColor: TBGRAPixel; 31 44 function GetDiffuseColorF: TColorF; … … 38 51 function GetSaturationHigh: single; 39 52 function GetSaturationLow: single; 53 function GetSimpleAlpha: byte; 54 function GetSimpleColor: TBGRAPixel; 55 function GetSimpleColorF: TColorF; 56 function GetSimpleColorInt: TColorInt65536; 57 function GetTexture: IBGRAScanner; 58 function GetTextureZoom: TPointF; 59 procedure SetAutoAmbiantColor(const AValue: boolean); 40 60 procedure SetAutoDiffuseColor(const AValue: boolean); 41 61 procedure SetAutoSpecularColor(const AValue: boolean); 62 procedure SetAmbiantAlpha(AValue: byte); 63 procedure SetAmbiantColor(const AValue: TBGRAPixel); 64 procedure SetAmbiantColorF(const AValue: TColorF); 65 procedure SetAmbiantColorInt(const AValue: TColorInt65536); 66 procedure SetDiffuseAlpha(AValue: byte); 42 67 procedure SetDiffuseColor(const AValue: TBGRAPixel); 43 68 procedure SetDiffuseColorF(const AValue: TColorF); … … 50 75 procedure SetSaturationHigh(const AValue: single); 51 76 procedure SetSaturationLow(const AValue: single); 77 procedure SetSimpleAlpha(AValue: byte); 78 procedure SetSimpleColor(AValue: TBGRAPixel); 79 procedure SetSimpleColorF(AValue: TColorF); 80 procedure SetSimpleColorInt(AValue: TColorInt65536); 81 procedure SetTexture(AValue: IBGRAScanner); 82 procedure SetTextureZoom(AValue: TPointF); 83 function GetName: string; 84 procedure SetName(const AValue: string); 52 85 53 86 function GetSpecularOn: boolean; … … 63 96 procedure TBGRAMaterial3D.UpdateSpecular; 64 97 begin 98 FAutoSpecularColor := (FSpecularColorInt.r = 65536) and (FSpecularColorInt.g = 65536) and (FSpecularColorInt.b = 65536) and (FSpecularColorInt.a = 65536); 65 99 FSpecularOn := (FSpecularIndex > 0) and ((FSpecularColorInt.r <> 0) or (FSpecularColorInt.g <> 0) or (FSpecularColorInt.b <> 0) or 66 100 FAutoSpecularColor); 101 end; 102 103 procedure TBGRAMaterial3D.UpdateSimpleColor; 104 begin 105 FSimpleColorInt := (FAmbiantColorInt+FDiffuseColorInt)*32768; 106 FAutoSimpleColor := (FSimpleColorInt.r = 65536) and (FSimpleColorInt.g = 65536) and (FSimpleColorInt.b = 65536) and (FSimpleColorInt.a = 65536); 67 107 end; 68 108 … … 91 131 constructor TBGRAMaterial3D.Create; 92 132 begin 133 SetAmbiantColorInt(ColorInt65536(65536,65536,65536)); 93 134 SetDiffuseColorInt(ColorInt65536(65536,65536,65536)); 94 FAutoDiffuseColor:= True;95 FSpecularColorInt := ColorInt65536(0,0,0);96 FAutoSpecularColor:= True;97 135 FSpecularIndex := 10; 98 FSpecularOn := false;136 SetSpecularColorInt(ColorInt65536(0,0,0)); 99 137 FLightThroughFactor:= 0; 100 138 SetSaturationLow(2); 101 139 SetSaturationHigh(3); 102 140 141 FTexture := nil; 142 FTextureZoom := PointF(1,1); 143 103 144 FPowerTableSize := 128; 104 145 FPowerTableSizeF := FPowerTableSize; … … 111 152 end; 112 153 154 function TBGRAMaterial3D.GetAutoAmbiantColor: boolean; 155 begin 156 result := FAutoAmbiantColor; 157 end; 158 159 procedure TBGRAMaterial3D.SetDiffuseAlpha(AValue: byte); 160 begin 161 if AValue = 0 then 162 FDiffuseColorInt.a := 0 163 else 164 FDiffuseColorInt.a := AValue*257+1; 165 UpdateSimpleColor; 166 end; 167 113 168 function TBGRAMaterial3D.GetAutoDiffuseColor: boolean; 114 169 begin … … 121 176 end; 122 177 178 function TBGRAMaterial3D.GetAutoSimpleColor: boolean; 179 begin 180 result := FAutoSimpleColor; 181 end; 182 183 function TBGRAMaterial3D.GetAmbiantAlpha: byte; 184 var v: integer; 185 begin 186 if FAmbiantColorInt.a < 128 then 187 result := 0 188 else 189 begin 190 v := (FAmbiantColorInt.a-128) shr 8; 191 if v > 255 then v := 255; 192 result := v; 193 end; 194 end; 195 196 function TBGRAMaterial3D.GetAmbiantColor: TBGRAPixel; 197 begin 198 result := ColorIntToBGRA(FAmbiantColorInt); 199 end; 200 201 function TBGRAMaterial3D.GetAmbiantColorF: TColorF; 202 begin 203 result := ColorInt65536ToColorF(FAmbiantColorInt); 204 end; 205 206 function TBGRAMaterial3D.GetAmbiantColorInt: TColorInt65536; 207 begin 208 result := FAmbiantColorInt; 209 end; 210 211 function TBGRAMaterial3D.GetDiffuseAlpha: byte; 212 var v: integer; 213 begin 214 if FDiffuseColorInt.a < 128 then 215 result := 0 216 else 217 begin 218 v := (FDiffuseColorInt.a-128) shr 8; 219 if v > 255 then v := 255; 220 result := v; 221 end; 222 end; 223 123 224 function TBGRAMaterial3D.GetDiffuseColor: TBGRAPixel; 124 225 begin … … 171 272 end; 172 273 274 function TBGRAMaterial3D.GetSimpleAlpha: byte; 275 begin 276 result := (GetAmbiantAlpha + GetDiffuseAlpha) shr 1; 277 end; 278 279 function TBGRAMaterial3D.GetSimpleColor: TBGRAPixel; 280 begin 281 result := ColorIntToBGRA(GetSimpleColorInt); 282 end; 283 284 function TBGRAMaterial3D.GetSimpleColorF: TColorF; 285 begin 286 result := ColorInt65536ToColorF(GetSimpleColorInt); 287 end; 288 289 function TBGRAMaterial3D.GetSimpleColorInt: TColorInt65536; 290 begin 291 result := (GetAmbiantColorInt + GetDiffuseColorInt)*32768; 292 end; 293 294 function TBGRAMaterial3D.GetTexture: IBGRAScanner; 295 begin 296 result := FTexture; 297 end; 298 299 function TBGRAMaterial3D.GetTextureZoom: TPointF; 300 begin 301 result := FTextureZoom; 302 end; 303 304 procedure TBGRAMaterial3D.SetAutoAmbiantColor(const AValue: boolean); 305 begin 306 If AValue then 307 SetAmbiantColorInt(ColorInt65536(65536,65536,65536)); 308 end; 309 173 310 procedure TBGRAMaterial3D.SetAutoDiffuseColor(const AValue: boolean); 174 311 begin 175 FAutoDiffuseColor:= AValue; 312 If AValue then 313 SetDiffuseColorInt(ColorInt65536(65536,65536,65536)); 176 314 end; 177 315 178 316 procedure TBGRAMaterial3D.SetAutoSpecularColor(const AValue: boolean); 179 317 begin 180 FAutoSpecularColor:= AValue; 181 UpdateSpecular; 318 If AValue then 319 SetSpecularColorInt(ColorInt65536(65536,65536,65536)); 320 end; 321 322 procedure TBGRAMaterial3D.SetAmbiantAlpha(AValue: byte); 323 begin 324 if AValue = 0 then 325 FAmbiantColorInt.a := 0 326 else 327 FAmbiantColorInt.a := AValue*257+1; 328 UpdateSimpleColor; 329 end; 330 331 procedure TBGRAMaterial3D.SetAmbiantColor(const AValue: TBGRAPixel); 332 begin 333 FAmbiantColorInt := BGRAToColorInt(AValue); 334 FAutoAmbiantColor := (FAmbiantColorInt.r = 65536) and (FAmbiantColorInt.g = 65536) and (FAmbiantColorInt.b = 65536) and (FAmbiantColorInt.a = 65536); 335 UpdateSimpleColor; 336 end; 337 338 procedure TBGRAMaterial3D.SetAmbiantColorF(const AValue: TColorF); 339 begin 340 FAmbiantColorInt := ColorFToColorInt65536(AValue); 341 FAutoAmbiantColor := (FAmbiantColorInt.r = 65536) and (FAmbiantColorInt.g = 65536) and (FAmbiantColorInt.b = 65536) and (FAmbiantColorInt.a = 65536); 342 UpdateSimpleColor; 343 end; 344 345 procedure TBGRAMaterial3D.SetAmbiantColorInt(const AValue: TColorInt65536); 346 begin 347 FAmbiantColorInt := AValue; 348 FAutoAmbiantColor := (FAmbiantColorInt.r = 65536) and (FAmbiantColorInt.g = 65536) and (FAmbiantColorInt.b = 65536) and (FAmbiantColorInt.a = 65536); 349 UpdateSimpleColor; 182 350 end; 183 351 … … 186 354 FDiffuseColorInt := BGRAToColorInt(AValue); 187 355 FDiffuseLightness := (FDiffuseColorInt.r + FDiffuseColorInt.g + FDiffuseColorInt.b) div 6; 356 FAutoDiffuseColor:= (FDiffuseColorInt.r = 65536) and (FDiffuseColorInt.g = 65536) and (FDiffuseColorInt.b = 65536); 357 UpdateSimpleColor; 188 358 end; 189 359 … … 192 362 FDiffuseColorInt := ColorFToColorInt65536(AValue); 193 363 FDiffuseLightness := (FDiffuseColorInt.r + FDiffuseColorInt.g + FDiffuseColorInt.b) div 6; 364 FAutoDiffuseColor:= (FDiffuseColorInt.r = 65536) and (FDiffuseColorInt.g = 65536) and (FDiffuseColorInt.b = 65536); 365 UpdateSimpleColor; 194 366 end; 195 367 … … 198 370 FDiffuseColorInt := AValue; 199 371 FDiffuseLightness := (FDiffuseColorInt.r + FDiffuseColorInt.g + FDiffuseColorInt.b) div 6; 372 FAutoDiffuseColor:= (FDiffuseColorInt.r = 65536) and (FDiffuseColorInt.g = 65536) and (FDiffuseColorInt.b = 65536); 373 UpdateSimpleColor; 200 374 end; 201 375 … … 238 412 begin 239 413 FSaturationLowF:= AValue; 414 end; 415 416 procedure TBGRAMaterial3D.SetSimpleAlpha(AValue: byte); 417 begin 418 SetAmbiantAlpha(AValue); 419 SetDiffuseAlpha(AValue); 420 end; 421 422 procedure TBGRAMaterial3D.SetSimpleColor(AValue: TBGRAPixel); 423 begin 424 SetAmbiantColor(AValue); 425 SetDiffuseColor(AValue); 426 end; 427 428 procedure TBGRAMaterial3D.SetSimpleColorF(AValue: TColorF); 429 begin 430 SetAmbiantColorF(AValue); 431 SetDiffuseColorF(AValue); 432 end; 433 434 procedure TBGRAMaterial3D.SetSimpleColorInt(AValue: TColorInt65536); 435 begin 436 SetAmbiantColorInt(AValue); 437 SetDiffuseColorInt(AValue); 438 end; 439 440 procedure TBGRAMaterial3D.SetTexture(AValue: IBGRAScanner); 441 begin 442 FTexture := AValue; 443 end; 444 445 procedure TBGRAMaterial3D.SetTextureZoom(AValue: TPointF); 446 begin 447 FTextureZoom := AValue; 448 end; 449 450 function TBGRAMaterial3D.GetName: string; 451 begin 452 result := FName; 453 end; 454 455 procedure TBGRAMaterial3D.SetName(const AValue: string); 456 begin 457 FName := AValue; 240 458 end; 241 459 … … 283 501 end 284 502 else 285 NH *=FPowerTableSize;503 PowerTablePos := NH*FPowerTableSize; 286 504 {$ELSE} 287 505 PowerTablePos := NH; … … 298 516 Context^.diffuseColor += ALightColor*round(DiffuseIntensity*65536) 299 517 else 300 Context^.diffuseColor += FDiffuseColorInt*round(DiffuseIntensity*65536);518 Context^.diffuseColor += ALightColor*FDiffuseColorInt*round(DiffuseIntensity*65536); 301 519 302 520 if FAutoSpecularColor then 303 521 Context^.specularColor += ALightColor*round(SpecularIntensity* NnH*65536) 304 522 else 305 Context^.specularColor += FSpecularColorInt*round(SpecularIntensity* NnH*65536);523 Context^.specularColor += ALightColor*FSpecularColorInt*round(SpecularIntensity* NnH*65536); 306 524 end; 307 525 … … 312 530 Context^.diffuseColor += ALightColor*round(DiffuseIntensity*65536) 313 531 else 314 Context^.diffuseColor += FDiffuseColorInt*round(DiffuseIntensity*65536);532 Context^.diffuseColor += ALightColor*FDiffuseColorInt*round(DiffuseIntensity*65536); 315 533 end; 316 534 … … 327 545 begin 328 546 if FDiffuseLightness <> 32768 then 329 Context^.lightness += CombineLightness(DiffuseLightnessTerm32768, FDiffuseLightness)547 Context^.lightness += CombineLightness(DiffuseLightnessTerm32768,CombineLightness(FDiffuseLightness,ALightLightness)) 330 548 else 331 Context^.lightness += DiffuseLightnessTerm32768;549 Context^.lightness += CombineLightness(DiffuseLightnessTerm32768,ALightLightness); 332 550 end; 333 551 end; … … 561 779 function TBGRADirectionalLight3D.GetDirection: TPoint3D; 562 780 begin 563 result := Point3D( FDirection.x,FDirection.y,FDirection.z);781 result := Point3D(-FDirection.x,-FDirection.y,-FDirection.z); 564 782 end; 565 783
Note:
See TracChangeset
for help on using the changeset viewer.