| 1 |
{%MainUnit castlescene.pas} |
| 2 |
{ |
| 3 |
Copyright 2022-2022 Michalis Kamburelis. |
| 4 |
|
| 5 |
This file is part of "Castle Game Engine". |
| 6 |
|
| 7 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 8 |
included in this distribution, for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
} |
| 16 |
|
| 17 |
{ Environment light. } |
| 18 |
|
| 19 |
{$ifdef read_interface} |
| 20 |
|
| 21 |
type |
| 22 |
{ Environment light in an environment (like a sky) defined as a cubemap that shines on everything. |
| 23 |
It is like a sky that lights everything. |
| 24 |
It is sometimes called image-based lighting. |
| 25 |
|
| 26 |
See @url(https://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/components/lighting.html#EnvironmentLight |
| 27 |
X3D EnvironmentLight specification) for various details. } |
| 28 |
TCastleEnvironmentLight = class(TCastleAbstractLight) |
| 29 |
strict private |
| 30 |
{ Same thing as FLightNode, but with proper type. } |
| 31 |
FEnvironmentLight: TEnvironmentLightNode; |
| 32 |
|
| 33 |
FDiffuseTextureCubemap: String; |
| 34 |
FDiffuseTextureNegativeZ: String; |
| 35 |
FDiffuseTexturePositiveZ: String; |
| 36 |
FDiffuseTexturePositiveY: String; |
| 37 |
FDiffuseTextureNegativeY: String; |
| 38 |
FDiffuseTextureNegativeX: String; |
| 39 |
FDiffuseTexturePositiveX: String; |
| 40 |
FSpecularTextureCubemap: String; |
| 41 |
FSpecularTextureNegativeZ: String; |
| 42 |
FSpecularTexturePositiveZ: String; |
| 43 |
FSpecularTexturePositiveY: String; |
| 44 |
FSpecularTextureNegativeY: String; |
| 45 |
FSpecularTextureNegativeX: String; |
| 46 |
FSpecularTexturePositiveX: String; |
| 47 |
|
| 48 |
procedure SetDiffuseTextureCubemap(const Value: String); |
| 49 |
procedure SetDiffuseTextureNegativeZ(const Value: String); |
| 50 |
procedure SetDiffuseTexturePositiveZ(const Value: String); |
| 51 |
procedure SetDiffuseTexturePositiveY(const Value: String); |
| 52 |
procedure SetDiffuseTextureNegativeY(const Value: String); |
| 53 |
procedure SetDiffuseTextureNegativeX(const Value: String); |
| 54 |
procedure SetDiffuseTexturePositiveX(const Value: String); |
| 55 |
procedure SetSpecularTextureCubemap(const Value: String); |
| 56 |
procedure SetSpecularTextureNegativeZ(const Value: String); |
| 57 |
procedure SetSpecularTexturePositiveZ(const Value: String); |
| 58 |
procedure SetSpecularTexturePositiveY(const Value: String); |
| 59 |
procedure SetSpecularTextureNegativeY(const Value: String); |
| 60 |
procedure SetSpecularTextureNegativeX(const Value: String); |
| 61 |
procedure SetSpecularTexturePositiveX(const Value: String); |
| 62 |
procedure UpdateTextures; |
| 63 |
public |
| 64 |
constructor Create(AOwner: TComponent); override; |
| 65 |
function PropertySections(const PropertyName: String): TPropertySections; override; |
| 66 |
published |
| 67 |
{ Diffuse texture defined as a cubemap. |
| 68 |
Use DDS cubemap texture here. |
| 69 |
If you set this, the other parameters to define diffuse cubemap as 6 separate images |
| 70 |
are ignored. |
| 71 |
TODO: Cubemaps in KTX should also be supported soon. } |
| 72 |
property DiffuseTextureCubemap: String read FDiffuseTextureCubemap write SetDiffuseTextureCubemap; |
| 73 |
|
| 74 |
{ Diffuse -Z texture. |
| 75 |
All 6 texture sides must be assigned in order for them to work. |
| 76 |
Alternatively, you can assign a KTX / DDS textures to DiffuseTextureCubemap. } |
| 77 |
property DiffuseTextureNegativeZ: String read FDiffuseTextureNegativeZ write SetDiffuseTextureNegativeZ; |
| 78 |
|
| 79 |
{ Diffuse +Z texture. |
| 80 |
All 6 texture sides must be assigned in order for them to work. |
| 81 |
Alternatively, you can assign a KTX / DDS textures to DiffuseTextureCubemap. } |
| 82 |
property DiffuseTexturePositiveZ: String read FDiffuseTexturePositiveZ write SetDiffuseTexturePositiveZ; |
| 83 |
|
| 84 |
{ Diffuse +Y texture. |
| 85 |
All 6 texture sides must be assigned in order for them to work. |
| 86 |
Alternatively, you can assign a KTX / DDS textures to DiffuseTextureCubemap. } |
| 87 |
property DiffuseTexturePositiveY: String read FDiffuseTexturePositiveY write SetDiffuseTexturePositiveY; |
| 88 |
|
| 89 |
{ Diffuse -Y texture. |
| 90 |
All 6 texture sides must be assigned in order for them to work. |
| 91 |
Alternatively, you can assign a KTX / DDS textures to DiffuseTextureCubemap. } |
| 92 |
property DiffuseTextureNegativeY: String read FDiffuseTextureNegativeY write SetDiffuseTextureNegativeY; |
| 93 |
|
| 94 |
{ Diffuse -X texture. |
| 95 |
All 6 texture sides must be assigned in order for them to work. |
| 96 |
Alternatively, you can assign a KTX / DDS textures to DiffuseTextureCubemap. } |
| 97 |
property DiffuseTextureNegativeX: String read FDiffuseTextureNegativeX write SetDiffuseTextureNegativeX; |
| 98 |
|
| 99 |
{ Diffuse +X texture. |
| 100 |
All 6 texture sides must be assigned in order for them to work. |
| 101 |
Alternatively, you can assign a KTX / DDS textures to DiffuseTextureCubemap. } |
| 102 |
property DiffuseTexturePositiveX: String read FDiffuseTexturePositiveX write SetDiffuseTexturePositiveX; |
| 103 |
|
| 104 |
{ Specular texture defined as a cubemap. |
| 105 |
Use DDS cubemap texture here. |
| 106 |
If you set this, the other parameters to define diffuse cubemap as 6 separate images |
| 107 |
are ignored. |
| 108 |
TODO: Cubemaps in KTX should also be supported soon. } |
| 109 |
property SpecularTextureCubemap: String read FSpecularTextureCubemap write SetSpecularTextureCubemap; |
| 110 |
|
| 111 |
{ Specular -Z texture. |
| 112 |
All 6 texture sides must be assigned in order for them to work. |
| 113 |
Alternatively, you can assign a KTX / DDS textures to SpecularTextureCubemap. } |
| 114 |
property SpecularTextureNegativeZ: String read FSpecularTextureNegativeZ write SetSpecularTextureNegativeZ; |
| 115 |
|
| 116 |
{ Specular +Z texture. |
| 117 |
All 6 texture sides must be assigned in order for them to work. |
| 118 |
Alternatively, you can assign a KTX / DDS textures to SpecularTextureCubemap. } |
| 119 |
property SpecularTexturePositiveZ: String read FSpecularTexturePositiveZ write SetSpecularTexturePositiveZ; |
| 120 |
|
| 121 |
{ Specular +Y texture. |
| 122 |
All 6 texture sides must be assigned in order for them to work. |
| 123 |
Alternatively, you can assign a KTX / DDS textures to SpecularTextureCubemap. } |
| 124 |
property SpecularTexturePositiveY: String read FSpecularTexturePositiveY write SetSpecularTexturePositiveY; |
| 125 |
|
| 126 |
{ Specular -Y texture. |
| 127 |
All 6 texture sides must be assigned in order for them to work. |
| 128 |
Alternatively, you can assign a KTX / DDS textures to SpecularTextureCubemap. } |
| 129 |
property SpecularTextureNegativeY: String read FSpecularTextureNegativeY write SetSpecularTextureNegativeY; |
| 130 |
|
| 131 |
{ Specular -X texture. |
| 132 |
All 6 texture sides must be assigned in order for them to work. |
| 133 |
Alternatively, you can assign a KTX / DDS textures to SpecularTextureCubemap. } |
| 134 |
property SpecularTextureNegativeX: String read FSpecularTextureNegativeX write SetSpecularTextureNegativeX; |
| 135 |
|
| 136 |
{ Specular +X texture. |
| 137 |
All 6 texture sides must be assigned in order for them to work. |
| 138 |
Alternatively, you can assign a KTX / DDS textures to SpecularTextureCubemap. } |
| 139 |
property SpecularTexturePositiveX: String read FSpecularTexturePositiveX write SetSpecularTexturePositiveX; |
| 140 |
end; |
| 141 |
|
| 142 |
{$endif read_interface} |
| 143 |
|
| 144 |
{$ifdef read_implementation} |
| 145 |
|
| 146 |
constructor TCastleEnvironmentLight.Create(AOwner: TComponent); |
| 147 |
begin |
| 148 |
inherited; |
| 149 |
|
| 150 |
{ internal stuff create } |
| 151 |
FEnvironmentLight := TEnvironmentLightNode.Create; |
| 152 |
FEnvironmentLight.Global := true; |
| 153 |
LightNode := FEnvironmentLight; |
| 154 |
if Gizmo <> nil then |
| 155 |
if InternalCastleDesignData <> '' then |
| 156 |
Gizmo.SetIconUrl(InternalCastleDesignData + 'gizmos/light/light_environment.png'); |
| 157 |
end; |
| 158 |
|
| 159 |
function TCastleEnvironmentLight.PropertySections(const PropertyName: String): TPropertySections; |
| 160 |
begin |
| 161 |
if (PropertyName = 'DiffuseTextureCubemap') or |
| 162 |
(PropertyName = 'DiffuseTextureNegativeZ') or |
| 163 |
(PropertyName = 'DiffuseTexturePositiveZ') or |
| 164 |
(PropertyName = 'DiffuseTexturePositiveY') or |
| 165 |
(PropertyName = 'DiffuseTextureNegativeY') or |
| 166 |
(PropertyName = 'DiffuseTextureNegativeX') or |
| 167 |
(PropertyName = 'DiffuseTexturePositiveX') or |
| 168 |
(PropertyName = 'SpecularTextureCubemap') or |
| 169 |
(PropertyName = 'SpecularTextureNegativeZ') or |
| 170 |
(PropertyName = 'SpecularTexturePositiveZ') or |
| 171 |
(PropertyName = 'SpecularTexturePositiveY') or |
| 172 |
(PropertyName = 'SpecularTextureNegativeY') or |
| 173 |
(PropertyName = 'SpecularTextureNegativeX') or |
| 174 |
(PropertyName = 'SpecularTexturePositiveX') then |
| 175 |
Result := [psBasic] |
| 176 |
else |
| 177 |
Result := inherited PropertySections(PropertyName); |
| 178 |
end; |
| 179 |
|
| 180 |
procedure TCastleEnvironmentLight.SetDiffuseTextureCubemap(const Value: String); |
| 181 |
begin |
| 182 |
if FDiffuseTextureCubemap <> Value then |
| 183 |
begin |
| 184 |
FDiffuseTextureCubemap := Value; |
| 185 |
UpdateTextures; |
| 186 |
end; |
| 187 |
end; |
| 188 |
|
| 189 |
procedure TCastleEnvironmentLight.SetDiffuseTextureNegativeZ(const Value: String); |
| 190 |
begin |
| 191 |
if FDiffuseTextureNegativeZ <> Value then |
| 192 |
begin |
| 193 |
FDiffuseTextureNegativeZ := Value; |
| 194 |
UpdateTextures; |
| 195 |
end; |
| 196 |
end; |
| 197 |
|
| 198 |
procedure TCastleEnvironmentLight.SetDiffuseTexturePositiveZ(const Value: String); |
| 199 |
begin |
| 200 |
if FDiffuseTexturePositiveZ <> Value then |
| 201 |
begin |
| 202 |
FDiffuseTexturePositiveZ := Value; |
| 203 |
UpdateTextures; |
| 204 |
end; |
| 205 |
end; |
| 206 |
|
| 207 |
procedure TCastleEnvironmentLight.SetDiffuseTexturePositiveY(const Value: String); |
| 208 |
begin |
| 209 |
if FDiffuseTexturePositiveY <> Value then |
| 210 |
begin |
| 211 |
FDiffuseTexturePositiveY := Value; |
| 212 |
UpdateTextures; |
| 213 |
end; |
| 214 |
end; |
| 215 |
|
| 216 |
procedure TCastleEnvironmentLight.SetDiffuseTextureNegativeY(const Value: String); |
| 217 |
begin |
| 218 |
if FDiffuseTextureNegativeY <> Value then |
| 219 |
begin |
| 220 |
FDiffuseTextureNegativeY := Value; |
| 221 |
UpdateTextures; |
| 222 |
end; |
| 223 |
end; |
| 224 |
|
| 225 |
procedure TCastleEnvironmentLight.SetDiffuseTextureNegativeX(const Value: String); |
| 226 |
begin |
| 227 |
if FDiffuseTextureNegativeX <> Value then |
| 228 |
begin |
| 229 |
FDiffuseTextureNegativeX := Value; |
| 230 |
UpdateTextures; |
| 231 |
end; |
| 232 |
end; |
| 233 |
|
| 234 |
procedure TCastleEnvironmentLight.SetDiffuseTexturePositiveX(const Value: String); |
| 235 |
begin |
| 236 |
if FDiffuseTexturePositiveX <> Value then |
| 237 |
begin |
| 238 |
FDiffuseTexturePositiveX := Value; |
| 239 |
UpdateTextures; |
| 240 |
end; |
| 241 |
end; |
| 242 |
|
| 243 |
procedure TCastleEnvironmentLight.SetSpecularTextureCubemap(const Value: String); |
| 244 |
begin |
| 245 |
if FSpecularTextureCubemap <> Value then |
| 246 |
begin |
| 247 |
FSpecularTextureCubemap := Value; |
| 248 |
UpdateTextures; |
| 249 |
end; |
| 250 |
end; |
| 251 |
|
| 252 |
procedure TCastleEnvironmentLight.SetSpecularTextureNegativeZ(const Value: String); |
| 253 |
begin |
| 254 |
if FSpecularTextureNegativeZ <> Value then |
| 255 |
begin |
| 256 |
FSpecularTextureNegativeZ := Value; |
| 257 |
UpdateTextures; |
| 258 |
end; |
| 259 |
end; |
| 260 |
|
| 261 |
procedure TCastleEnvironmentLight.SetSpecularTexturePositiveZ(const Value: String); |
| 262 |
begin |
| 263 |
if FSpecularTexturePositiveZ <> Value then |
| 264 |
begin |
| 265 |
FSpecularTexturePositiveZ := Value; |
| 266 |
UpdateTextures; |
| 267 |
end; |
| 268 |
end; |
| 269 |
|
| 270 |
procedure TCastleEnvironmentLight.SetSpecularTexturePositiveY(const Value: String); |
| 271 |
begin |
| 272 |
if FSpecularTexturePositiveY <> Value then |
| 273 |
begin |
| 274 |
FSpecularTexturePositiveY := Value; |
| 275 |
UpdateTextures; |
| 276 |
end; |
| 277 |
end; |
| 278 |
|
| 279 |
procedure TCastleEnvironmentLight.SetSpecularTextureNegativeY(const Value: String); |
| 280 |
begin |
| 281 |
if FSpecularTextureNegativeY <> Value then |
| 282 |
begin |
| 283 |
FSpecularTextureNegativeY := Value; |
| 284 |
UpdateTextures; |
| 285 |
end; |
| 286 |
end; |
| 287 |
|
| 288 |
procedure TCastleEnvironmentLight.SetSpecularTextureNegativeX(const Value: String); |
| 289 |
begin |
| 290 |
if FSpecularTextureNegativeX <> Value then |
| 291 |
begin |
| 292 |
FSpecularTextureNegativeX := Value; |
| 293 |
UpdateTextures; |
| 294 |
end; |
| 295 |
end; |
| 296 |
|
| 297 |
procedure TCastleEnvironmentLight.SetSpecularTexturePositiveX(const Value: String); |
| 298 |
begin |
| 299 |
if FSpecularTexturePositiveX <> Value then |
| 300 |
begin |
| 301 |
FSpecularTexturePositiveX := Value; |
| 302 |
UpdateTextures; |
| 303 |
end; |
| 304 |
end; |
| 305 |
|
| 306 |
procedure TCastleEnvironmentLight.UpdateTextures; |
| 307 |
begin |
| 308 |
// TODO |
| 309 |
end; |
| 310 |
|
| 311 |
{$endif read_implementation} |