-
Notifications
You must be signed in to change notification settings - Fork 0
/
LightHelper.h
113 lines (85 loc) · 3.45 KB
/
LightHelper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef LIGHTHELPER_H
#define LIGHTHELPER_H
#include <cstring>
#include <DirectXMath.h>
// 方向光
struct DirectionalLight
{
DirectionalLight() = default;
DirectionalLight(const DirectionalLight&) = default;
DirectionalLight& operator=(const DirectionalLight&) = default;
DirectionalLight(DirectionalLight&&) = default;
DirectionalLight& operator=(DirectionalLight&&) = default;
DirectionalLight(const DirectX::XMFLOAT4& _ambient, const DirectX::XMFLOAT4& _diffuse, const DirectX::XMFLOAT4& _specular,
const DirectX::XMFLOAT3& _direction) :
ambient(_ambient), diffuse(_diffuse), specular(_specular), direction(_direction), pad() {}
DirectX::XMFLOAT4 ambient;
DirectX::XMFLOAT4 diffuse;
DirectX::XMFLOAT4 specular;
DirectX::XMFLOAT3 direction;
float pad; // 最后用一个浮点数填充使得该结构体大小满足16的倍数,便于我们以后在HLSL设置数组
};
// 点光
struct PointLight
{
PointLight() = default;
PointLight(const PointLight&) = default;
PointLight& operator=(const PointLight&) = default;
PointLight(PointLight&&) = default;
PointLight& operator=(PointLight&&) = default;
PointLight(const DirectX::XMFLOAT4& _ambient, const DirectX::XMFLOAT4& _diffuse, const DirectX::XMFLOAT4& _specular,
const DirectX::XMFLOAT3& _position, float _range, const DirectX::XMFLOAT3& _att) :
ambient(_ambient), diffuse(_diffuse), specular(_specular), position(_position), range(_range), att(_att), pad() {}
DirectX::XMFLOAT4 ambient;
DirectX::XMFLOAT4 diffuse;
DirectX::XMFLOAT4 specular;
// 打包成4D向量: (position, range)
DirectX::XMFLOAT3 position;
float range;
// 打包成4D向量: (A0, A1, A2, pad)
DirectX::XMFLOAT3 att;
float pad; // 最后用一个浮点数填充使得该结构体大小满足16的倍数,便于我们以后在HLSL设置数组
};
// 聚光灯
struct SpotLight
{
SpotLight() = default;
SpotLight(const SpotLight&) = default;
SpotLight& operator=(const SpotLight&) = default;
SpotLight(SpotLight&&) = default;
SpotLight& operator=(SpotLight&&) = default;
SpotLight(const DirectX::XMFLOAT4& _ambient, const DirectX::XMFLOAT4& _diffuse, const DirectX::XMFLOAT4& _specular,
const DirectX::XMFLOAT3& _position, float _range, const DirectX::XMFLOAT3& _direction,
float _spot, const DirectX::XMFLOAT3& _att) :
ambient(_ambient), diffuse(_diffuse), specular(_specular),
position(_position), range(_range), direction(_direction), spot(_spot), att(_att), pad() {}
DirectX::XMFLOAT4 ambient;
DirectX::XMFLOAT4 diffuse;
DirectX::XMFLOAT4 specular;
// 打包成4D向量: (position, range)
DirectX::XMFLOAT3 position;
float range;
// 打包成4D向量: (direction, spot)
DirectX::XMFLOAT3 direction;
float spot;
// 打包成4D向量: (att, pad)
DirectX::XMFLOAT3 att;
float pad; // 最后用一个浮点数填充使得该结构体大小满足16的倍数,便于我们以后在HLSL设置数组
};
// 物体表面材质
struct Material
{
Material() = default;
Material(const Material&) = default;
Material& operator=(const Material&) = default;
Material(Material&&) = default;
Material& operator=(Material&&) = default;
Material(const DirectX::XMFLOAT4& _ambient, const DirectX::XMFLOAT4& _diffuse, const DirectX::XMFLOAT4& _specular,
const DirectX::XMFLOAT4& _reflect) :
ambient(_ambient), diffuse(_diffuse), specular(_specular), Reflect(_reflect) {}
DirectX::XMFLOAT4 ambient;
DirectX::XMFLOAT4 diffuse;
DirectX::XMFLOAT4 specular; // w = 镜面反射强度
DirectX::XMFLOAT4 Reflect;
};
#endif