playcanvas
Version:
PlayCanvas WebGL game engine
60 lines (57 loc) • 1.75 kB
JavaScript
var skyboxPS = `
varying vLinearDepth: f32;
varying vViewDir : vec3f;
uniform skyboxHighlightMultiplier : f32;
var texture_cubeMap : texture_cube<f32>;
var texture_cubeMap_sampler : sampler;
varying vWorldPos : vec3f;
uniform cubeMapRotationMatrix : mat3x3f;
uniform projectedSkydomeCenter : vec3f;
var texture_envAtlas : texture_2d<f32>;
var texture_envAtlas_sampler : sampler;
uniform mipLevel : f32;
@fragment
fn fragmentMain(input : FragmentInput) -> FragmentOutput {
var output: FragmentOutput;
output.color = float2vec4(vLinearDepth);
var linear : vec3f;
var dir : vec3f;
var envDir : vec3f = normalize(input.vWorldPos - uniform.projectedSkydomeCenter);
dir = envDir * uniform.cubeMapRotationMatrix;
dir = input.vViewDir;
dir.x *= -1.0;
linear = {SKYBOX_DECODE_FNC}(textureSample(texture_cubeMap, texture_cubeMap_sampler, dir));
dir = input.vViewDir * vec3f(-1.0, 1.0, 1.0);
let uv : vec2f = toSphericalUv(normalize(dir));
linear = {SKYBOX_DECODE_FNC}(textureSample(texture_envAtlas, texture_envAtlas_sampler, mapRoughnessUv(uv, uniform.mipLevel)));
if (any(linear >= vec3f(64.0))) {
linear *= uniform.skyboxHighlightMultiplier;
}
output.color = vec4f(gammaCorrectOutput(toneMap(processEnvironment(linear))), 1.0);
return output;
}
`;
export { skyboxPS as default };