1
|
|
|
<?php |
2
|
|
|
/** @formatter:off |
3
|
|
|
* ****************************************************************** |
4
|
|
|
* Created by Marko Kungla on Jun 21, 2016 - 1:53:21 AM |
5
|
|
|
* Contact [email protected] |
6
|
|
|
* @copyright 2016 Marko Kungla - https://github.com/mkungla |
7
|
|
|
* @license The MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* @category AframeVR |
10
|
|
|
* @package aframe-php |
11
|
|
|
* |
12
|
|
|
* Lang PHP (php version >= 7) |
13
|
|
|
* Encoding UTF-8 |
14
|
|
|
* File Standard.php |
15
|
|
|
* Code format PSR-2 and 12 |
16
|
|
|
* @link https://github.com/mkungla/aframe-php |
17
|
|
|
* @issues https://github.com/mkungla/aframe-php/issues |
18
|
|
|
* ******************************************************************** |
19
|
|
|
* Contributors: |
20
|
|
|
* @author Marko Kungla <[email protected]> |
21
|
|
|
* ******************************************************************** |
22
|
|
|
* Comments: |
23
|
|
|
* @formatter:on */ |
24
|
|
|
namespace AframeVR\Core\Shaders; |
25
|
|
|
|
26
|
|
|
use \AframeVR\Interfaces\ShaderInterface; |
27
|
|
|
use \AframeVR\Core\Helpers\ShaderAbstract; |
28
|
|
|
|
29
|
|
|
class Standard extends ShaderAbstract implements ShaderInterface |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Shader |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $shader = 'standard'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Base diffuse color. |
40
|
|
|
* |
41
|
|
|
* @var string $color |
42
|
|
|
*/ |
43
|
|
|
protected $color = '#fff'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Height of video (in pixels), if defining a video texture. |
47
|
|
|
* |
48
|
|
|
* @var int $height |
49
|
|
|
*/ |
50
|
|
|
protected $height = 360; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Environment cubemap texture for reflections. |
54
|
|
|
* |
55
|
|
|
* Can be a selector to or a comma-separated list of URLs. |
56
|
|
|
* |
57
|
|
|
* @var string|null $envMap |
58
|
|
|
*/ |
59
|
|
|
protected $envMap = null; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Whether or not material is affected by fog. |
63
|
|
|
* |
64
|
|
|
* @var string $fog |
65
|
|
|
*/ |
66
|
|
|
protected $fog = 'true'; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* How metallic the material is from 0 to 1. |
70
|
|
|
* |
71
|
|
|
* @var float $metalness |
72
|
|
|
*/ |
73
|
|
|
protected $metalness = 0.5; |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* How rough the material is from 0 to 1. |
78
|
|
|
* A rougher material will scatter |
79
|
|
|
* reflected light in more directions than a smooth material. |
80
|
|
|
* |
81
|
|
|
* @var float $roughness |
82
|
|
|
*/ |
83
|
|
|
protected $roughness = 0.5; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Image or video texture map. |
87
|
|
|
* Can either be a selector to an <img> or <video>, or an inline URL. |
88
|
|
|
* |
89
|
|
|
* @var string|null $src |
90
|
|
|
*/ |
91
|
|
|
protected $src = null; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Width of video (in pixels), if defining a video texture. |
95
|
|
|
* |
96
|
|
|
* @var int $width |
97
|
|
|
*/ |
98
|
|
|
protected $width = 640; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Set shader defaults |
102
|
|
|
* |
103
|
|
|
* @return void |
104
|
|
|
*/ |
105
|
1 |
|
public function defaults() |
106
|
|
|
{ |
107
|
1 |
|
$this->color('#fff'); |
108
|
1 |
|
$this->height(360); |
109
|
1 |
|
$this->envMap(); |
110
|
1 |
|
$this->fog(true); |
111
|
1 |
|
$this->metalness(0.5); |
112
|
1 |
|
$this->roughness(0.5); |
113
|
1 |
|
$this->src(); |
114
|
1 |
|
$this->width(640); |
115
|
1 |
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Base diffuse color |
119
|
|
|
* |
120
|
|
|
* @param string $color |
121
|
|
|
*/ |
122
|
10 |
|
public function color(string $color) |
123
|
|
|
{ |
124
|
10 |
|
$this->color = $color; |
125
|
10 |
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Height of video (in pixels), if defining a video texture. |
130
|
|
|
* |
131
|
|
|
* @param int $height |
132
|
|
|
*/ |
133
|
2 |
|
public function height($height) |
134
|
|
|
{ |
135
|
2 |
|
$this->height = $height; |
136
|
2 |
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* envMap |
141
|
|
|
* |
142
|
|
|
* Environment cubemap texture for reflections. |
143
|
|
|
* Can be a selector to or a comma-separated list of URLs. |
144
|
|
|
* |
145
|
|
|
* @param string|null $envMap |
146
|
|
|
*/ |
147
|
2 |
|
public function envMap(string $envMap = null) |
148
|
|
|
{ |
149
|
2 |
|
$this->envMap = $envMap; |
150
|
2 |
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Whether or not material is affected by fog. |
155
|
|
|
* |
156
|
|
|
* @param bool $fog |
157
|
|
|
*/ |
158
|
2 |
|
public function fog($fog) |
159
|
|
|
{ |
160
|
2 |
|
$this->fog = $fog ? 'true' : 'false'; |
161
|
2 |
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* How metallic the material is from 0 to 1. |
166
|
|
|
* |
167
|
|
|
* @param float $metalness |
168
|
|
|
*/ |
169
|
8 |
|
public function metalness($metalness) |
170
|
|
|
{ |
171
|
8 |
|
$this->metalness = $metalness; |
172
|
8 |
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* How rough the material is from 0 to 1 |
177
|
|
|
* |
178
|
|
|
* A rougher material will scatter reflected light in more directions than a smooth material. |
179
|
|
|
* |
180
|
|
|
* @param float $roughness |
181
|
|
|
*/ |
182
|
4 |
|
public function roughness(float $roughness) |
183
|
|
|
{ |
184
|
4 |
|
$this->roughness = $roughness; |
185
|
4 |
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* How many times a texture (defined by src) repeats in the X and Y direction. |
190
|
|
|
* |
191
|
|
|
* @param string|null $src |
192
|
|
|
*/ |
193
|
9 |
|
public function src(string $src = null) |
194
|
|
|
{ |
195
|
9 |
|
$this->src = $src; |
196
|
9 |
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Width of video (in pixels), if defining a video texture. |
201
|
|
|
* |
202
|
|
|
* @param int $width |
203
|
|
|
*/ |
204
|
2 |
|
public function width(int $width) |
205
|
|
|
{ |
206
|
2 |
|
$this->width = $width; |
207
|
2 |
|
return $this; |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
|