@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
25 lines (23 loc) • 932 B
JavaScript
var reflectionEnvHQPS = `
uniform sampler2D texture_envAtlas;
uniform samplerCube texture_cubeMap;
uniform float material_reflectivity;
vec3 calcReflection(vec3 reflDir, float gloss) {
vec3 dir = cubeMapProject(reflDir) * vec3(-1.0, 1.0, 1.0);
vec2 uv = toSphericalUv(dir);
float level = saturate(1.0 - gloss) * 5.0;
float ilevel = floor(level);
float flevel = level - ilevel;
vec3 sharp = $DECODE_CUBEMAP(textureCube(texture_cubeMap, fixSeams(dir)));
vec3 roughA = $DECODE(texture2D(texture_envAtlas, mapRoughnessUv(uv, ilevel)));
vec3 roughB = $DECODE(texture2D(texture_envAtlas, mapRoughnessUv(uv, ilevel + 1.0)));
return processEnvironment(mix(sharp, mix(roughA, roughB, flevel), min(level, 1.0)));
}
void addReflection(vec3 reflDir, float gloss) {
dReflection += vec4(calcReflection(reflDir, gloss), material_reflectivity);
}
`;
export { reflectionEnvHQPS as default };