Skip to content

Commit c3d15da

Browse files
authored
Directional lightmap fix (playcanvas#2590)
* lightmap fix
1 parent f30c4b9 commit c3d15da

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

src/graphics/program-lib/chunks/lightmapDir.frag

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,19 @@ uniform sampler2D texture_lightMap;
22
uniform sampler2D texture_dirLightMap;
33

44
void addLightMap() {
5-
65
vec3 color = $texture2DSAMPLE(texture_lightMap, $UV).$CH;
7-
vec4 dir = texture2D(texture_dirLightMap, $UV);
8-
9-
if (dot(dir.xyz,vec3(1.0)) < 0.00001) {
6+
vec3 dir = texture2D(texture_dirLightMap, $UV).xyz;
7+
if (dot(dir, vec3(1.0)) < 0.00001) {
108
dDiffuseLight += color;
11-
return;
12-
}
13-
14-
dLightDirNormW = normalize(dir.xyz * 2.0 - vec3(1.0));
9+
} else {
10+
dLightDirNormW = normalize(dir * 2.0 - vec3(1.0));
1511

16-
float vlight = saturate(dot(dLightDirNormW, -dVertexNormalW));
17-
float flight = saturate(dot(dLightDirNormW, -dNormalW));
18-
float nlight = (flight / max(vlight,0.01)) * 0.5;
12+
float vlight = saturate(dot(dLightDirNormW, -dVertexNormalW));
13+
float flight = saturate(dot(dLightDirNormW, -dNormalW));
14+
float nlight = (flight / max(vlight, 0.01)) * 0.5;
1915

20-
dDiffuseLight += color * nlight * 2.0;
21-
}
22-
23-
void addDirLightMap() {
24-
vec4 dir = texture2D(texture_dirLightMap, $UV);
25-
if (dot(dir.xyz,vec3(1.0)) < 0.00001) return;
26-
vec3 color = $texture2DSAMPLE(texture_lightMap, $UV).$CH;
16+
dDiffuseLight += color * nlight * 2.0;
17+
}
2718

28-
dLightDirNormW = normalize(dir.xyz * 2.0 - vec3(1.0));
29-
dSpecularLight += vec3(getLightSpecular()) * color;
19+
dSpecularLight += color * getLightSpecular();
3020
}

src/graphics/program-lib/programs/standard.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,10 +1454,6 @@ var standard = {
14541454
code += " addReflection();\n";
14551455
}
14561456

1457-
if (options.dirLightMap) {
1458-
code += " addDirLightMap();\n";
1459-
}
1460-
14611457
for (i = 0; i < options.lights.length; i++) {
14621458
// The following code is not decoupled to separate shader files, because most of it can be actually changed to achieve different behaviors like:
14631459
// - different falloffs

0 commit comments

Comments
 (0)