1 | {$i bgrasse.inc}
|
---|
2 | var
|
---|
3 | {%H-}dist2,LdotN,NdotH,lightEnergy,diffuse : single;
|
---|
4 | begin
|
---|
5 | {$IFDEF BGRASSE_AVAILABLE}If UseSSE then
|
---|
6 | begin
|
---|
7 | with Context^ do
|
---|
8 | begin
|
---|
9 | {$IFDEF PARAM_POINTLIGHT}
|
---|
10 | vL := FVertex.ViewCoord_128;
|
---|
11 | vH := FViewVector;
|
---|
12 | {$ELSE}
|
---|
13 | vL := FDirection;
|
---|
14 | vH := FBetweenDirectionAndObserver;
|
---|
15 | {$ENDIF}
|
---|
16 | end;
|
---|
17 | if UseSSE3 then
|
---|
18 | begin
|
---|
19 | {$DEFINE PARAM_USESSE3}
|
---|
20 | {$i phonglightsse.inc}
|
---|
21 | {$UNDEF PARAM_USESSE3}
|
---|
22 | end else
|
---|
23 | begin
|
---|
24 | {$i phonglightsse.inc}
|
---|
25 | end;
|
---|
26 | end else
|
---|
27 | {$ENDIF}
|
---|
28 | with Context^ do
|
---|
29 | begin
|
---|
30 | {$IFDEF PARAM_POINTLIGHT}
|
---|
31 | vL := FVertex.ViewCoord_128 - basic.Position;
|
---|
32 | Normalize3D_128_SqLen(vL, dist2);
|
---|
33 | //compute bisector of angle between light and observer
|
---|
34 | vH := vL + FViewVector;
|
---|
35 | Normalize3D_128(vH);
|
---|
36 | //Calculate LdotN and NnH
|
---|
37 | LdotN := DotProduct3D_128(basic.Normal, vL);
|
---|
38 | NdotH := DotProduct3D_128(basic.Normal, vH);
|
---|
39 | {$ELSE}
|
---|
40 | LdotN := DotProduct3D_128(basic.Normal, FDirection);
|
---|
41 | NdotH := DotProduct3D_128(basic.Normal, FBetweenDirectionAndObserver);
|
---|
42 | {$ENDIF}
|
---|
43 | end;
|
---|
44 |
|
---|
45 | {$IFDEF PARAM_POINTLIGHT}
|
---|
46 | if dist2 = 0 then
|
---|
47 | lightEnergy := 0
|
---|
48 | else
|
---|
49 | lightEnergy := FIntensity / dist2;
|
---|
50 | diffuse := LdotN*lightEnergy;
|
---|
51 | {$ELSE}
|
---|
52 | lightEnergy := 1;
|
---|
53 | diffuse := LdotN;
|
---|
54 | {$ENDIF}
|
---|
55 | if diffuse < FMinIntensity then diffuse:= FMinIntensity;
|
---|
56 |
|
---|
57 | if Context^.LightThrough and (diffuse < 0) then diffuse := -diffuse*Context^.LightThroughFactor;
|
---|
58 | TBGRAMaterial3D(Context^.material).ComputeDiffuseAndSpecularColor(Context, diffuse, lightEnergy, NdotH, FColorInt);
|
---|
59 | end;
|
---|
60 |
|
---|
61 | {$UNDEF PARAM_POINTLIGHT}
|
---|