playcanvas
Version:
PlayCanvas WebGL game engine
41 lines (39 loc) • 1.18 kB
JavaScript
var ambientPS = `
uniform vec3 ambientSH[9];
uniform sampler2D texture_envAtlas;
void addAmbient(vec3 worldNormal) {
vec3 n = cubeMapRotate(worldNormal);
vec3 color =
ambientSH[0] +
ambientSH[1] * n.x +
ambientSH[2] * n.y +
ambientSH[3] * n.z +
ambientSH[4] * n.x * n.z +
ambientSH[5] * n.z * n.y +
ambientSH[6] * n.y * n.x +
ambientSH[7] * (3.0 * n.z * n.z - 1.0) +
ambientSH[8] * (n.x * n.x - n.y * n.y);
dDiffuseLight += processEnvironment(max(color, vec3(0.0)));
vec3 dir = normalize(cubeMapRotate(worldNormal) * vec3(-1.0, 1.0, 1.0));
vec2 uv = mapUv(toSphericalUv(dir), vec4(128.0, 256.0 + 128.0, 64.0, 32.0) / atlasSize);
vec4 raw = texture2D(texture_envAtlas, uv);
vec3 linear = {ambientDecode}(raw);
dDiffuseLight += processEnvironment(linear);
dDiffuseLight += light_globalAmbient;
}
`;
export { ambientPS as default };