Ignore:
Timestamp:
Apr 9, 2015, 9:58:36 PM (9 years ago)
Author:
chronos
Message:
  • Fixed: Use csOpaque control style also to Image, PaintBox and OpenGLControl.
  • Modified: Change size of test frame with SpinEdits as delayed using timer.
  • Updated: BRGABitmap package to version 8.1.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/Packages/bgrabitmap/lightingclasses3d.inc

    r452 r472  
    55  TBGRAMaterial3D = class(TInterfacedObject, IBGRAMaterial3D)
    66  private
    7     FDiffuseColorInt: TColorInt65536;
     7    FName: string;
     8    FTexture: IBGRAScanner;
     9    FAutoSimpleColor,FAutoAmbiantColor,FAutoDiffuseColor,FAutoSpecularColor: boolean;
     10    FSimpleColorInt, FAmbiantColorInt, FDiffuseColorInt: TColorInt65536;
    811    FDiffuseLightness: integer;
     12    FTextureZoom: TPointF;
     13
    914    FSpecularColorInt: TColorInt65536;
    10     FAutoDiffuseColor,FAutoSpecularColor: boolean;
    1115    FSpecularIndex: integer;
    1216    FSpecularOn: boolean;
     17
    1318    FSaturationLowF: single;
    1419    FSaturationHighF: single;
     
    2126
    2227    procedure UpdateSpecular;
     28    procedure UpdateSimpleColor;
    2329    procedure ComputePowerTable;
    2430  public
     
    2632    destructor Destroy; override;
    2733
     34    function GetAutoAmbiantColor: boolean;
    2835    function GetAutoDiffuseColor: boolean;
    2936    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;
    3043    function GetDiffuseColor: TBGRAPixel;
    3144    function GetDiffuseColorF: TColorF;
     
    3851    function GetSaturationHigh: single;
    3952    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);
    4060    procedure SetAutoDiffuseColor(const AValue: boolean);
    4161    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);
    4267    procedure SetDiffuseColor(const AValue: TBGRAPixel);
    4368    procedure SetDiffuseColorF(const AValue: TColorF);
     
    5075    procedure SetSaturationHigh(const AValue: single);
    5176    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);
    5285
    5386    function GetSpecularOn: boolean;
     
    6396procedure TBGRAMaterial3D.UpdateSpecular;
    6497begin
     98  FAutoSpecularColor := (FSpecularColorInt.r = 65536) and (FSpecularColorInt.g = 65536) and (FSpecularColorInt.b = 65536) and (FSpecularColorInt.a = 65536);
    6599  FSpecularOn := (FSpecularIndex > 0) and ((FSpecularColorInt.r <> 0) or (FSpecularColorInt.g <> 0) or (FSpecularColorInt.b <> 0) or
    66100                                            FAutoSpecularColor);
     101end;
     102
     103procedure TBGRAMaterial3D.UpdateSimpleColor;
     104begin
     105  FSimpleColorInt := (FAmbiantColorInt+FDiffuseColorInt)*32768;
     106  FAutoSimpleColor := (FSimpleColorInt.r = 65536) and (FSimpleColorInt.g = 65536) and (FSimpleColorInt.b = 65536) and (FSimpleColorInt.a = 65536);
    67107end;
    68108
     
    91131constructor TBGRAMaterial3D.Create;
    92132begin
     133  SetAmbiantColorInt(ColorInt65536(65536,65536,65536));
    93134  SetDiffuseColorInt(ColorInt65536(65536,65536,65536));
    94   FAutoDiffuseColor:= True;
    95   FSpecularColorInt := ColorInt65536(0,0,0);
    96   FAutoSpecularColor:= True;
    97135  FSpecularIndex := 10;
    98   FSpecularOn := false;
     136  SetSpecularColorInt(ColorInt65536(0,0,0));
    99137  FLightThroughFactor:= 0;
    100138  SetSaturationLow(2);
    101139  SetSaturationHigh(3);
    102140
     141  FTexture := nil;
     142  FTextureZoom := PointF(1,1);
     143
    103144  FPowerTableSize := 128;
    104145  FPowerTableSizeF := FPowerTableSize;
     
    111152end;
    112153
     154function TBGRAMaterial3D.GetAutoAmbiantColor: boolean;
     155begin
     156  result := FAutoAmbiantColor;
     157end;
     158
     159procedure TBGRAMaterial3D.SetDiffuseAlpha(AValue: byte);
     160begin
     161  if AValue = 0 then
     162    FDiffuseColorInt.a := 0
     163  else
     164    FDiffuseColorInt.a := AValue*257+1;
     165  UpdateSimpleColor;
     166end;
     167
    113168function TBGRAMaterial3D.GetAutoDiffuseColor: boolean;
    114169begin
     
    121176end;
    122177
     178function TBGRAMaterial3D.GetAutoSimpleColor: boolean;
     179begin
     180  result := FAutoSimpleColor;
     181end;
     182
     183function TBGRAMaterial3D.GetAmbiantAlpha: byte;
     184var v: integer;
     185begin
     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;
     194end;
     195
     196function TBGRAMaterial3D.GetAmbiantColor: TBGRAPixel;
     197begin
     198  result := ColorIntToBGRA(FAmbiantColorInt);
     199end;
     200
     201function TBGRAMaterial3D.GetAmbiantColorF: TColorF;
     202begin
     203  result := ColorInt65536ToColorF(FAmbiantColorInt);
     204end;
     205
     206function TBGRAMaterial3D.GetAmbiantColorInt: TColorInt65536;
     207begin
     208  result := FAmbiantColorInt;
     209end;
     210
     211function TBGRAMaterial3D.GetDiffuseAlpha: byte;
     212var v: integer;
     213begin
     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;
     222end;
     223
    123224function TBGRAMaterial3D.GetDiffuseColor: TBGRAPixel;
    124225begin
     
    171272end;
    172273
     274function TBGRAMaterial3D.GetSimpleAlpha: byte;
     275begin
     276  result := (GetAmbiantAlpha + GetDiffuseAlpha) shr 1;
     277end;
     278
     279function TBGRAMaterial3D.GetSimpleColor: TBGRAPixel;
     280begin
     281  result := ColorIntToBGRA(GetSimpleColorInt);
     282end;
     283
     284function TBGRAMaterial3D.GetSimpleColorF: TColorF;
     285begin
     286  result := ColorInt65536ToColorF(GetSimpleColorInt);
     287end;
     288
     289function TBGRAMaterial3D.GetSimpleColorInt: TColorInt65536;
     290begin
     291  result := (GetAmbiantColorInt + GetDiffuseColorInt)*32768;
     292end;
     293
     294function TBGRAMaterial3D.GetTexture: IBGRAScanner;
     295begin
     296  result := FTexture;
     297end;
     298
     299function TBGRAMaterial3D.GetTextureZoom: TPointF;
     300begin
     301  result := FTextureZoom;
     302end;
     303
     304procedure TBGRAMaterial3D.SetAutoAmbiantColor(const AValue: boolean);
     305begin
     306  If AValue then
     307    SetAmbiantColorInt(ColorInt65536(65536,65536,65536));
     308end;
     309
    173310procedure TBGRAMaterial3D.SetAutoDiffuseColor(const AValue: boolean);
    174311begin
    175   FAutoDiffuseColor:= AValue;
     312  If AValue then
     313    SetDiffuseColorInt(ColorInt65536(65536,65536,65536));
    176314end;
    177315
    178316procedure TBGRAMaterial3D.SetAutoSpecularColor(const AValue: boolean);
    179317begin
    180   FAutoSpecularColor:= AValue;
    181   UpdateSpecular;
     318  If AValue then
     319    SetSpecularColorInt(ColorInt65536(65536,65536,65536));
     320end;
     321
     322procedure TBGRAMaterial3D.SetAmbiantAlpha(AValue: byte);
     323begin
     324  if AValue = 0 then
     325    FAmbiantColorInt.a := 0
     326  else
     327    FAmbiantColorInt.a := AValue*257+1;
     328  UpdateSimpleColor;
     329end;
     330
     331procedure TBGRAMaterial3D.SetAmbiantColor(const AValue: TBGRAPixel);
     332begin
     333  FAmbiantColorInt := BGRAToColorInt(AValue);
     334  FAutoAmbiantColor := (FAmbiantColorInt.r = 65536) and (FAmbiantColorInt.g = 65536) and (FAmbiantColorInt.b = 65536) and (FAmbiantColorInt.a = 65536);
     335  UpdateSimpleColor;
     336end;
     337
     338procedure TBGRAMaterial3D.SetAmbiantColorF(const AValue: TColorF);
     339begin
     340  FAmbiantColorInt := ColorFToColorInt65536(AValue);
     341  FAutoAmbiantColor := (FAmbiantColorInt.r = 65536) and (FAmbiantColorInt.g = 65536) and (FAmbiantColorInt.b = 65536) and (FAmbiantColorInt.a = 65536);
     342  UpdateSimpleColor;
     343end;
     344
     345procedure TBGRAMaterial3D.SetAmbiantColorInt(const AValue: TColorInt65536);
     346begin
     347  FAmbiantColorInt := AValue;
     348  FAutoAmbiantColor := (FAmbiantColorInt.r = 65536) and (FAmbiantColorInt.g = 65536) and (FAmbiantColorInt.b = 65536) and (FAmbiantColorInt.a = 65536);
     349  UpdateSimpleColor;
    182350end;
    183351
     
    186354  FDiffuseColorInt := BGRAToColorInt(AValue);
    187355  FDiffuseLightness := (FDiffuseColorInt.r + FDiffuseColorInt.g + FDiffuseColorInt.b) div 6;
     356  FAutoDiffuseColor:= (FDiffuseColorInt.r = 65536) and (FDiffuseColorInt.g = 65536) and (FDiffuseColorInt.b = 65536);
     357  UpdateSimpleColor;
    188358end;
    189359
     
    192362  FDiffuseColorInt := ColorFToColorInt65536(AValue);
    193363  FDiffuseLightness := (FDiffuseColorInt.r + FDiffuseColorInt.g + FDiffuseColorInt.b) div 6;
     364  FAutoDiffuseColor:= (FDiffuseColorInt.r = 65536) and (FDiffuseColorInt.g = 65536) and (FDiffuseColorInt.b = 65536);
     365  UpdateSimpleColor;
    194366end;
    195367
     
    198370  FDiffuseColorInt := AValue;
    199371  FDiffuseLightness := (FDiffuseColorInt.r + FDiffuseColorInt.g + FDiffuseColorInt.b) div 6;
     372  FAutoDiffuseColor:= (FDiffuseColorInt.r = 65536) and (FDiffuseColorInt.g = 65536) and (FDiffuseColorInt.b = 65536);
     373  UpdateSimpleColor;
    200374end;
    201375
     
    238412begin
    239413  FSaturationLowF:= AValue;
     414end;
     415
     416procedure TBGRAMaterial3D.SetSimpleAlpha(AValue: byte);
     417begin
     418  SetAmbiantAlpha(AValue);
     419  SetDiffuseAlpha(AValue);
     420end;
     421
     422procedure TBGRAMaterial3D.SetSimpleColor(AValue: TBGRAPixel);
     423begin
     424  SetAmbiantColor(AValue);
     425  SetDiffuseColor(AValue);
     426end;
     427
     428procedure TBGRAMaterial3D.SetSimpleColorF(AValue: TColorF);
     429begin
     430  SetAmbiantColorF(AValue);
     431  SetDiffuseColorF(AValue);
     432end;
     433
     434procedure TBGRAMaterial3D.SetSimpleColorInt(AValue: TColorInt65536);
     435begin
     436  SetAmbiantColorInt(AValue);
     437  SetDiffuseColorInt(AValue);
     438end;
     439
     440procedure TBGRAMaterial3D.SetTexture(AValue: IBGRAScanner);
     441begin
     442  FTexture := AValue;
     443end;
     444
     445procedure TBGRAMaterial3D.SetTextureZoom(AValue: TPointF);
     446begin
     447  FTextureZoom := AValue;
     448end;
     449
     450function TBGRAMaterial3D.GetName: string;
     451begin
     452  result := FName;
     453end;
     454
     455procedure TBGRAMaterial3D.SetName(const AValue: string);
     456begin
     457  FName := AValue;
    240458end;
    241459
     
    283501    end
    284502    else
    285       NH *= FPowerTableSize;
     503      PowerTablePos := NH*FPowerTableSize;
    286504    {$ELSE}
    287505    PowerTablePos := NH;
     
    298516    Context^.diffuseColor += ALightColor*round(DiffuseIntensity*65536)
    299517  else
    300     Context^.diffuseColor += FDiffuseColorInt*round(DiffuseIntensity*65536);
     518    Context^.diffuseColor += ALightColor*FDiffuseColorInt*round(DiffuseIntensity*65536);
    301519
    302520  if FAutoSpecularColor then
    303521    Context^.specularColor += ALightColor*round(SpecularIntensity* NnH*65536)
    304522  else
    305     Context^.specularColor += FSpecularColorInt*round(SpecularIntensity* NnH*65536);
     523    Context^.specularColor += ALightColor*FSpecularColorInt*round(SpecularIntensity* NnH*65536);
    306524end;
    307525
     
    312530    Context^.diffuseColor += ALightColor*round(DiffuseIntensity*65536)
    313531  else
    314     Context^.diffuseColor += FDiffuseColorInt*round(DiffuseIntensity*65536);
     532    Context^.diffuseColor += ALightColor*FDiffuseColorInt*round(DiffuseIntensity*65536);
    315533end;
    316534
     
    327545  begin
    328546    if FDiffuseLightness <> 32768 then
    329       Context^.lightness += CombineLightness(DiffuseLightnessTerm32768,FDiffuseLightness)
     547      Context^.lightness += CombineLightness(DiffuseLightnessTerm32768,CombineLightness(FDiffuseLightness,ALightLightness))
    330548    else
    331       Context^.lightness += DiffuseLightnessTerm32768;
     549      Context^.lightness += CombineLightness(DiffuseLightnessTerm32768,ALightLightness);
    332550  end;
    333551end;
     
    561779function TBGRADirectionalLight3D.GetDirection: TPoint3D;
    562780begin
    563   result := Point3D(FDirection.x,FDirection.y,FDirection.z);
     781  result := Point3D(-FDirection.x,-FDirection.y,-FDirection.z);
    564782end;
    565783
Note: See TracChangeset for help on using the changeset viewer.