-
Notifications
You must be signed in to change notification settings - Fork 1
/
lights.fx
47 lines (38 loc) · 1.24 KB
/
lights.fx
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
#include "container.fx"
float4 gMaterialAmbient < string materialState="Ambient"; >;
float4 gMaterialDiffuse < string materialState="Diffuse"; >;
float4 gMaterialSpecular < string materialState="Specular"; >;
float4 gMaterialEmissive < string materialState="Emissive"; >;
float gMaterialSpecPower < string materialState="Power"; >;
static float M_EPS = 1/256.0;
static float4 WHITE = 1;
static int NOT_LIGHT = -1;
static float3 LIGHTS_FLAGS[MACRO_LIGHTS_FLAGS_ARRAY_SIZE] = {
MACRO_LIGHTS_FLAGS_ARRAY
};
bool MatchRGB(float3 rgb1, float3 rgb2) {
return
abs(rgb1.r - rgb2.r) < M_EPS &&
abs(rgb1.g - rgb2.g) < M_EPS &&
abs(rgb1.b - rgb2.b) < M_EPS;
}
int DetectLight() {
for(int light = 0; light < MACRO_LIGHTS_FLAGS_ARRAY_SIZE; light++) {
if (MatchRGB(LIGHTS_FLAGS[light]/255, gMaterialDiffuse.rgb)) return light;
}
return NOT_LIGHT;
}
static int CURRENT_LIGHT = DetectLight();
technique lights {
pass P0 {
MaterialAmbient = gMaterialAmbient/gMaterialDiffuse;
MaterialDiffuse = WHITE;
MaterialPower = gMaterialSpecPower;
MaterialSpecular = gMaterialSpecular;
MaterialEmissive = CURRENT_LIGHT != NOT_LIGHT ? GetContainerData(CURRENT_LIGHT) : gMaterialEmissive;
}
}
technique fallback {
pass P0 {
}
}